LUA - Enumerating Functions
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement