thanks for replies!
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
os.queueEvent - queuing tables
Started by grabie2, 23 January 2013 - 06:04 AMPosted 23 January 2013 - 07:04 AM
I went into strange problem, when I queued event with strings and tables, in os.pullEventRaw it returned strings and ALL tables were nil. Could someone explain to me why it doesn't work, maybe there is a solution(I don't want to do textutils.serialize, sometimes tables contain functions WITH upvalues)
thanks for replies!
thanks for replies!
Posted 23 January 2013 - 08:19 AM
Code.
Posted 23 January 2013 - 09:06 AM
When you use queueEvent, you pass the arguments through to the java code, then they bubble back through. Unfortunately, it is impossible to send tables in this way.
There are a number of ways to solve this. One way would be to wrap queueEvent and pullEvent in lua code that maintains an internal queue, and works with the couroutine API. I think this is possible - have a look at the source code for the parallel API to get ideas.
The easier solution is to just store metadata elsewhere, and use the standard event system to pass a key to that metadata.
There are a number of ways to solve this. One way would be to wrap queueEvent and pullEvent in lua code that maintains an internal queue, and works with the couroutine API. I think this is possible - have a look at the source code for the parallel API to get ideas.
The easier solution is to just store metadata elsewhere, and use the standard event system to pass a key to that metadata.
eventExtraData = {}
id = 1
function queueMyEvent(...)
eventExtraData[id] = {...}
os.queueEvent("my event", id)
id = id + 1
end
function pullMyEvent()
local event = {os.pullEvent("my event")}
local id = event[2]
local data = eventExtraData[id]
eventExtraData[id] = nil
return "my event", unpack(data)
end
Posted 23 January 2013 - 09:52 AM
Thanks Eric, I thought that this is the case, but I used Lua only with C api, and that wasn't problem.
But instead of FILO queue that you shown I'll use FIFO, that'll be better for event queue ;)/>
Again thanks for quick response and help!
(Thread can be closed)
But instead of FILO queue that you shown I'll use FIFO, that'll be better for event queue ;)/>
Again thanks for quick response and help!
(Thread can be closed)
Posted 23 January 2013 - 09:58 AM
Are you sure you thought that through? This may not apply to your case, but think about these events:But instead of FILO queue that you shown I'll use FIFO, that'll be better for event queue ;)/>
char f
char a
char i
char l
And a piece of code that gets them one by one and prints. With a FILO (a queue, hence queueEvent()), this will print "fail", but with a FIFO (a stack), you get "liaf".Posted 23 January 2013 - 10:06 AM
Are you sure you thought that through? This may not apply to your case, but think about these events:But instead of FILO queue that you shown I'll use FIFO, that'll be better for event queue ;)/>And a piece of code that gets them one by one and prints. With a FILO (a queue, hence queueEvent()), this will print "fail", but with a FIFO (a stack), you get "liaf".char f char a char i char l
I disagree…. you press f-a-i-l and it queues "f" first, then "a", then "i", then "l", FIFO means "f" comes out first 'cos it went in first so you keep the order of events.
Posted 23 January 2013 - 10:15 AM
Derp. I was confused by grabie calling my code a FILO when it is in fact a fifo.
Posted 23 January 2013 - 10:17 AM
Oww right, derp.
I looked at your code and somehow seen FILO queue, derp.
Sorry for that.
(Thread can be closed)
I looked at your code and somehow seen FILO queue, derp.
Sorry for that.
(Thread can be closed)