Jump to content
  • Advertisement
Sign in to follow this  
of_ownage

LUA getting variables from the c++ project

This topic is 3888 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

hi, i have a question about lua. I recently started it and found it very cool. But i have a problem for example if i have this:: class player { public: int strength; }; int main() { player p; p.strength = 100; lua_State* lua = lua_open(); lua_register( lua, "StartQuest", lua_StartQuest ); luaL_dofile(lua, "./quest.lua"); } int lua_StartQuest( lua_State* lua) { //Start the quest; } now i want in my lua file this:: quest.lua if strength > 200 then StartQuest(); else //Inform the application that he has not enough strength to start the quest end ok i have 2 problems. 1) How should the lua script access the life variable from the game? 2) How do i send variables from lua to the game? I can do it with a function but is there a better idea, i read something about the lua stack but i have no idea what that is. Thank you for any help

Share this post


Link to post
Share on other sites
Advertisement
You might want to look into tolua, at http://www.tecgraf.puc-rio.br/~celes/tolua/

Tolua can generate the binding code to access your C++ code from Lua. All you basically have to do is run tolua over the headers that you want to be accessible from Lua, and compile the generated bindings file together with your project. I guess the tolua guys have a manual with detailed instructions. Good luck!

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!