Following the example from here: viewtopic.php?f=5&t=9934.
It is no problem to get data from a thread.
But I want to send data from the "main.lua" to the thread.
If this is possible, if so how?
Thank you for your help.
freedmo
Code: Select all
self = love.thread.getThread()
thread = love.thread.newThread('thread', 'thread.lua')
thread:start()
self:set('some var', 'something')
Code: Select all
self = love.thread.getThread()
main = love.thread.getThread('main')
while true do
if main:get('some var') == 'something' then
--well, just do something
end
love.timer.speel(.001)
end
Code: Select all
myThread = love.thread.newThread('thread', 'thread.lua')
myThread:start()
myThread:set('some var', 'something')
Code: Select all
self = love.thread.getThread()
self:set("myVar", "hello from inside the thread")
Code: Select all
msg = myThread:get("myVar")
That's what I was looking for.Nixola wrote:The main thread is called 'main'; by getting the thread (main_thread = love.thread.getThread()) inside main.lua (or anything inside that thread) you can then set a message there; by getting the 'main' thread from another thread (main_thread = love.thread.getThread('main')) you can then get the message. Example:
main.lua:thread.lua:Code: Select all
self = love.thread.getThread() thread = love.thread.newThread('thread', 'thread.lua') thread:start() self:set('some var', 'something')
I didn't test this yet but it should workCode: Select all
self = love.thread.getThread() main = love.thread.getThread('main') while true do if main:get('some var') == 'something' then --well, just do something end love.timer.speel(.001) end
(P.S: I did something similar, anyway I was able to send data from the main thread to another with this method)
Users browsing this forum: Bing [Bot] and 9 guests