Lua: Get all functions defined in script

Started by
4 comments, last by Perceptron 16 years, 10 months ago
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
Advertisement
The global table is just a table. You can iterate through it just like any other table.
Okay, but with which function can I push it on the stack?

Or what is the table's name?
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.
To access the global table from the C interface, use the stack index LUA_GLOBALINDEX
Thanks alot! It's working now!

This topic is closed to new replies.

Advertisement