lua-users home
lua-l archive

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


OK, so please ignore my second question ... it had to do with local
variables and some callback/notifications I have going on.  I am,
however, still curious about the first one.

thanks,
wes who is having a bad Lua day

On Jan 24, 2008 2:35 AM, Wesley Smith <wesley.hoke@gmail.com> wrote:
> I'm finding the following behavior a bit odd:
>
> lua_State *Ls = lua_newthread(L);
>                 printf("\nlua_newthread\n");
>                 stackDump(L);
>                 int err = luaL_dofile(Ls, filename);
>                 if (err) {
>                         printf("error loading file %s %s\n", filename, lua_tostring(Ls, -1));
>                         lua_pop(Ls, 2); //pop error and thread
>                 }
>                 else {
>                         script = new LuaScript(Ls, filename, modDate);
>                         c_activeScripts[filename] = script;
>
>                         //register script in Lua to access later and keep from being collected
>                         lua_getfield(L, LUA_REGISTRYINDEX, LuaAV_app_table_name);
>                         printf("\n L gut check\n");
>                         stackDump(L);
>                         lua_getfield(Ls, LUA_REGISTRYINDEX, LuaAV_app_table_name);
>                         printf("\n Ls gut check\n");
>                         stackDump(L);
>                         lua_pop(L, 1);
>
>
> output from stackdumps
> lua_newthread
> stack dump 2:
> 2       'thread'
> 1 table: 0x110b070
>
>  L gut check
> stack dump 3:
> 3 table: 0x110b5a0
> 2       'thread'
> 1 table: 0x110b070
>
>  Ls gut check
> stack dump 3:
> 3 table: 0x110b5a0
> 2       'thread'
> 1 table: 0x110b070
>
> My question is why the second call to lua_getfield doesn't also push a
> table (and in fact the same table) on the stack?  This is with Lua
> 5.1.2.
>
> A further question is about preventing threads from being collected.
> I'm pushing the thread created above into a table in the registry but
> when I callect the garbage, it goes away.  I've verified that is is
> indeed going into the table and the table and the table is in the
> registry, but that doesn't seem to stop collection.  Is what I'm
> expecting normal behavior?
>
> thanks,
> wes
>