sending c variables to lua

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
WSPSNIPER
Chaos Rift Regular
Chaos Rift Regular
Posts: 145
Joined: Sun Jan 03, 2010 6:19 pm
Current Project: top down shooter
Favorite Gaming Platforms: ps3
Programming Language of Choice: c++

sending c variables to lua

Post by WSPSNIPER »

ok here is the situation. i am using luabridge because it is very nice and small. it allows me to export class definitions to lua but i want to pass the class variables to lua.

i have been reading about the stack and the doc is not very clear, i have been working with lua_newuserdata, luaL_getmetatable, and lua_setmetatable for about 4 hours now and im getting nowhere. i want to create a function to create a global variable in lua. here is the abstract code( what i want it to look like )

Code: Select all

Test test;
Mgr->SetGlobal("test", &test);

std::cout << test.getX() << std::endl; // output = 0;

Mgr->DoFile("test.lua"); // just a wrapper for luaL_dofile

std::cout << test.getX() << std::endl; // output = 4;
in lua

Code: Select all

test:setX(4)

now test will be in lua and in c++ is there any way to do this, cause i know i can do this in luabind but its huge and uses boost so i want to stay away from it.

thanks for any info you can give. im going to go look for more resources lol
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: sending c variables to lua

Post by Ginto8 »

ok your best bet is to use a lua function and call it with a certain parameter. IDK how references are handled in lua, but in some way you want to push the reference onto the stack, then call the function. Something like that should work.

PS sorry if it's a bit confusing, it's like 1am where I am
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
WSPSNIPER
Chaos Rift Regular
Chaos Rift Regular
Posts: 145
Joined: Sun Jan 03, 2010 6:19 pm
Current Project: top down shooter
Favorite Gaming Platforms: ps3
Programming Language of Choice: c++

Re: sending c variables to lua

Post by WSPSNIPER »

Ginto8 wrote:ok your best bet is to use a lua function and call it with a certain parameter. IDK how references are handled in lua, but in some way you want to push the reference onto the stack, then call the function. Something like that should work.

PS sorry if it's a bit confusing, it's like 1am where I am

thanks i was thinking about aborting the mission and doing that lol, i am trying to look at what lua bind did but they have me running in circles with abstraction... i found it oh no this is a constructor call to another class that calls a method from another class... infinate loop!!!
Post Reply