-
I'm not sure if this is a bug or I'm not understanding how this works If you are placing a chest next to a computer and wrap it as a peripheral. There are multiple thing that seems odd:
I tried to find what could be causing this in the source code but wasn't able to find if this was intended or not, I didn't have much time to look deeply into it. local p = peripheral.wrap("right") -- chest
local co = coroutine.create(function()
print("before") -- Print "before"
local list = p.list() -- Yields the coroutine
print("after") -- Unfortunately does not come here event after resuming the coroutine another time
for k, v in pairs(list) do
print(k, v)
end
end)
print(coroutine.resume(co)) -- success, task_complete
local event, task_id, success, list = os.pullEvent("task_complete")
print(coroutine.status(co)) -- suspended
coroutine.resume(co, list) -- resumes the coroutine with the obtained list of items, but nothing happens |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
TLDR: Peripheral functions should be treated as a black box, like any like other user provided function. The events they pull, and what those events contain, isn't part of the public API, and so isn't guaranteed to be stable.
When a function/program/coroutine pulls an event, it doesn't contain anything aside from the event name (in the same way that
In your example code, you resume the coroutine with just the local event = table.pack(os.pullEvent("task_complete"))
print(coroutine.status(co)) -- suspended
coroutine.resume(co, table.unpack(event, 1, event.n)) That said, there's no guarantee that this local ok, filter = coroutine.resume(co)
while coroutine.status(co) ~- "dead" do
local event = table.pack(os.pullEvent(filter))
ok, filter = coroutine.resume(co, table.unpack(event, 1, event.n))
end
if not ok then error(filter, 0) end |
Beta Was this translation helpful? Give feedback.
TLDR: Peripheral functions should be treated as a black box, like any like other user provided function. The events they pull, and what those events contain, isn't part of the public API, and so isn't guaranteed to be stable.
When a function/program/coroutine pulls an event, it doesn't contain anything aside from the event name (in the same way that
http.get
just pulls thehttp_*
events, rather thanhttp_*
and a URL).