Advertisement

LUA - Enumerating Functions

Started by July 17, 2004 02:46 AM
1 comment, last by Prozak 20 years, 4 months ago
Is it possible under LUA 5.0 to enumerate all functions that are available for use to the script? ...those functions registered by the coder using: lua_register(L, function_name, function_ptr) Is it possible to enumerate them all, or will I have to create a means to accomplish this myself? Thank You.
Just iterate through the globals table _G and make a list of all the functions in it, e.g. something like this in c:

lua_pushstring(state, "_G"); //the global table is a member _G in itselflua_gettable(state, LUA_GLOBALSINDEX); //grab global tablelua_pushnil(state); //push nil as first key for lua_nextwhile(lua_next(state, -2)) //iterate through table{   if(lua_iscfunction(state, -1)) //if current table value is a function   {       AddToFunctionList(lua_tostring(state, -2)) //add the key (the function name as a string) to a list   }   lua_pop(state, 1); //pop off the current table value}lua_pop(state, 2); //clean up the stack
Advertisement
Ah, glad to see there is a method for this.

Thank you [wink]

This topic is closed to new replies.

Advertisement