Hi
I have a simple Lua function like this:
function test( x )
while x>0 do
print(x);
x=x-1;
coroutine.yield();
end
end
Basically it prints one number every time it is resumed. From C I can do:
co=lua_newthread(L);
lua_getglobal(co,”test”);
lua_pushinteger(co,100);
lua_resume(co,1);
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.
Any ideas?
Regards
Ivo