Sign in to follow this  
of_ownage

LUA getting variables from the c++ project

Recommended Posts

of_ownage    110
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
Sponzie    122
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

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