[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_resume and a C-function as the main coroutine function problem
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 13 Apr 2010 16:39:18 -0300
> Please consider the following piece of code:
>
> ---------------------------------------------------------------
> #include <stdio.h>
> #include <lua.h>
>
> int test(lua_State* L) {
> printf("test start\n");
> return lua_yield(L, 0);
> }
>
> int main() {
> lua_State* L = luaL_newstate();
> lua_State* T = lua_newthread(L);
> luaL_ref(L, LUA_REGISTRYINDEX);
> lua_pushcfunction(T, test);
> printf("1st resume: %d\n", lua_resume(T, 0));
> printf("2nd resume: %d\n", lua_resume(T, 0));
> lua_close(L);
> return 0;
> }
> ---------------------------------------------------------------
>
> In this example, I am trying to use a C-function as the main function
> for lua_resume() call. The program crashes with segfault.
>
> Probably, it is forbidden to use lua_resume() this way, however I
> didn't find any related information neihter in the Lua 5.1 manual nor
> on the Lua users wiki and the whole Internet. [...]
It is forbidden to resume a C function. The manual should mention that.
Thanks for the report.
-- Roberto