[luabind] Luabind and coroutines
Brought to you by:
arvidn,
daniel_wallin
From: Alexander G. <agl...@gm...> - 2006-02-27 05:46:32
|
Hi, all! 1. I have some troubles with understanding of coroutines part of Luabind documentation. I think it could benefit from some elaboration, at least can some more examples be added there? When should I call luabind::resume_function() and when luabind::resume() for example? 2. Can I create coroutine in Lua, pass it to C++, and call resume on it like on coroutine I created from C? [lua] local f =3D function() while true do coroutine.yield() print("!!!") end end BindCoroutine(coroutine.create(f)) [/lua] [cpp] class foo { public: void BindCoroutine(luabind::object obj) { if (luabind::type(obj) !=3D LUA_TTHREAD) { lua_pushstring(obj.interpreter(), "Expected coroutine"); lua_error(obj.interpreter()); } m_Coroutine =3D obj; } void Update() { m_Coroutine.push(m_Coroutine.interpreter()); lua_State * pThread =3D lua_tothread(m_Coroutine.interpreter(), -1); lua_pop(m_Coroutine.interpreter(), 1); luabind::resume<void>(pThread); } private: luabind::object m_Coroutine; }; [/cpp] Is this the correct way? Am I missing something? I'm getting the same assertion on luabind::resume() call at line 264 of call_function.hpp in my actual code. (I can make a minimal compiling example if needed.) Thanks in advance, Alexander. P.S. Docs say luabind::object::state() to have no arguments, but it accepts lua_State * in current code. |