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+
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

0 commit comments

Comments
 (0)