lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi Mike,

On Fri, 30 Sep 2011, Mike Pall wrote:

mitchell wrote:
static VALUE l_yield(VALUE self, VALUE arg) {
  lua_pushsomething(L, RUBY2LUA(arg));
  lua_yield(L, 1); // coroutine.resume() should return the arg
  printf("This should not be called right away due to lua_yield()\n");

The 'L' you're using here must be the lua_State for the coroutine,
not the main thread.

Thanks for the response. My question is how to I get the coroutine's Lua state? What I gather from your response is that when run_ruby() is called, the lua_State passed to it is the main thread.

Do I have to create the thread using coco's lua_newcthread() and use it's returned Lua State? The documentation also states I can call 'coroutine.create' from C so would the following:

    lua_getglobal(L, "coroutine");
    lua_getfield(L, -1, "create");
    lua_call(L, 1, ...);

work? If not, what do you mean?

Thanks a lot,