Jump to content
  • Advertisement
Sign in to follow this  
Perceptron

Lua: Get all functions defined in script

This topic is 4063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!