Thread
You can create thread using static method:
Lib.Sys.VM.Thread.create(spath) |
Creates a new thread that will execute the spath Lua script as independent instance, then exit. |
spath - can be Lua script or project path to Lua script |
More static methods:
Lib.Sys.VM.Thread.current() |
Returns the current thread. |
|
Lib.Sys.VM.Thread.readMessage(block) |
Reads a message from the thread queue. If block is true, the function blocks until a message is available. If block is false, the function returns nil if no message is available. |
block - true/false, thread reading blocking condition |
Created thread has methods:
sendMessage(msg) |
Send a message msg to the thread queue. This message can be read by using readMessage. |
msg - any object, string, etc. to send |
Examples:
Thread = Lib.Sys.VM.Thread
t = Thread.create([[
Thread = Lib.Sys.VM.Thread
--get ref to main thread
local main = Thread.readMessage(true)
for ii=0, 5, 1 do
print("message"..ii)
end
main.sendMessage("thread done")
]])
--give thread t a ref to main thread
t.sendMessage(Thread.current())
--wait for thread to finish
Lib.Media.Display.stage.addEventListener(Lib.Media.Events.Event.ENTER_FRAME,
function (e)
local message = Thread.readMessage(false)
if message ~= nil then
print(message)
end
end, false, 0, false)
Created with the Personal Edition of HelpNDoc: Free PDF documentation generator