🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

LUA - Enumerating Functions

Started by
1 comment, last by Prozak 19 years, 11 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.
Advertisement
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
Ah, glad to see there is a method for this.

Thank you [wink]

This topic is closed to new replies.

Advertisement