Advertisement

Getting the parameters from yield

Started by August 27, 2003 11:24 AM
0 comments, last by Hazelnuss 21 years, 2 months ago
Here is my program:

// C
void main()
{
	lua_State * L;

	L = lua_open();
	luaopen_base(L);

	lua_dofile(L, "skript.txt");

	for(int i = 0; i < 3; ++i)
	{
		cout << "Here is main(). Returned value: " << lua_tonumber(L, -1)
			 << endl << endl;

		lua_dostring(L, "coroutine.resume(co)");
	}
}

-- Lua
function yieldtest()
  while true do
    print("Here is the Lua function")
	coroutine.yield(666)
  end
end

co = coroutine.create(yieldtest)
coroutine.resume(co)
 
My question: How can i get the value given to yield() within my program? And another question: How can i resume my coroutine other than via lua_dostring(L, "coroutine.resume(co)"); ?
The value is returned by coroutine.resume(co), but is not returned back to C, since you''re not specifying to return any values.

You really shouldn''t bother with the Lua coroutine interface if you''re doing it from C, since coroutines have their own C functions. And there we lead into your second question. Long answer short: lua_resume. Short answer long: RTFM.

How appropriate. You fight like a cow.

This topic is closed to new replies.

Advertisement