diff --git a/doc/samples/meshviewer/scenesetup.cpp b/doc/samples/meshviewer/scenesetup.cpp index 74e942dd..a86ff561 100644 --- a/doc/samples/meshviewer/scenesetup.cpp +++ b/doc/samples/meshviewer/scenesetup.cpp @@ -159,86 +159,76 @@ SceneSetupLuaObject::~SceneSetupLuaObject() //----------------------------------------------------------------------------- SceneSetupLuaObject* SceneSetupLuaObject::New(lua_State* l, int arg_nb) { - UNUSED(l); UNUSED(arg_nb); - LuaStack s(l); - LuaString n; - s >> n; - return new SceneSetupLuaObject(n()); + auto s = LuaStack::Begin(l); + auto n = s.Get(); + return new SceneSetupLuaObject(n); } //-- Setup command ------------------------------------------------------------ int SceneSetupLuaObject::AddLight(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - LuaString t; - s >> o >> t; - o->m_setup->AddLight(FindValue(t().C())); - return 0; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); + auto t = s.Get(); + o->m_setup->AddLight(FindValue(t.C())); + return s.End(); } int SceneSetupLuaObject::SetupScene(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - s >> o; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); o->m_setup->SetupScene(); - return 0; + return s.End(); } //-- main funcs --------------------------------------------------------------- int SceneSetupLuaObject::SetPosition(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - LuaVec3 c; - s >> o >> c; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); + auto c = s.Get(); o->m_setup->SetPosition(c); - return 0; + return s.End(); } int SceneSetupLuaObject::SetLookAt(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - LuaVec3 c; - s >> o >> c; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); + auto c = s.Get(); o->m_setup->SetLookAt(c); - return 0; + return s.End(); } int SceneSetupLuaObject::SetColor(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - LuaColor c; - s >> o >> c; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); + auto c = s.Get(); o->m_setup->SetColor(c); - return 0; + return s.End(); } int SceneSetupLuaObject::Show(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - LuaDisplay e; - s >> o >> e; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); + auto e = s.GetEnum(); o->m_setup->Show(e); - return 0; + return s.End(); } int SceneSetupLuaObject::Hide(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - LuaDisplay e; - s >> o >> e; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); + auto e = s.GetEnum(); o->m_setup->Hide(e); - return 0; + return s.End(); } int SceneSetupLuaObject::Toggle(lua_State* l) { - LuaStack s(l); - LuaSSetupPtr o; - LuaDisplay e; - s >> o >> e; + auto s = LuaStack::Begin(l); + auto o = s.GetPtr(); + auto e = s.GetEnum(); o->m_setup->Toggle(e); - return 0; + return s.End(); } //----------------------------------------------------------------------------- @@ -264,7 +254,7 @@ const LuaObjectLibrary* SceneSetupLuaObject::GetLib() }, //Variables { { nullptr, nullptr, nullptr } }); - return &lib; + return &lib; } //----------------------------------------------------------------------------- diff --git a/doc/samples/meshviewer/scenesetup.h b/doc/samples/meshviewer/scenesetup.h index 39165715..23694a7b 100644 --- a/doc/samples/meshviewer/scenesetup.h +++ b/doc/samples/meshviewer/scenesetup.h @@ -103,12 +103,10 @@ public: bool m_show_gizmo; bool m_show_lights; }; -typedef Lolua::VarEnum LuaDisplay; //----------------------------------------------------------------------------- class SceneSetupLuaObject : public LuaObject { - typedef Lolua::VarPtr LuaSSetupPtr; public: //------------------------------------------------------------------------- SceneSetupLuaObject(String& name); diff --git a/doc/tutorial/14_lol_lua.cpp b/doc/tutorial/14_lol_lua.cpp index de5b5cd0..ce0348ab 100644 --- a/doc/tutorial/14_lol_lua.cpp +++ b/doc/tutorial/14_lol_lua.cpp @@ -23,7 +23,6 @@ using namespace lol; //----------------------------------------------------------------------------- class DemoObject : public LuaObject { - typedef Lolua::VarPtr LuaDemoObjectPtr; public: DemoObject() : LuaObject() {} virtual ~DemoObject() {} diff --git a/src/easymesh/easymeshlua.cpp b/src/easymesh/easymeshlua.cpp index a68c6a7e..a36ab4d8 100644 --- a/src/easymesh/easymeshlua.cpp +++ b/src/easymesh/easymeshlua.cpp @@ -81,10 +81,9 @@ EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State* l, int arg_nb) { UNUSED(l); UNUSED(arg_nb); - LuaStack s(l); - LuaString n("", true); - s >> n; - return new EasyMeshLuaObject(n()); + LuaStack s = LuaStack::Begin(l); + String str = s.Get("", true); + return new EasyMeshLuaObject(str); } //----------------------------------------------------------------------------- diff --git a/src/easymesh/easymeshlua.h b/src/easymesh/easymeshlua.h index 35e76140..5fb32ea8 100644 --- a/src/easymesh/easymeshlua.h +++ b/src/easymesh/easymeshlua.h @@ -18,7 +18,6 @@ namespace lol //----------------------------------------------------------------------------- class EasyMeshLuaObject : public LuaObject { - typedef Lolua::VarPtr EzMeshPtr; EasyMesh m_instance; public: //------------------------------------------------------------------------- @@ -33,604 +32,583 @@ public: //------------------------------------------------------------------------- static int AppendCylinder(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 nsides; - LuaFloat h, d1, d2; - LuaBool dualside(false, true), smooth(false, true), close(false, true); - s >> m >> nsides >> h >> d1 >> d2 >> dualside >> smooth >> close; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto nsides = s.Get(); + auto h = s.Get(); + auto d1 = s.Get(); + auto d2 = s.Get(); + auto dualside = s.Get(false, true); + auto smooth = s.Get(false, true); + auto close = s.Get(false, true); m->m_instance.AppendCylinder(nsides, h, d1, d2, dualside, smooth, close); - return 0; + return s.End(); } static int AppendSphere(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 ndivisions; - LuaFloat d; - s >> m >> ndivisions >> d; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto ndivisions = s.Get(); + auto d = s.Get(); m->m_instance.AppendSphere(ndivisions, d); - return 0; + return s.End(); } static int AppendCapsule(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 ndivisions; - LuaFloat h, d; - s >> m >> ndivisions >> h >> d; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto ndivisions = s.Get(); + auto h = s.Get(); + auto d = s.Get(); m->m_instance.AppendCapsule(ndivisions, h, d); - return 0; + return s.End(); } static int AppendTorus(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 ndivisions; - LuaFloat d1, d2; - s >> m >> ndivisions >> d1 >> d2; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto ndivisions = s.Get(); + auto d1 = s.Get(); + auto d2 = s.Get(); m->m_instance.AppendTorus(ndivisions, d1, d2); - return 0; + return s.End(); } static int AppendBox(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaVec3 size; - LuaFloat chamf(0.f, true); - LuaBool smooth(false, true); - s >> m >> size >> chamf >> smooth; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto size = s.Get(); + auto chamf = s.Get(0.f, true); + auto smooth = s.Get(false, true); m->m_instance.AppendBox(size, chamf, smooth); - return 0; + return s.End(); } static int AppendStar(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 nbranches; - LuaFloat d1, d2; - LuaBool fade(false, true), fade2(false, true); - s >> m >> nbranches >> d1 >> d2 >> fade >> fade2; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto nbranches = s.Get(); + auto d1 = s.Get(); + auto d2 = s.Get(); + auto fade = s.Get(false, true); + auto fade2 = s.Get(false, true); m->m_instance.AppendStar(nbranches, d1, d2, fade, fade2); - return 0; + return s.End(); } static int AppendExpandedStar(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 nbranches; - LuaFloat d1, d2, extrad(0.f, true); - s >> m >> nbranches >> d1 >> d2 >> extrad; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto nbranches = s.Get(); + auto d1 = s.Get(); + auto d2 = s.Get(); + auto extrad = s.Get(0.f, true); m->m_instance.AppendExpandedStar(nbranches, d1, d2, extrad); - return 0; + return s.End(); } static int AppendDisc(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 nsides; - LuaFloat d; - LuaBool fade(false, true); - s >> m >> nsides >> d >> fade; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto nsides = s.Get(); + auto d = s.Get(); + auto fade = s.Get(false, true); m->m_instance.AppendDisc(nsides, d, fade); - return 0; + return s.End(); } static int AppendSimpleTriangle(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat d; - LuaBool fade(false, true); - s >> m >> d >> fade; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto d = s.Get(); + auto fade = s.Get(false, true); m->m_instance.AppendSimpleTriangle(d, fade); - return 0; + return s.End(); } static int AppendSimpleQuad(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat size; - LuaBool fade(false, true); - s >> m >> size >> fade; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto size = s.Get(); + auto fade = s.Get(false, true); m->m_instance.AppendSimpleQuad(size, fade); - return 0; + return s.End(); } static int AppendCog(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 nbsides; - LuaFloat h, sidemul(0.f, true); - LuaVec2 d0, d1, d2; - LuaBool offset(false, true); - s >> m >> nbsides >> h >> d0 >> d1 >> d2 >> sidemul >> offset; - m->m_instance.AppendCog(nbsides, h, d0().x, d0().y, d1().x, d1().y, d2().x, d2().y, sidemul, offset); - return 0; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto nbsides = s.Get(); + auto h = s.Get(); + auto sidemul = s.Get(0.f, true); + auto d0 = s.Get(); + auto d1 = s.Get(); + auto d2 = s.Get(); + auto offset = s.Get(false, true); + m->m_instance.AppendCog(nbsides, h, d0.x, d0.y, d1.x, d1.y, d2.x, d2.y, sidemul, offset); + return s.End(); } //------------------------------------------------------------------------- static int TranslateX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat f; - s >> m >> f; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto f = s.Get(); m->m_instance.TranslateX(f); - return 0; + return s.End(); } static int TranslateY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat f; - s >> m >> f; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto f = s.Get(); m->m_instance.TranslateY(f); - return 0; + return s.End(); } static int TranslateZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat f; - s >> m >> f; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto f = s.Get(); m->m_instance.TranslateZ(f); - return 0; + return s.End(); } static int Translate(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaVec3 v; - s >> m >> v; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto v = s.Get(); m->m_instance.Translate(v); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int RotateX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat a; - s >> m >> a; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto a = s.Get(); m->m_instance.RotateX(a); - return 0; + return s.End(); } static int RotateY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat a; - s >> m >> a; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto a = s.Get(); m->m_instance.RotateY(a); - return 0; + return s.End(); } static int RotateZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat a; - s >> m >> a; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto a = s.Get(); m->m_instance.RotateZ(a); - return 0; + return s.End(); } static int Rotate(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat a; - LuaVec3 v; - s >> m >> a >> v; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto a = s.Get(); + auto v = s.Get(); m->m_instance.Rotate(a, v); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int ScaleX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat x; - s >> m >> x; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto x = s.Get(); m->m_instance.ScaleX(x); - return 0; + return s.End(); } static int ScaleY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat y; - s >> m >> y; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto y = s.Get(); m->m_instance.ScaleY(y); - return 0; + return s.End(); } static int ScaleZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat z; - s >> m >> z; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto z = s.Get(); m->m_instance.ScaleZ(z); - return 0; + return s.End(); } static int Scale(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaVec3 v; - s >> m >> v; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto v = s.Get(); m->m_instance.Scale(v); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int RadialJitter(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat f; - s >> m >> f; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto f = s.Get(); m->m_instance.RadialJitter(f); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int TaperX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat y, z, xoff(0.f, true); - LuaBool abs(true, true); - s >> m >> y >> z >> xoff >> abs; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto y = s.Get(); + auto z = s.Get(); + auto xoff = s.Get(0.f, true); + auto abs = s.Get(true, true); m->m_instance.TaperX(y, z, xoff, abs); - return 0; + return s.End(); } static int TaperY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat x, z, yoff(0.f, true); - LuaBool abs(true, true); - s >> m >> x >> z >> yoff >> abs; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto x = s.Get(); + auto z = s.Get(); + auto yoff = s.Get(0.f, true); + auto abs = s.Get(true, true); m->m_instance.TaperY(x, z, yoff, abs); - return 0; + return s.End(); } static int TaperZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat x, y, zoff(0.f, true); - LuaBool abs(true, true); - s >> m >> x >> y >> zoff >> abs; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto x = s.Get(); + auto y = s.Get(); + auto zoff = s.Get(0.f, true); + auto abs = s.Get(true, true); m->m_instance.TaperZ(x, y, zoff, abs); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int TwistX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.TwistX(t, toff); - return 0; + return s.End(); } static int TwistY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.TwistY(t, toff); - return 0; + return s.End(); } static int TwistZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.TwistZ(t, toff); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int ShearX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat y, z, xoff(0.f, true); - LuaBool abs(true, true); - s >> m >> y >> z >> xoff >> abs; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto y = s.Get(); + auto z = s.Get(); + auto xoff = s.Get(0.f, true); + auto abs = s.Get(true, true); m->m_instance.ShearX(y, z, xoff, abs); - return 0; + return s.End(); } static int ShearY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat x, z, yoff(0.f, true); - LuaBool abs(true, true); - s >> m >> x >> z >> yoff >> abs; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto x = s.Get(); + auto z = s.Get(); + auto yoff = s.Get(0.f, true); + auto abs = s.Get(true, true); m->m_instance.ShearY(x, z, yoff, abs); - return 0; + return s.End(); } static int ShearZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat x, y, zoff(0.f, true); - LuaBool abs(true, true); - s >> m >> x >> y >> zoff >> abs; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto x = s.Get(); + auto y = s.Get(); + auto zoff = s.Get(0.f, true); + auto abs = s.Get(true, true); m->m_instance.ShearZ(x, y, zoff, abs); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int StretchX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat y, z, xoff(0.f, true); - s >> m >> y >> z >> xoff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto y = s.Get(); + auto z = s.Get(); + auto xoff = s.Get(0.f, true); m->m_instance.StretchX(y, z, xoff); - return 0; + return s.End(); } static int StretchY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat x, z, yoff(0.f, true); - s >> m >> x >> z >> yoff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto x = s.Get(); + auto z = s.Get(); + auto yoff = s.Get(0.f, true); m->m_instance.StretchY(x, z, yoff); - return 0; + return s.End(); } static int StretchZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat x, y, zoff(0.f, true); - s >> m >> x >> y >> zoff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto x = s.Get(); + auto y = s.Get(); + auto zoff = s.Get(0.f, true); m->m_instance.StretchZ(x, y, zoff); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int BendXY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.BendXY(t, toff); - return 0; + return s.End(); } static int BendXZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.BendXZ(t, toff); - return 0; + return s.End(); } static int BendYX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.BendYX(t, toff); - return 0; + return s.End(); } static int BendYZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.BendYZ(t, toff); - return 0; + return s.End(); } static int BendZX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.BendZX(t, toff); - return 0; + return s.End(); } static int BendZY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat t, toff(0.f, true); - s >> m >> t >> toff; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto t = s.Get(); + auto toff = s.Get(0.f, true); m->m_instance.BendZY(t, toff); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int MirrorX(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.MirrorX(); - return 0; + return s.End(); } static int MirrorY(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.MirrorY(); - return 0; + return s.End(); } static int MirrorZ(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.MirrorZ(); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int LoopStart(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 loopnb; - s >> m >> loopnb; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto loopnb = s.Get(); m->m_instance.LoopStart(loopnb); - return 0; + return s.End(); } static int LoopEnd(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.LoopEnd(); - return 0; + return s.End(); } static int OpenBrace(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.OpenBrace(); - return 0; + return s.End(); } static int CloseBrace(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.CloseBrace(); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int ToggleScaleWinding(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.ToggleScaleWinding(); - return 0; + return s.End(); } static int ToggleQuadWeighting(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.ToggleQuadWeighting(); - return 0; + return s.End(); } static int TogglePostBuildNormal(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.TogglePostBuildNormal(); - return 0; + return s.End(); } static int ToggleVerticeNoCleanup(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.ToggleVerticeNoCleanup(); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int VerticesMerge(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.VerticesMerge(); - return 0; + return s.End(); } static int VerticesSeparate(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.VerticesSeparate(); - return 0; + return s.End(); } static int VerticesCleanup(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - s >> m; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); m->m_instance.VerticesCleanup(); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int Duplicate(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaVec3 ds(vec3(1.f)); - s >> m >> ds; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto ds = s.Get(vec3(1.f)); m->m_instance.DupAndScale(ds, true); - return 0; + return s.End(); } static int Smooth(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 pass, split_per_pass, smooth_per_pass; - s >> m >> pass >> split_per_pass >> smooth_per_pass; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto pass = s.Get(); + auto split_per_pass = s.Get(); + auto smooth_per_pass = s.Get(); m->m_instance.SmoothMesh(pass, split_per_pass, smooth_per_pass); - return 0; + return s.End(); } static int SplitTriangles(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaInt32 pass; - s >> m >> pass; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto pass = s.Get(); m->m_instance.SplitTriangles(pass); - return 0; + return s.End(); } static int Chamfer(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaFloat f; - s >> m >> f; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto f = s.Get(); m->m_instance.Chamfer(f); - return 0; + return s.End(); } //------------------------------------------------------------------------- static int SetCurColor(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaColor c; - s >> m >> c; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto c = s.Get(); m->m_instance.SetCurColor(c); - return 0; + return s.End(); } static int SetCurColorA(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaColor c; - s >> m >> c; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto c = s.Get(); m->m_instance.SetCurColorA(c); - return 0; + return s.End(); } static int SetCurColorB(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaColor c; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto c = s.Get(); m->m_instance.SetCurColorB(c); - return 0; + return s.End(); } static int SetVertColor(lua_State* l) { - LuaStack s(l); - EzMeshPtr m; - LuaColor c; - s >> m >> c; + auto s = LuaStack::Begin(l); + auto m = s.GetPtr(); + auto c = s.Get(); m->m_instance.SetVertColor(c); - return 0; + return s.End(); } /* (csgu|csgunion) { return token::T_CSGUNION; } diff --git a/src/lolua/baselua.cpp b/src/lolua/baselua.cpp index 8a1c035d..faffef0f 100644 --- a/src/lolua/baselua.cpp +++ b/src/lolua/baselua.cpp @@ -40,8 +40,9 @@ class LuaBaseData int status = luaL_dostring(l, s.C()); if (status == 1) { - LuaString error; error.Get(l, -1); - msg::error("Lua error %s\n", error().C()); + auto stack = LuaStack::Begin(l, -1); + auto error = stack.Get(); + msg::error("Lua error %s\n", error.C()); lua_pop(l, 1); } return status; @@ -53,8 +54,8 @@ class LuaBaseData if (lua_isnoneornil(l, 1)) return LUA_ERRFILE; - LuaCharPtr var; var.Get(l, 1); - char const *filename = var;// lua_tostring(l, 1); + auto stack = LuaStack::Begin(l); + char const *filename = stack.Get(); int status = LUA_ERRFILE; File f; @@ -76,8 +77,9 @@ class LuaBaseData msg::error("could not find Lua file %s\n", filename); else if (status == 1) { - LuaString error; error.Get(l, -1); - msg::error("Lua error %s\n", error().C()); + stack.SetIndex(-1); + auto error = stack.Get(); + msg::error("Lua error %s\n", error.C()); lua_pop(l, 1); } diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index 035a641b..c4316558 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -16,9 +16,6 @@ #pragma once -#define OLD_VAR_SYSTEM true -#define NEW_VAR_SYSTEM true - namespace lol { @@ -134,20 +131,19 @@ public: { "New", New }, { "Store", Store }, { "__gc", Del }, + { "__tostring", ToString }, + { "__add", OpAdd }, + { "__sub", OpSubstract }, + { "__mul", OpMultiply }, + { "__div", OpDivide }, + { "__mod", OpModulo }, + { "__unm", OpUnaryNeg }, + { "__concat", OpConcat }, + { "__eq", CmpEqual }, + { "__lt", CmpLessThan }, + { "__le", CmpLessEqual }, { NULL, NULL } }; - //TODO: Touky: Implement that - //__tostring : ToString - //__add : Addition(+) - //__sub : Subtraction(-) - //__mul : Multiplication(*) - //__div : Division(/ ) - //__mod : Modulos(%) - //__unm : Unary - , used for negation on numbers - //__concat : Concatenation(..) - //__eq : Equality(== ) - //__lt : Less than(<) - //__le : Less than or equal to(<= ) //Create Static metatable luaL_newmetatable(l, GetStaticName()); @@ -235,6 +231,18 @@ protected: //------------------------------------------------------------------------- template static int Store(lua_State * l); template static int Del(lua_State * l); + //------------------------------------------------------------------------- + template static int ToString(lua_State* l) { ASSERT(false); return 0; } + template static int OpAdd(lua_State* l) { ASSERT(false); return 0; } + template static int OpSubstract(lua_State* l) { ASSERT(false); return 0; } + template static int OpMultiply(lua_State* l) { ASSERT(false); return 0; } + template static int OpDivide(lua_State* l) { ASSERT(false); return 0; } + template static int OpModulo(lua_State* l) { ASSERT(false); return 0; } + template static int OpUnaryNeg(lua_State* l) { ASSERT(false); return 0; } + template static int OpConcat(lua_State* l) { ASSERT(false); return 0; } + template static int CmpEqual(lua_State* l) { ASSERT(false); return 0; } + template static int CmpLessThan(lua_State* l) { ASSERT(false); return 0; } + template static int CmpLessEqual(lua_State* l) { ASSERT(false); return 0; } }; //----------------------------------------------------------------------------- @@ -248,683 +256,47 @@ public: } }; -//----------------------------------------------------------------------------- -#if OLD_VAR_SYSTEM - -//----------------------------------------------------------------------------- -template -class VarPtr -{ -protected: - T* m_value = nullptr; - bool m_optional = false; - -public: - VarPtr(bool optional = false) - { - m_optional = optional; - } - VarPtr(T* value, bool optional = false) - : VarPtr(optional) - { - m_value = value; - } - VarPtr(lua_State* l, int& index, bool optional = false) - : VarPtr(optional) - { - GetInc(l, index); - } - VarPtr(T* value, lua_State* l, int& index, bool optional = false) - : VarPtr(value, optional) - { - GetInc(l, index); - } - - inline T* operator ()() { return m_value; } - inline T* operator ->() { return m_value; } - inline T* operator=(T* value) { m_value = value; } - inline T* GetValue() { return m_value; } - inline bool IsValid(lua_State* l, int index) - { - return InnerIsValid(l, index); - } - inline bool IsOptional() - { - return m_optional; - } -private: - inline void GetInc(lua_State* l, int& index) - { - bool is_nil = lua_isnil(l, index); - if (!m_optional || (!is_nil && InnerIsValid(l, index))) - { - ASSERT(!is_nil); - InnerGet(l, index); - } - } -public: - inline void Get(lua_State* l, int index) - { - int idx = index; - GetInc(l, idx); - } - inline int Return(lua_State* l) - { - InnerPush(l); - return 1; - } - -protected: - virtual bool InnerIsValid(lua_State* l, int index) - { - return !!lua_isuserdata(l, index); - } - virtual void InnerGet(lua_State* l, int& index) - { - T** obj = static_cast(luaL_checkudata(l, index++, ObjectHelper::GetMethodName())); - m_value = obj ? *obj : nullptr; - } - void InnerPush(lua_State* l) - { - T** data = (T**)lua_newuserdata(l, sizeof(T*)); - *data = m_value; - } -}; - -//----------------------------------------------------------------------------- -/* TODO: FIX THAT TOUKY !! -template -class VarPtrLight -{ -public: - VarPtrLight(bool optional = false) : VarPtr(optional) { } - VarPtrLight(T* value, bool optional = false) : VarPtr(value, optional) { } - VarPtrLight(lua_State* l, int& index, bool optional = false) : VarPtr(l, index, optional) { } - VarPtrLight(T* value, lua_State* l, int& index, bool optional = false) : VarPtr(value, l, index, optional) { } -protected: - virtual void InnerGet(lua_State* l, int& index) - { - T** obj = static_cast(luaL_testudata(l, index++, ObjectDef::GetMethodName())); - m_value = obj ? *obj : nullptr; - } -}; -*/ - -//----------------------------------------------------------------------------- -template -class Var -{ -protected: - bool m_optional = false; - T m_value; - -public: - Var(bool optional = false) - { - m_optional = optional; - InnerInit(); - } - Var(T value, bool optional = false) - { - m_optional = optional; - m_value = value; - } - Var(lua_State* l, int& index, bool optional = false) - { - m_optional = optional; - GetInc(l, index); - } - Var(T value, lua_State* l, int& index, bool optional = false) - { - m_optional = optional; - m_value = value; - GetInc(l, index); - } - inline operator T() { return m_value; } - inline T& operator ()() { return m_value; } - inline T& GetValue() { return m_value; } - inline bool IsValid(lua_State* l, int index) - { - return InnerIsValid(l, index); - } - inline bool IsOptional() - { - return m_optional; - } -private: - void GetInc(lua_State* l, int& index) - { - bool is_nil = lua_isnil(l, index); - if (!m_optional || (!is_nil && InnerIsValid(l, index))) - { - ASSERT(!is_nil); - InnerGet(l, index); - } - } -public: - inline void Get(lua_State* l, int index) - { - int idx = index; - GetInc(l, idx); - } - inline int Return(lua_State* l) - { - return InnerPush(l); - } - inline Var& operator-(const T& value) { m_value - value; return *this; } - inline Var& operator+(const T& value) { m_value + value; return *this; } - inline Var& operator*(const T& value) { m_value * value; return *this; } - inline Var& operator/(const T& value) { m_value / value; return *this; } - inline Var& operator=(const T& value) { m_value = value; return *this; } - inline Var& operator-=(const T& value) { m_value -= value; return *this; } - inline Var& operator+=(const T& value) { m_value += value; return *this; } - inline Var& operator*=(const T& value) { m_value *= value; return *this; } - inline Var& operator/=(const T& value) { m_value /= value; return *this; } - inline Var& operator-(const Var& o) { m_value - o.m_value; return *this; } - inline Var& operator+(const Var& o) { m_value + o.m_value; return *this; } - inline Var& operator*(const Var& o) { m_value * o.m_value; return *this; } - inline Var& operator/(const Var& o) { m_value / o.m_value; return *this; } - inline Var& operator=(const Var& o) { m_value = o.m_value; return *this; } - inline Var& operator-=(const Var& o) { m_value -= o.m_value; return *this; } - inline Var& operator+=(const Var& o) { m_value += o.m_value; return *this; } - inline Var& operator*=(const Var& o) { m_value *= o.m_value; return *this; } - inline Var& operator/=(const Var& o) { m_value /= o.m_value; return *this; } - inline bool operator==(const T& value) { return m_value == value; } - inline bool operator!=(const T& value) { return m_value != value; } - inline bool operator==(const Var& o) { return m_value == o.m_value; } - inline bool operator!=(const Var& o) { return m_value != o.m_value; } - -protected: - void InnerInit() { m_value = T(0); } - bool InnerIsValid(lua_State* l, int index) { UNUSED(l); UNUSED(index); ASSERT(false); return false; } - void InnerGet(lua_State* l, int& index) { UNUSED(l); UNUSED(index); ASSERT(false); } - int InnerPush(lua_State* l) { UNUSED(l); ASSERT(false); return 0; } -}; - -//----------------------------------------------------------------------------- -#ifndef BASE_TYPES -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - return lua_isboolean(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - m_value = !!lua_toboolean(l, index++); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - lua_pushboolean(l, m_value); - return 1; -} -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - return !!lua_isstring(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - m_value = lua_tostring(l, index++); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - lua_pushstring(l, m_value); - return 1; -} -//----------------------------------------------------------------------------- -template<> inline void Var::InnerInit() -{ - m_value = String(); -} -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - Var v; - return v.IsValid(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - Var v(l, index); - m_value = v(); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - Var v; - v = m_value.C(); - return v.Return(l); -} -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - return !!lua_isnumber(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - m_value = lua_tonumber(l, index++); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - lua_pushnumber(l, m_value); - return 1; -} -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - Var v; - return v.IsValid(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - Var v(l, index); - m_value = (float)v(); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - Var v = (double)m_value; - return v.Return(l); -} - -#if 0 -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - return !!lua_isnumber(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - m_value = lua_tointeger(l, index++); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - lua_pushinteger(l, m_value); - return 1; -} -#endif - -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - Var v; - return v.IsValid(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - Var v(l, index); - m_value = (int32_t)v(); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - Var v = (int64_t)m_value; - return v.Return(l); -} - -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - return !!lua_isnumber(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - m_value = (uint32_t)(lua_Unsigned)lua_tointeger(l, index++); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - lua_pushinteger(l, (lua_Integer)m_value); - return 1; -} - -#if 0 -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - Var v; - return v.IsValid(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - Var v(l, index); - m_value = (uint64_t)v(); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - Var v = (uint32_t)m_value; - return v.Return(l); -} -#endif - -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - Var x; - return x.IsValid(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - Var x(l, index); - Var y(x(), l, index, true); - m_value = vec2(x, y); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - Var x = m_value.x; - Var y = m_value.y; - return (x.Return(l) + y.Return(l)); -} -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - Var x; - return x.IsValid(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - Var x(l, index); - Var y(x(), l, index, true); - Var z(x(), l, index, true); - m_value = vec3(x, y, z); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - Var x = m_value.x; - Var y = m_value.y; - Var z = m_value.z; - return (x.Return(l) + y.Return(l) + z.Return(l)); -} -//----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(lua_State* l, int index) -{ - Var x; - return x.IsValid(l, index); -} -template<> inline void Var::InnerGet(lua_State* l, int& index) -{ - Var x(l, index); - Var y(x(), l, index, true); - Var z(x(), l, index, true); - Var w(x(), l, index, true); - m_value = vec4(x, y, z, w); -} -template<> inline int Var::InnerPush(lua_State* l) -{ - Var x = m_value.x; - Var y = m_value.y; - Var z = m_value.z; - Var w = m_value.w; - return (x.Return(l) + y.Return(l) + z.Return(l) + w.Return(l)); -} -#endif //BASE_TYPES - -//----------------------------------------------------------------------------- -#ifndef CUSTOM_TYPES -class VarColor -{ -protected: - Var m_value; - -public: - VarColor(bool optional = false) - { - m_value = Var(optional); - InnerInit(); - } - VarColor(vec4 value, bool optional = false) - { - m_value = Var(value, optional); - } - VarColor(lua_State* l, int& index, bool optional = false) - : VarColor(optional) - { - GetInc(l, index); - } - VarColor(vec4 value, lua_State* l, int& index, bool optional = false) - : VarColor(value, optional) - { - GetInc(l, index); - } - - inline operator vec4() { return m_value; } - inline vec4& operator ()() { return m_value(); } - inline vec4& GetValue() { return m_value.GetValue(); } - inline bool IsValid(lua_State* l, int index) - { - return InnerIsValid(l, index); - } - inline bool IsOptional() - { - return m_value.IsOptional(); - } -private: - void GetInc(lua_State* l, int& index) - { - bool is_nil = lua_isnil(l, index); - if (!m_value.IsOptional() || (!is_nil && InnerIsValid(l, index))) - { - ASSERT(!is_nil); - InnerGet(l, index); - } - } -public: - inline void Get(lua_State* l, int index) - { - int idx = index; - GetInc(l, idx); - } - inline int Return(lua_State* l) - { - return InnerPush(l); - } - inline VarColor& operator-(const vec4& value) { m_value - value; return *this; } - inline VarColor& operator+(const vec4& value) { m_value + value; return *this; } - inline VarColor& operator*(const vec4& value) { m_value * value; return *this; } - inline VarColor& operator/(const vec4& value) { m_value / value; return *this; } - inline VarColor& operator=(const vec4& value) { m_value = value; return *this; } - inline VarColor& operator-=(const vec4& value) { m_value -= value; return *this; } - inline VarColor& operator+=(const vec4& value) { m_value += value; return *this; } - inline VarColor& operator*=(const vec4& value) { m_value *= value; return *this; } - inline VarColor& operator/=(const vec4& value) { m_value /= value; return *this; } - inline VarColor& operator-(const Var& o) { m_value - o; return *this; } - inline VarColor& operator+(const Var& o) { m_value + o; return *this; } - inline VarColor& operator*(const Var& o) { m_value * o; return *this; } - inline VarColor& operator/(const Var& o) { m_value / o; return *this; } - inline VarColor& operator=(const Var& o) { m_value = o; return *this; } - inline VarColor& operator-=(const Var& o) { m_value -= o; return *this; } - inline VarColor& operator+=(const Var& o) { m_value += o; return *this; } - inline VarColor& operator*=(const Var& o) { m_value *= o; return *this; } - inline VarColor& operator/=(const Var& o) { m_value /= o; return *this; } - inline bool operator==(const vec4& value) { return m_value == value; } - inline bool operator!=(const vec4& value) { return m_value != value; } - inline bool operator==(const Var& o) { return m_value == o; } - inline bool operator!=(const Var& o) { return m_value != o; } - inline VarColor& operator-(const VarColor& v) { m_value - v.m_value; return *this; } - inline VarColor& operator+(const VarColor& v) { m_value + v.m_value; return *this; } - inline VarColor& operator*(const VarColor& v) { m_value * v.m_value; return *this; } - inline VarColor& operator/(const VarColor& v) { m_value / v.m_value; return *this; } - inline VarColor& operator=(const VarColor& v) { m_value = v.m_value; return *this; } - inline VarColor& operator-=(const VarColor& v) { m_value -= v.m_value; return *this; } - inline VarColor& operator+=(const VarColor& v) { m_value += v.m_value; return *this; } - inline VarColor& operator*=(const VarColor& v) { m_value *= v.m_value; return *this; } - inline VarColor& operator/=(const VarColor& v) { m_value /= v.m_value; return *this; } - inline bool operator==(const VarColor& v) { return m_value == v.m_value; } - inline bool operator!=(const VarColor& v) { return m_value != v.m_value; } - -protected: - void InnerInit() - { - m_value = vec4::zero; - } - bool InnerIsValid(lua_State* l, int index) - { - Var s; - return m_value.IsValid(l, index) || s.IsValid(l, index); - } - void InnerGet(lua_State* l, int& index) - { - //Try vec4 first - if (m_value.IsValid(l, index)) - { - m_value.Get(l, index); - } - else - { - Var c(l, index); - *this = Color::C8BppHexString(c); - } - } - int InnerPush(lua_State* l) - { - Var c = Color::HexString8Bpp(m_value); - return c.Return(l); - } -}; - -//----------------------------------------------------------------------------- -template -class VarEnum -{ -protected: - SafeEnum m_value; - bool m_optional = false; - -public: - VarEnum(bool optional = false) - { - m_optional = optional; - InnerInit(); - } - VarEnum(SafeEnum value, bool optional = false) - : VarEnum(optional) - { - m_value = value; - } - VarEnum(lua_State* l, int& index, bool optional = false) - : VarEnum(optional) - { - GetInc(l, index); - } - VarEnum(SafeEnum value, lua_State* l, int& index, bool optional = false) - : VarEnum(value, optional) - { - GetInc(l, index); - } - - inline operator SafeEnum() { return m_value; } - inline SafeEnum& operator ()() { return m_value; } - inline SafeEnum& GetValue() { return m_value; } - inline bool IsValid(lua_State* l, int index) - { - return InnerIsValid(l, index); - } - inline bool IsOptional() - { - return m_optional; - } -private: - void GetInc(lua_State* l, int& index) - { - bool is_nil = lua_isnil(l, index); - if (!m_optional || (!is_nil && InnerIsValid(l, index))) - { - ASSERT(!is_nil); - InnerGet(l, index); - } - } -public: - inline void Get(lua_State* l, int index) - { - int idx = index; - GetInc(l, idx); - } - inline int Return(lua_State* l) - { - return InnerPush(l); - } - inline VarEnum& operator-(const SafeEnum& value) { m_value - value; return *this; } - inline VarEnum& operator+(const SafeEnum& value) { m_value + value; return *this; } - inline VarEnum& operator*(const SafeEnum& value) { m_value * value; return *this; } - inline VarEnum& operator/(const SafeEnum& value) { m_value / value; return *this; } - inline VarEnum& operator=(const SafeEnum& value) { m_value = value; return *this; } - inline VarEnum& operator-=(const SafeEnum& value) { m_value -= value; return *this; } - inline VarEnum& operator+=(const SafeEnum& value) { m_value += value; return *this; } - inline VarEnum& operator*=(const SafeEnum& value) { m_value *= value; return *this; } - inline VarEnum& operator/=(const SafeEnum& value) { m_value /= value; return *this; } - inline bool operator==(const SafeEnum& value) { return m_value == value; } - inline bool operator!=(const SafeEnum& value) { return m_value != value; } - inline VarEnum& operator-(const VarEnum& v) { m_value - v.m_value; return *this; } - inline VarEnum& operator+(const VarEnum& v) { m_value + v.m_value; return *this; } - inline VarEnum& operator*(const VarEnum& v) { m_value * v.m_value; return *this; } - inline VarEnum& operator/(const VarEnum& v) { m_value / v.m_value; return *this; } - inline VarEnum& operator=(const VarEnum& v) { m_value = v.m_value; return *this; } - inline VarEnum& operator-=(const VarEnum& v) { m_value -= v.m_value; return *this; } - inline VarEnum& operator+=(const VarEnum& v) { m_value += v.m_value; return *this; } - inline VarEnum& operator*=(const VarEnum& v) { m_value *= v.m_value; return *this; } - inline VarEnum& operator/=(const VarEnum& v) { m_value /= v.m_value; return *this; } - inline bool operator==(const VarEnum& v) { return m_value == v.m_value; } - inline bool operator!=(const VarEnum& v) { return m_value != v.m_value; } - -protected: - void InnerInit() - { - m_value = SafeEnum(0); - } - bool InnerIsValid(lua_State* l, int index) - { - Var s; - return s.IsValid(l, index); - } - void InnerGet(lua_State* l, int& index) - { - Var c(l, index); - *this = FindValue >(c); - } - int InnerPush(lua_State* l) - { - Var s = this->GetValue().ToString(); - return s.Return(l); - } -}; -#endif //CUSTOM_TYPES - -#endif //OLD_VAR_SYSTEM - //----------------------------------------------------------------------------- // Stack: Main class that encapsulates everything ----------------------------- //----------------------------------------------------------------------------- class Stack { -public: - -#if NEW_VAR_SYSTEM - //------------------------------------------------------------------------- +public: static Stack Begin(lua_State* state, int32_t start_index = 1) { return Stack(state, start_index); } + //------------------------------------------------------------------------- + void SetIndex(int32_t index) + { + m_index = index; + } + //------------------------------------------------------------------------- int32_t End() { return m_result; } -#if !OLD_VAR_SYSTEM + //------------------------------------------------------------------------- protected: -#endif //!OLD_VAR_SYSTEM - -#endif //NEW_VAR_SYSTEM - Stack(lua_State* l, int32_t start_index = 1) { m_state = l; m_index = start_index; } + +public: virtual ~Stack() { } +protected: int32_t GetArgs() { return lua_gettop(m_state); } -#if NEW_VAR_SYSTEM - public: //------------------------------------------------------------------------- //The encapsulating struct for pointers @@ -945,6 +317,7 @@ public: } Ptr(const T*& value) { m_value = value; } inline operator T*() { return m_value; } + inline T* operator ->() { return m_value; } inline Ptr& operator=(T const*& value) { m_value = value; return *this; } }; @@ -985,13 +358,6 @@ protected: template T InnerGet(T value) { UNUSED(value); ASSERT(false, INNER_ERROR); return InnerDefault(); } template int InnerPush(T value) { UNUSED(value); ASSERT(false, INNER_ERROR); return 0; } -#ifndef INNER_T_T - //template class C> C InnerDefault() { return C(); } - //template bool InnerIsValid() { return InnerIsValid(); } - //template SafeEnum InnerGet(SafeEnum value) { return FindValue >(InnerGet(value.ToString().C())); } - //template int InnerPush(SafeEnum value) { return InnerPush(value.ToString.C()); } -#endif //STACK_STRING - #ifndef INNER_SAFE_ENUM template SafeEnum InnerDefaultSafeEnum() { return SafeEnum(); } template bool InnerIsValidSafeEnum() { return InnerIsValid(); } @@ -1016,35 +382,7 @@ protected: } #endif //STACK_STRING -#endif //NEW_VAR_SYSTEM - - //------------------------------------------------------------------------- -#if OLD_VAR_SYSTEM -public: - inline operator int32_t() { return m_result; } - //------------------------------------------------------------------------- - - template - Stack& operator>>(T& var) - { - var = T(var.GetValue(), m_state, m_index, var.IsOptional()); - return *this; - } - -#if !NEW_VAR_SYSTEM - //------------------------------------------------------------------------- - template - Stack& operator<<(T& var) - { - m_result += var.Return(m_state); - return *this; - } - -#endif //NEW_VAR_SYSTEM - -#endif //OLD_VAR_SYSTEM - private: lua_State* m_state = nullptr; int32_t m_index = 1; @@ -1052,22 +390,8 @@ private: }; //----------------------------------------------------------------------------- -#if NEW_VAR_SYSTEM - #ifndef REGION_STACK_VAR -//#if OLD_VAR_SYSTEM && NEW_VAR_SYSTEM -// -////------------------------------------------------------------------------- -//template -//Stack& Stack::operator<<(Var& var) -//{ -// m_result += var.Return(m_state); -// return *this; -//} -// -//#endif //OLD_VAR_SYSTEM && NEW_VAR_SYSTEM - #ifndef STACK_BOOL template<> inline bool Stack::InnerIsValid() { return lua_isboolean(m_state, m_index); } template<> inline bool Stack::InnerGet(bool value) { UNUSED(value); return !!lua_toboolean(m_state, m_index++); } @@ -1104,7 +428,6 @@ template<> inline int Stack::InnerPush(float value) { return InnerPush inline bool Stack::InnerIsValid() { return !!lua_isnumber(m_state, m_index); } template<> inline int64_t Stack::InnerGet(int64_t value) { UNUSED(value); return lua_tointeger(m_state, m_index++); } @@ -1153,36 +476,8 @@ template<> inline vec4 Stack::InnerGet(vec4 value) { return vec4(InnerGet< template<> inline int Stack::InnerPush(vec4 value) { return (InnerPush(value.x) + InnerPush(value.y) + InnerPush(value.z) + InnerPush(value.w)); } #endif STACK_VEC4 -//----------------------------------------------------------------------------- -#ifndef STACK_SAFE_ENUM -//template inline SafeEnum Stack::InnerDefault() { return SafeEnum(); } -//template inline bool Stack::InnerIsValid >() { return InnerIsValid(); } -//template inline SafeEnum Stack::InnerGet >(SafeEnum value) { return FindValue >(InnerGet(value.ToString().C())); } -//template inline int Stack::InnerPush >(SafeEnum value) { return InnerPush(value.ToString.C()); } -#endif //STACK_STRING - -//----------------------------------------------------------------------------- -#ifndef STACK_PTR -//template inline Stack::Ptr

Stack::InnerDefault >() { return Stack::Ptr

(nullptr); } -//template inline bool Stack::InnerIsValid >() { return !!lua_isuserdata(m_state, m_index); } -//template inline Stack::Ptr

Stack::InnerGet >(Stack::Ptr

value) -//{ -// P** obj = static_cast(value.m_throw_error -// ? luaL_checkudata(m_state, m_index++, ObjectHelper::GetMethodName

()) -// : luaL_testudata(m_state, m_index++, ObjectHelper::GetMethodName

()) ); -// return Stack::Ptr

(obj ? *obj : value.m_value); -//} -//template inline int Stack::InnerPush >(Stack::Ptr

value) -//{ -// P** data = (P**)lua_newuserdata(m_state, sizeof(P*)); -// *data = value.m_value; -//} -#endif //STACK_STRING - #endif //REGION_STACK_VAR -#endif //NEW_VAR_SYSTEM - //----------------------------------------------------------------------------- class Loader { @@ -1194,7 +489,6 @@ public: bool ExecLuaFile(String const &lua); bool ExecLuaCode(String const &lua); -#if NEW_VAR_SYSTEM //------------------------------------------------------------------------- #define DECLARE_LOADER_GET(T0, T1, GET_NAME) \ template \ @@ -1213,27 +507,6 @@ public: #undef DECLARE_LOADER_GET -#else //OLD_VAR_SYSTEM - - template - T GetVar(String const &name) - { - lua_getglobal(m_lua_state, name.C()); - Var var; var.Get(m_lua_state, -1); - lua_pop(m_lua_state, 1); - return var; - } - template - T* GetPtr(String const &name) - { - lua_getglobal(m_lua_state, name.C()); - VarPtr var; var.Get(m_lua_state, -1); - lua_pop(m_lua_state, 1); - return var(); - } - -#endif //OLD_VAR_SYSTEM - protected: lua_State* GetLuaState(); static void Store(lua_State* l, Loader* loader); @@ -1249,12 +522,11 @@ private: //----------------------------------------------------------------------------- // ObjectHelper member implementations that require VarPtr -#if NEW_VAR_SYSTEM template int ObjectHelper::Store(lua_State * l) { auto stack = LuaStack::Begin(l); - auto obj = stack.Get >(); + TLuaClass* obj = stack.GetPtr(); ASSERT(obj); Loader::StoreObject(l, obj); return 0; @@ -1264,37 +536,12 @@ template int ObjectHelper::Del(lua_State * l) { auto stack = LuaStack::Begin(l); - auto obj = stack.Get >(); + TLuaClass* obj = stack.GetPtr(); ASSERT(obj); delete obj; return 0; } -#else //OLD_VAR_SYSTEM - -template -int ObjectHelper::Store(lua_State * l) -{ - VarPtr obj; - obj.Get(l, 1); - ASSERT(obj()); - Loader::StoreObject(l, obj()); - return 0; -} - -template -int ObjectHelper::Del(lua_State * l) -{ - VarPtr obj; - obj.Get(l, 1); - ASSERT(obj()); - delete obj(); - return 0; -} - -#endif //OLD_VAR_SYSTEM - - } /* namespace Lolua */ //TYPEDEFS @@ -1305,22 +552,5 @@ typedef Lolua::Object::Library LuaObjectLibrary; typedef Lolua::Loader LuaLoader; typedef Lolua::Stack LuaStack; template using LuaPtr = Lolua::Stack::Ptr

; -//template -//typedef Lolua::Stack::Ptr

LuaPtr

; -#if OLD_VAR_SYSTEM -typedef Lolua::Var LuaBool; -typedef Lolua::Var LuaCharPtr; -typedef Lolua::Var LuaString; -typedef Lolua::Var LuaDouble; -typedef Lolua::Var LuaFloat; -typedef Lolua::Var LuaInt64; -typedef Lolua::Var LuaInt32; -typedef Lolua::Var LuaUInt32; -typedef Lolua::Var LuaUInt64; -typedef Lolua::Var LuaVec2; -typedef Lolua::Var LuaVec3; -typedef Lolua::Var LuaVec4; -typedef Lolua::VarColor LuaColor; -#endif //OLD_VAR_SYSTEM } /* namespace lol */