How do you use threads?
How do you use threads?
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?
Last edited by zac352 on Sun Nov 07, 2010 1:41 am, edited 1 time in total.
Hello, I am not dead.
- 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...
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,
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.
Re: You people are all familiar with lua...
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,
Hello, I am not dead.
- 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...
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.
Re: You people are all familiar with lua...
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.
Hello, I am not dead.
- 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...
Then, my friend, you are doomed.
dooooomed.
dooooomed.
Help us help you: attach a .love.
Re: You people are all familiar with lua...
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.
Edit: No, they don't.
Hello, I am not dead.
Re: How do you use threads?
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.
- 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...
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.
Help us help you: attach a .love.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: How do you use threads?
I wonder how you guys fail to see it as easy as it is:
input.lua:
main.lua:
That being said, I have no idea why you would want to do this.
input.lua:
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
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 5 guests