Sign in to follow this  
Perceptron

Lua: Get all functions defined in script

Recommended Posts

Hey, I've been programming with Lua for several weeks and now I've started creating a script module for my game engine. But now I've got a problem. I want to know all the functions that are defined in the script, e.g function Func1() -- lala end function Func2() -- lala end and the engine should then display the names of Func1 and Func2 after execution. Well, displaying is not usefull, but it in the editor it will. I think the solution is pushing all global variables on the stack, but how? I know that you can push one with lua_getglobal(), but only if you know its name :P Could anybody help me? Regards, Perceptron

Share this post


Link to post
Share on other sites
The global table is just a table. You can iterate through it just like any other table.

Share this post


Link to post
Share on other sites
The table _G (that's underscore, capital G) contains all global functions and variables. You can iterate through that table (see lua_next), and use lua_gettype to check if a value is a function.

Share this post


Link to post
Share on other sites
To access the global table from the C interface, use the stack index LUA_GLOBALINDEX

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this