Don’t know if this’s a bug or something that I don’t understand about Lua, but coroutine.status is always returning “suspended”, even though the coroutine is clearly running.
local f = coroutine.create(function()
while true do
wait()
print("running")
end
end)
coroutine.resume(f)
while true do
wait()
print(coroutine.status(f))
end
You’re printing the status of the coroutine from outside of it, in a different thread. In order for that code to run, the coroutine it’s checking the status of has to be suspended. If you print its status inside itself while it’s running then it will say it’s running.
You are checking the status outside of itself already. Its status is suspended. If it weren’t suspended then code outside of itself wouldn’t be running.
spawn behaves the same, just with a frame delay at the start. There isn’t a way to run simultaneous threads in parallel, which is why there are coroutines. wait suspends the thread and then resumes it later.
The only code that runs while it’s running is inside of it. If code outside of it is running then it’s not running, it’s suspended (or normal if it resumed another coroutine itself). https://www.lua.org/manual/5.1/manual.html#5.2