I have a simple Lua function like this:
function test( x )
while x>0 do
Basically it prints one number every time it is resumed. From C I can do:
Then keep calling lua_resume(co,0) until the thread is done.
Is it possible to write a C function “test” that behaves the exact same way? Obviously it can’t have a loop with a yield in the middle, because that’s not going to work in C. The C code will need to yield and put the thread in such a state that the next lua_resume will call it again. Also there’s the matter of storing ‘x’ in the thread’s state to act like a local variable.