How do you use threads?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

How do you use threads?

Post by zac352 »

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? :ehem:
Last edited by zac352 on Sun Nov 07, 2010 1:41 am, edited 1 time in total.
Hello, I am not dead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: You people are all familiar with lua...

Post by Robin »

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,
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: You people are all familiar with lua...

Post by zac352 »

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,
Awww... :(
Hello, I am not dead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: You people are all familiar with lua...

Post by Robin »

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.
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: You people are all familiar with lua...

Post by zac352 »

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.
I'm scared of whitespace. I don't see that working.
Hello, I am not dead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: You people are all familiar with lua...

Post by Robin »

Then, my friend, you are doomed.
dooooomed.
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: You people are all familiar with lua...

Post by zac352 »

Robin wrote:Then, my friend, you are doomed.
dooooomed.
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.
Hello, I am not dead.
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: How do you use threads?

Post by Mud »

zac352 wrote:I just spent the last 1/2 hour googling a way to use io.stdin:read() without completely pausing your program.
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):
rude wrote:I made a decision (that can be easily changed) to incorporate Lua into EXE file, not to use it as DLL.
That pretty much kills extending Love dynamically. Which is ironic, because in the same post he says:
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.
If Lua was still in a DLL/so, you could.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: You people are all familiar with lua...

Post by Robin »

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.
What, in LÖVE?
Mud wrote:If Lua was still in a DLL/so, you could.
Except that it wouldn't be very portable, and your game wouldn't run in SELÖVE.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How do you use threads?

Post by bartbes »

I wonder how you guys fail to see it as easy as it is:

input.lua:

Code: Select all

local t = love.thread.getThread()
repeat
    local s = io.read()
    t:send("input", s)
until t:receive("quit")
main.lua:

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
That being said, I have no idea why you would want to do this.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests