Page 1 of 1

sending c variables to lua

Posted: Mon Jun 14, 2010 8:09 pm
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

Re: sending c variables to lua

Posted: Tue Jun 15, 2010 12:01 am
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

Re: sending c variables to lua

Posted: Tue Jun 15, 2010 12:16 am
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!!!