lua-users home
lua-l archive

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


On Mon, Jan 24, 2011 at 11:03 AM, Nicolas <nicolas@net-core.org> wrote:
> Hi,
>
> I'm toying with the idea of switching to luajit2 for my game, I
> resolved most issues (the main one being the lanes incompatiblity
> discussed previously and the no-luadump function which I'll fix ..
> someway ) but then this bites me:
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00000000004790cc in lj_BC_RET ()
> (gdb) bt
> #0  0x00000000004790cc in lj_BC_RET ()
> #1  0x000000000047a071 in lj_ff_coroutine_resume ()
> #2  0x000000000046771b in lua_pcall (L=0x40000378, nargs=1, nresults=1, errfunc=28) at src/luajit2/src/lj_api.c:1021
> #3  0x000000000041252e in docall (L=0x40000378, narg=1, nret=1) at src/main.c:91
> #4 0x0000000000412d86 in on_tick () at src/main.c:261
> #5 0x000000000041435d in main (argc=2, argv=0x7fffffffe088) at src/main.c:841
>
>
> I do multiple lua calls from my C code but it always fails in that
> spot, the only difference I can see is that I get one return whereas in
> others I get none.
> I tried to return nothing but it's the same.
>
> I can not paste the whole lua source as the game is several thousand
> files, but I see no obvious reasons this can fail (and not fail in
> standard lua 5.1.4).
>
> Is there something obvious that I am missing? Am I being stupid?
>
> For reference, my docall method is as follow, nothing fancy:
>
> static int traceback (lua_State *L) {
>        lua_Debug ar;
>        int n;
>        n = 0;
>        printf("Lua Error: %s\n", lua_tostring(L, 1));
>        while(lua_getstack(L, n++, &ar)) {
>                lua_getinfo(L, "nSl", &ar);
>                printf("\tAt %s:%d %s\n", ar.short_src, ar.currentline,
> ar.name?ar.name:""); }
>        return 1;
> }
>
> int docall (lua_State *L, int narg, int nret)
> {
>        int status;
>        int base = lua_gettop(L) - narg;  /* function index */
>        lua_pushcfunction(L, traceback);  /* push traceback function */
>        lua_insert(L, base);  /* put it under chunk and args */
>        status = lua_pcall(L, narg, nret, base);
>        lua_remove(L, base);  /* remove traceback function */
>        /* force a complete garbage collection in case of errors */
>        if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
>        return status;
> }

Your docall has an off-by-one error. base should be "lua_gettop(L)-narg+1".

-- 
- Patrick Donnelly