lua-users home
lua-l archive

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


Brett Bibby wrote:
>

- a7b45j3 = { a=1, b=2, alias=BossTank }
+ a7b45j3 = { a=1, b=2, alias="BossTank" }
  BossTank = a7b45j3

> 1. How do I delete from C side a7b45j3 and alias so that they are
> both garbage collected? Currently I'm trying to do it like this:

- char table = { "a7b45j3" };
- char field = { "alias" };
+ char table[] = "a7b45j3";
+ char field[] = "alias";

  // get table
  lua_pushstring(L, table);
  lua_gettable(L, LUA_GLOBALSINDEX);
   // get field
  lua_pushstring(L, field);
  lua_gettable(L, -2);
 // the string "Tank" is now at top of stack, push nil
  lua_pushnil(L);
  lua_settable(L, LUA_GLOBALSINDEX);
- // this should have changed Tank = a7b45j3 to Tank = nil in the globals table?
- // now remove external reference from table
-  lua_pushstring(L, field);
-  lua_pushnil(L);
-  lua_settable(L, -3);
- // this should have removed the field alias from the table?
 // now delete the table, first get it off the stack
 lua_pop(L,1);
 // put up the name, nil and set it back to globals
  lua_pushstring(L, table);
  lua_pushnil(L);
  lua_settable(L, LUA_GLOBALSINDEX);
 
 // DONE! ??????

Ciao, ET.