How do you use threads?
Posted: Sun Nov 07, 2010 12:44 am
I just spent the last 1/2 hour googling a way to use io.stdin:read() without completely pausing your program. Coroutines don't work. Anyone know a workaround?
Awww...Robin wrote:Threads?
But if you're using stdin, you're probably not using LÖVE anyway, right?
Anyway, reading from stdin is a blocking function, for good reasons. To disable the blocking, you need to do some deep, largely unportable magic,
I'm scared of whitespace. I don't see that working.Robin wrote:If you really need it, and you're not using LÖVE, you could consider using Python, which has curses and termios in its standard library.
Can you give me an example of how to use the message system in threads? And do threads share _G?Robin wrote:Then, my friend, you are doomed.
dooooomed.
Hmm... I was gonna say that this would be trivial to add via Lua's module system (literally 5 or 6 lines of C code), but Love appears to be statically linked to Lua and the API functions aren't exported, so this isn't really an option. Digging around on this site, this is all I was able to find on the subject (2008):zac352 wrote:I just spent the last 1/2 hour googling a way to use io.stdin:read() without completely pausing your program.
That pretty much kills extending Love dynamically. Which is ironic, because in the same post he says:rude wrote:I made a decision (that can be easily changed) to incorporate Lua into EXE file, not to use it as DLL.
If Lua was still in a DLL/so, you could.rude wrote:Because one of the problems of such kind of engines is that in non-trivial games there is always some non-standard functionality that is missing or too slow to be done in scripts. It would be nice to allow users to extend Love with plug-ins.
What, in LÖVE?zac352 wrote:Can you give me an example of how to use the message system in threads? And do threads share _G?
Edit: No, they don't.
Except that it wouldn't be very portable, and your game wouldn't run in SELÖVE.Mud wrote:If Lua was still in a DLL/so, you could.
Code: Select all
local t = love.thread.getThread()
repeat
local s = io.read()
t:send("input", s)
until t:receive("quit")
Code: Select all
function love.load()
t = love.thread.newThread("input", "input.lua")
t:start()
end
function love.update(dt)
local input = t:receive("input")
if input then
--input!
end
end