15 posts
Posted 13 July 2012 - 06:42 AM
What would happen if I called print after calling read on a different thread?
504 posts
Location
Seattle, WA
Posted 13 July 2012 - 06:58 AM
ComputerCraft and Lua, as far as I know, doesn't support multithreading but rather you can take advantage of the parallel API which implements coroutines to mimic simultaneous execution.
Using 'parallel.waitForAny(print("TEST", read()))' would result in the print statement being executed first and then the read would be executed.
Hope I helped! :)/>/>
15 posts
Posted 13 July 2012 - 07:01 AM
So I can't print something while trying to read()?
1604 posts
Posted 13 July 2012 - 05:26 PM
Yes, but it wouldn't be at the same time. It looks like it's running at the same time but it's not.
You can use:
local function printStuff()
while true do
print("Some text here")
end
end
local function getInput()
while true do
local input = read()
-- do something with input
end
end
parallel.waitForAny(printStuff, getInput)
But you have to take care of the functions not overwriting each other's text.