lua-users home
lua-l archive

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


On 14/08/11 14:02, jseb wrote:
> So i've tried and gave a name to my table, just after created it:
>    lua_newtable (L);
>    lua_setglobal(L,"classname_table");
> Now, the table contains only function i did't add:
> runmainloop     function: 0x2251a00
> fluidimport     function: 0x22519a0
> widgetshow      function: 0x22519d0
> If i simply remove «lua_setglobal», those records disappear.

did you consider that lua_setglobal pops the top value from the stack?

e.g. the following code fragment:

   lua_newtable (L);
   lua_pushstring (L, classname); // key
   lua_pushlightuserdata (L, (void*)object); // value
   lua_rawset (L, -3); // -3 : position of table on the stack

will set the key value pair not in the table "classname_table" but in
another "table" or something else that was on the stack before
lua_newtable was invoked.

Best regards,