lua-users home
lua-l archive

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

After messing about with this for a while, I found the following adapted from the manual. If I call this function after nil'ing and gc'ing and they're gone, is there anywhere else in Lua I need to check to be sure they're really gone?


// function void ScriptDumpGlobals(lua_State *luaStatePtr)
void ScriptDumpGlobals(lua_State *luaStatePtr)
int t;
printf("Lua globals table dump start:\n");
// table is in the stack at index `t'
lua_pushnil(luaStatePtr); // first key
while(lua_next(luaStatePtr, t) != 0)
// `key' is at index -2 and `value' at index -1
switch(lua_type(luaStatePtr, -2))
printf("%s\n", lua_tostring(luaStatePtr, -2));
printf("%s - %s\n", lua_typename(luaStatePtr, lua_type(luaStatePtr, -2)), lua_typename(luaStatePtr, lua_type(luaStatePtr, -1)));
lua_pop(luaStatePtr, 1); // removes `value'; keeps `key' for next iteration
printf("Lua globals table dump end.\n\n");

----- Original Message ----- From: "Research" <>
To: "Lua List" <>
Sent: Sunday, June 25, 2006 12:31 PM
Subject: Dump all strings/symbols?

I sorta asked this in reply to another question, but I still don't know how to do it.

Is there a way to traverse the entire globals/registry and get the strings/symbol names out? (only top level stuff is needed, not a deep traversal) We're setting tables and functions to nil and it seems that not everything is being garbage collected. I want some way to find out what lua is still holding references to so I can clean them up. What are the ways to do this?