I already tried something with lua and C ++, and all the "light" functions work, that is, they can call the C ++ function from lua and vice versa, however I have 1 main problem.
its a tiny game / simulator in the making, and I wanted to use lua, ode and make my own tiny interface (and not direct like LuaOde). My code structure is as follows
main class
v = new Visual();
p = new Physics();
l = new LuaAddons();
Now, of course, I want to talk with physics from LuaAddons. so in LuaAddons.cpp I have:
int setWorldGravity(lua_State* L){
float x = luaL_checknumber(L, 1);
float y = luaL_checknumber(L, 2);
float z = luaL_checknumber(L, 3);
return 0;
}
Thus, I can just call setWorldGravity(1, 2, 3)in my .lua file, and the above function is called accordingly with the correct parameters passed.
. int setWorldGravity , ODE .
, Physics.h :
void setWorldGravity(float x, float y, float z);
ODE :
void Physics::setWorldGravity( float x, float y, float z ){
dWorldSetGravity (world_, x, y, z);
}
world_ - , , .
, int setWorldGravity(lua_State* L) LuaAddons (.. LuaAddons.h, ), (); . , LuaAddons , .
:
l = new LuaAddons(p);
( LuaAddons.h)
LuaAddons(Physics* p);
( LuaAddons.cpp)
LuaAddons(Physics* p){
phys_ = p; // where phys_ is a private member of LuaAddons.h
}
,
phys_->setWorldGravity(x, y, z);
, ( ) .
Lunar.h.
lua -, .h _- > . ( ) .lua, :
la_ = LuaAddons()
la_:setWorldGravity(1, 2, 3)
, . , ODE, ( .. - : P)
, lua, , . , .
, , .
/ .