8000 Bugfixes · neumond/python-computer-craft@c8fba72 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8fba72

Browse files
committed
Bugfixes
1 parent c4c6523 commit c8fba72

17 files changed

+65
-38
lines changed

computercraft/back.lua

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local event_sub = {}
44
genv.temp = temp
55
local url = 'http://127.0.0.1:4343/'
66
local tasks = {}
7+
local filters = {}
78
local ycounts = {}
89

910
ws = http.websocket(url..'ws/')
@@ -59,6 +60,7 @@ while true do
5960
elseif msg.action == 'drop' then
6061
for _, task_id in ipairs(msg.task_ids) do
6162
tasks[task_id] = nil
63+
filters[task_id] = nil
6264
ycounts[task_id] = nil
6365
end
6466
elseif msg.action == 'sub' then
@@ -83,21 +85,29 @@ while true do
8385

8486
local del_tasks = {}
8587
for task_id in pairs(tasks) do
86-
local r = {coroutine.resume(tasks[task_id], event, p1, p2, p3, p4, p5)}
87-
if coroutine.status(tasks[task_id]) == 'dead' then
88-
ws.send(textutils.serializeJSON{
89-
action='task_result',
90-
task_id=task_id,
91-
result=r,
92-
yields=ycounts[task_id],
93-
})
94-
del_tasks[task_id] = true
95-
else
96-
ycounts[task_id] = ycounts[task_id] + 1
88+
if filters[task_id] == nil or filters[task_id] == event then
89+
local r = {coroutine.resume(tasks[task_id], event, p1, p2, p3, p4, p5)}
90+
if coroutine.status(tasks[task_id]) == 'dead' then
91+
ws.send(textutils.serializeJSON{
92+
action='task_result',
93+
task_id=task_id,
94+
result=r,
95+
yields=ycounts[task_id],
96+
})
97+
del_tasks[task_id] = true
98+
else
99+
if r[1] == true then
100+
filters[task_id] = r[2]
101+
else
102+
filters[task_id] = nil
103+
end
104+
ycounts[task_id] = ycounts[task_id] + 1
105+
end
97106
end
98107
end
99108
for task_id in pairs(del_tasks) do
100109
tasks[task_id] = nil
110+
filters[task_id] = nil
101111
ycounts[task_id] = nil
102112
end
103113
end

computercraft/sess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def readline(self, size=-1):
7373
"stdin readline method with parameter")
7474
return rproc.string(eval_lua(
7575
return_lua_call('io.read')
76-
))
76+
)) + '\n'
7777

7878
def write(self, s):
7979
if _is_global_greenlet():

computercraft/subapis/colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ def unpackRGB(rgb: int) -> Tuple[float, float, float]:
9595
}
9696

9797

98-
def iter_colors(self):
99-
for c in self.chars.values():
98+
def iter_colors():
99+
for c in chars.values():
100100
yield c

computercraft/subapis/fs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import builtins
12
from contextlib import contextmanager
23
from typing import Optional, List, Union
34

@@ -20,7 +21,7 @@ class SeekMixin:
2021
def seek(self, whence: str = None, offset: int = None) -> int:
2122
# whence: set, cur, end
2223
r = self._method('seek', whence, offset)
23-
if isinstance(r, list):
24+
if isinstance(r, builtins.list):
2425
assert r[0] is False
2526
raise LuaException(r[1])
2627
return integer(r)

computercraft/subapis/os.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def run(environment: dict, programPath: str, *args: List[str]):
5151
return boolean(method('run', environment, programPath, *args))
5252

5353

54-
def pullEvent(event: str) -> tuple:
54+
def pullEvent(event: str = None) -> tuple:
5555
return tuple(any_list(method('pullEvent', event)))
5656

5757

58-
def pullEventRaw(event: str) -> tuple:
58+
def pullEventRaw(event: str = None) -> tuple:
5959
return tuple(any_list(method('pullEventRaw', event)))
6060

6161

computercraft/subapis/peripheral.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ..lua import LuaNum, lua_args, return_lua_call
77
from ..rproc import (
88
boolean, nil, integer, string, option_integer, option_string,
9-
tuple2_integer, array_string, option_string_bool, try_result,
9+
tuple2_integer, array_string, option_string_bool, flat_try_result,
1010
)
1111
from ..sess import eval_lua, eval_lua_method_factory
1212

@@ -137,11 +137,12 @@ def receive(self, channel: int):
137137
try:
138138
while True:
139139
evt = pullEvent('modem_message')
140-
if evt[0] != self._side:
140+
assert evt[0] == 'modem_message'
141+
if evt[1] != self._side:
141142
continue
142-
if evt[1] != channel:
143+
if evt[2] != channel:
143144
continue
144-
yield ModemMessage(*evt[2:])
145+
yield ModemMessage(*evt[3:])
145146
finally:
146147
self.close(channel)
147148

@@ -246,7 +247,7 @@ def setCommand(self, command: str):
246247
return nil(self._method('setCommand', command))
247248

248249
def runCommand(self):
249-
return try_result(self._method('runCommand'))
250+
return flat_try_result(self._method('runCommand'))
250251

251252

252253
class CCWorkbench(BasePeripheral):

computercraft/subapis/rednet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def broadcast(message: Any, protocol: str = None):
5050

5151

5252
def receive(
53-
self, protocolFilter: str = None, timeout: LuaNum = None,
53+
protocolFilter: str = None, timeout: LuaNum = None,
5454
) -> Optional[Tuple[int, Any, Optional[str]]]:
5555
return recv_result(method('receive', protocolFilter, timeout))
5656

computercraft/subapis/redstone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424

25-
def getSides(self) -> List[str]:
25+
def getSides() -> List[str]:
2626
return array_string(method('getSides'))
2727

2828

computercraft/subapis/shell.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@
3030
)
3131

3232

33-
def exit(self):
33+
def exit():
3434
return nil(method('exit'))
3535

3636

37-
def dir(self) -> str:
37+
def dir() -> str:
3838
return string(method('dir'))
3939

4040

4141
def setDir(path: str):
4242
return nil(method('setDir', path))
4343

4444

45-
def path(self) -> str:
45 1CF5 +
def path() -> str:
4646
return string(method('path'))
4747

4848

@@ -58,7 +58,7 @@ def resolveProgram(name: str) -> Optional[str]:
5858
return option_string(method('resolveProgram', name))
5959

6060

61-
def aliases(self) -> Dict[str, str]:
61+
def aliases() -> Dict[str, str]:
6262
return map_string_string(method('aliases'))
6363

6464

@@ -74,7 +74,7 @@ def programs(showHidden: bool = None) -> List[str]:
7474
return array_string(method('programs', showHidden))
7575

7676

77-
def getRunningProgram(self) -> str:
77+
def getRunningProgram() -> str:
7878
return string(method('getRunningProgram'))
7979

8080

computercraft/subapis/term.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TermAPI(BaseSubAPI, TermMixin):
2424
'getCursorPos',
2525
'setCursorPos',
2626
'getCursorBlink',
27+
'setCursorBlink',
2728
'isColor',
2829
'getSize',
2930
'scroll',
@@ -33,6 +34,10 @@ class TermAPI(BaseSubAPI, TermMixin):
3334
'getBackgroundColor',
3435
'getPaletteColor',
3536
'setPaletteColor',
37+
'nativePaletteColor',
38+
'redirect',
39+
'get_current_target',
40+
'get_native_target',
3641
)
3742

3843

@@ -43,6 +48,7 @@ class TermAPI(BaseSubAPI, TermMixin):
4348
getCursorPos = tapi.getCursorPos
4449
setCursorPos = tapi.setCursorPos
4550
getCursorBlink = tapi.getCursorBlink
51+
setCursorBlink = tapi.setCursorBlink
4652
isColor = tapi.isColor
4753
getSize = tapi.getSize
4854
scroll = tapi.scroll

examples/modem_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
side = 'back'
55
m = peripheral.wrap(side)
66
listen_channel = 5
7+
m.close(listen_channel)
78
for msg in m.receive(listen_channel):
89
print(repr(msg))
910
if msg.content == 'stop':

examples/test_fs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
assert isinstance(f.read(), int)
221221

222222
with fs.open('tdir/binfile', 'r') as f:
223-
assert [line async for line in f] == ['bbcccaaaaddd']
223+
assert [line for line in f] == ['bbcccaaaaddd']
224224

225225
assert fs.delete('tdir') is None
226226
assert fs.delete('tfile') is None

examples/test_peripheral.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
del tbl['function']['getName']
1414
del tbl['function']['find']
1515

16+
tbl['function']['get_term_target'] = True
17+
1618
assert _lib.get_class_table(peripheral) == tbl
1719

1820
_lib.step('Remove all peripherals')

examples/test_peripheral_modem.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from cc import import_file, parallel, peripheral
1+
from cc import import_file, parallel, os, peripheral
22

33
_lib = import_file('_lib.py', __file__)
44

@@ -22,10 +22,14 @@
2222

2323

2424
def _send():
25-
m.transmit(remote_channel, local_channel, 1)
26-
m.transmit(remote_channel, local_channel, 'hi')
27-
m.transmit(remote_channel, local_channel, {'data': 5})
28-
m.transmit(remote_channel, local_channel, 'stop')
25+
for msg in [
26+
1,
27+
'hi',
28+
{'data': 5},
29+
'stop',
30+
]:
31+
os.sleep(1)
32+
m.transmit(remote_channel, local_channel, msg)
2933

3034

3135
def _recv():
@@ -39,6 +43,7 @@ def _recv():
3943
break
4044

4145

46+
assert m.closeAll() is None
4247
parallel.waitForAll(_recv, _send)
4348

4449
assert messages == [1, 'hi', {'data': 5}]

examples/test_peripheral_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
assert m.getPageSize() == (25, 21)
5656

5757

58-
async def row(n=1):
58+
def row(n=1):
5959
_, r = m.getCursorPos()
6060
m.setCursorPos(1, r + n)
6161

examples/test_term.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
del tbl['function']['redirect']
1111
del tbl['function']['current']
1212
del tbl['function']['native']
13+
del tbl['function']['nativePaletteColor']
1314

1415
# remove British method names to make API lighter
1516
del tbl['function']['getBackgroundColour']
@@ -94,7 +95,7 @@
9495
assert term.setBackgroundColor(colors.white) is None
9596
assert term.clear() is None
9697
assert term.setCursorPos(1, 1) is None
97-
for i, color in enumerate(colors):
98+
for i, color in enumerate(colors.iter_colors()):
9899
term.setPaletteColor(color, i / 15, 0, 0)
99100
assert term.blit(
100101
' redtextappears!',

examples/test_turtle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def craft1():
221221

222222
def craft2():
223223
c = peripheral.wrap('right')
224-
return await c.craft()
224+
return c.craft()
225225

226226

227227
step('Put crafting table into slot 1')

0 commit comments

Comments
 (0)
0