lua-users home
lua-l archive

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


In my Lua code, I'm creating a coroutine using coroutine.create() and 
storing its value in a global (my_coroutine).

>From C, if I do:

const char *code = "coroutine.resume(my_coroutine)";
if (luaL_loadbuffer(L, code, strlen(code), "unknown") || lua_pcall(L, 0, 0, 

all works well, and the coroutine until the next yield is executed. However, 
if I do:

lua_getglobal(L, "my_coroutine");
if (lua_resume(L, 0) != 0)

I get the error: "attempt to call a thread value", which is sort of true I 
suppose, except I thought I was resuming it, not calling it.

Can someone explain how coroutine.resume differs from lua_resume? Is there a 
way to do what I'm trying to do, or must I always use the first version?

The actual reason that I was trying to do the second version was to get 
error reporting. When the coroutine code has an error, the error does not 
seem to make it back "out" of the coroutine.resume(...), whereas using pcall 
(and presumably) lua_resume will return an error so that I can figure out 
what's going on.

Any insight will be appreciated.
thanks, scott