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!
os.queueEvent - queuing tables
Started by grabie2, Jan 23 2013 07:04 AM
7 replies to this topic
#1
Posted 23 January 2013 - 07:04 AM
#2
Posted 23 January 2013 - 08:19 AM
Code.
#3
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
#4
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)
#5
Posted 23 January 2013 - 09:58 AM
grabie2, on 23 January 2013 - 09:52 AM, said:
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 lAnd 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".
#6
Posted 23 January 2013 - 10:06 AM
Eric, on 23 January 2013 - 09:58 AM, said:
grabie2, on 23 January 2013 - 09:52 AM, said:
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 lAnd 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".
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.
#7
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.
#8
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)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











