object_L.cpp

Go to the documentation of this file.
00001 #include "lugre_prefix.h"
00002 #include "lugre_luabind.h"
00003 #include "lugre_ode.h"
00004 #include "object.h"
00005 
00006 extern "C" {
00007     #include "lua.h"
00008     #include "lauxlib.h"
00009     #include "lualib.h"
00010 }
00011 using namespace Lugre;
00012 
00013 
00014 class cObject_L : public cLuaBind<cObject> { public:
00016         virtual void RegisterMethods    (lua_State *L) { PROFILE
00017             lua_register(L,"CreateObject",      &cObject_L::CreateObject);
00018 
00019             #define REGISTER_METHOD(methodname) mlMethod.push_back(make_luaL_reg(#methodname,&cObject_L::methodname));
00020             REGISTER_METHOD(Destroy);
00021             REGISTER_METHOD(GetID);
00022             REGISTER_METHOD(SetID);
00023             REGISTER_METHOD(ResetResyncCounterLow);
00024             REGISTER_METHOD(SetParentLocation);
00025             REGISTER_METHOD(SetPhysicForm);
00026             REGISTER_METHOD(SetController);
00027             REGISTER_METHOD(SetGfx);
00028         }
00029 
00031         virtual void RegisterMembers    () { PROFILE
00032             cObject* prototype = new cObject(); // memory leak : never deleted, but better than side effects
00033             cMemberVar_REGISTER(prototype,  kVarType_int,           miLastChangeTime,       0);
00034             cMemberVar_REGISTER(prototype,  kVarType_int,           miResyncCounterHigh,    0);
00035             cMemberVar_REGISTER(prototype,  kVarType_Float,         mfBoundingRad,          0);
00036             cMemberVar_REGISTER(prototype,  kVarType_Float,         mfDistToLocationCenter, 0);
00037             cMemberVar_REGISTER(prototype,  kVarType_Float,         mfMaxSpeed,             0);
00038             cMemberVar_REGISTER(prototype,  kVarType_bool,          mbResynced,     0);
00039             cMemberVar_REGISTER(prototype,  kVarType_Vector3,       mvPos,          0);
00040             cMemberVar_REGISTER(prototype,  kVarType_Vector3,       mvVel,          0);
00041             cMemberVar_REGISTER(prototype,  kVarType_Vector3,       mvAccel,        0);
00042             cMemberVar_REGISTER(prototype,  kVarType_Quaternion,    mqRot,          0);
00043             cMemberVar_REGISTER(prototype,  kVarType_Quaternion,    mqTurn,         0);
00044         }
00045 
00046     // static methods exported to lua
00047 
00049         static int              CreateObject        (lua_State *L) { PROFILE 
00050             return CreateUData(L,new cObject()); 
00051         }
00052 
00053     // object methods exported to lua
00054         
00055         static int  Destroy             (lua_State *L) { PROFILE 
00056             delete checkudata_alive(L);
00057             return 0; 
00058         }
00059         
00061         static int          GetID   (lua_State *L) { PROFILE 
00062             lua_pushnumber(L,checkudata_alive(L)->GetID());
00063             return 1; 
00064         }
00065         
00067         static int          SetID   (lua_State *L) { PROFILE 
00068             checkudata_alive(L)->SetID(luaL_checkint(L,2));
00069             return 0; 
00070         }
00071         
00073         static int          SetGfx  (lua_State *L) { PROFILE 
00074             checkudata_alive(L)->mpGfx3D = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? cLuaBind<cGfx3D>::checkudata(L,2) : 0;
00075             return 0; 
00076         }
00077         
00079         static int          ResetResyncCounterLow   (lua_State *L) { PROFILE 
00080             checkudata_alive(L)->miResyncCounterLow = 0;
00081             return 0; 
00082         }
00083         
00085         static int          SetParentLocation   (lua_State *L) { PROFILE 
00086             cLocation* pLocation = cLuaBind<cLocation>::checkudata(L,2);
00087             checkudata_alive(L)->SetParentLocation(pLocation);
00088             return 0; 
00089         }
00090         
00091         
00093         static int          SetPhysicForm   (lua_State *L) { PROFILE 
00094             #ifdef ENABLE_ODE
00095             cOdeObject *o = checkudata_alive(L)->mpPhysicForm;
00096             if(o){
00097                 delete o;
00098             }
00099             checkudata_alive(L)->mpPhysicForm = cLuaBind<cOdeObject>::checkudata_alive(L,2);
00100             #endif
00101             return 0; 
00102         }
00103         
00105         static int          SetController   (lua_State *L) { PROFILE 
00106             cObjectController* p = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? cLuaBind<cObjectController>::checkudata(L,2) : 0;
00107             checkudata_alive(L)->SetController(p);
00108             return 0; 
00109         }
00110 
00111         virtual const char* GetLuaTypeName () { return "sfz.obj"; }
00112 };
00113 
00115 void    cObject::LuaRegister    (lua_State *L) { PROFILE
00116     cLuaBind<cObject>::GetSingletonPtr(new cObject_L())->LuaRegister(L);
00117 }

Generated on Wed Feb 8 06:00:13 2012 for cpp by  doxygen 1.5.6