From 96d725fd71d2d0a40b378679a32f61227f5f7cce Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 8 Oct 2016 18:15:46 +0200 Subject: [PATCH] lua: replace lol::LuaState with the original lua_State We have no hope of extending lua_State to add more data to it, because that object may be created by Lua itself, for instance within a coroutine, and it has no knowledge of our version of the object. --- doc/samples/meshviewer/scenesetup.cpp | 20 +-- doc/samples/meshviewer/scenesetup.h | 18 +-- doc/tutorial/14_lol_lua.cpp | 16 +-- src/easymesh/easymeshlua.cpp | 4 +- src/easymesh/easymeshlua.h | 130 +++++++++--------- src/lolua/baselua.cpp | 16 +-- src/lolua/baselua.h | 182 +++++++++++++------------- 7 files changed, 192 insertions(+), 194 deletions(-) diff --git a/doc/samples/meshviewer/scenesetup.cpp b/doc/samples/meshviewer/scenesetup.cpp index 7c90fd3e..46806349 100644 --- a/doc/samples/meshviewer/scenesetup.cpp +++ b/doc/samples/meshviewer/scenesetup.cpp @@ -157,7 +157,7 @@ SceneSetupLuaObject::~SceneSetupLuaObject() } //----------------------------------------------------------------------------- -SceneSetupLuaObject* SceneSetupLuaObject::New(LuaState* l, int arg_nb) +SceneSetupLuaObject* SceneSetupLuaObject::New(lua_State* l, int arg_nb) { UNUSED(l); UNUSED(arg_nb); @@ -168,7 +168,7 @@ SceneSetupLuaObject* SceneSetupLuaObject::New(LuaState* l, int arg_nb) } //-- Setup command ------------------------------------------------------------ -int SceneSetupLuaObject::AddLight(LuaState* l) +int SceneSetupLuaObject::AddLight(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -177,7 +177,7 @@ int SceneSetupLuaObject::AddLight(LuaState* l) o->m_setup->AddLight(FindValue(t().C())); return 0; } -int SceneSetupLuaObject::SetupScene(LuaState* l) +int SceneSetupLuaObject::SetupScene(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -186,7 +186,7 @@ int SceneSetupLuaObject::SetupScene(LuaState* l) return 0; } //-- main funcs --------------------------------------------------------------- -int SceneSetupLuaObject::SetPosition(LuaState* l) +int SceneSetupLuaObject::SetPosition(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -195,7 +195,7 @@ int SceneSetupLuaObject::SetPosition(LuaState* l) o->m_setup->SetPosition(c); return 0; } -int SceneSetupLuaObject::SetLookAt(LuaState* l) +int SceneSetupLuaObject::SetLookAt(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -204,7 +204,7 @@ int SceneSetupLuaObject::SetLookAt(LuaState* l) o->m_setup->SetLookAt(c); return 0; } -int SceneSetupLuaObject::SetColor(LuaState* l) +int SceneSetupLuaObject::SetColor(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -213,7 +213,7 @@ int SceneSetupLuaObject::SetColor(LuaState* l) o->m_setup->SetColor(c); return 0; } -int SceneSetupLuaObject::Show(LuaState* l) +int SceneSetupLuaObject::Show(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -222,7 +222,7 @@ int SceneSetupLuaObject::Show(LuaState* l) o->m_setup->Show(e); return 0; } -int SceneSetupLuaObject::Hide(LuaState* l) +int SceneSetupLuaObject::Hide(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -231,7 +231,7 @@ int SceneSetupLuaObject::Hide(LuaState* l) o->m_setup->Hide(e); return 0; } -int SceneSetupLuaObject::Toggle(LuaState* l) +int SceneSetupLuaObject::Toggle(lua_State* l) { LuaStack s(l); LuaSSetupPtr o; @@ -271,7 +271,7 @@ const LuaObjectLib* SceneSetupLuaObject::GetLib() map SceneSetupLuaLoader::m_setups; SceneSetupLuaLoader::SceneSetupLuaLoader() : LuaLoader() { - LuaState* l = GetLuaState(); + lua_State* l = GetLuaState(); LuaObjectDef::Register(l); } diff --git a/doc/samples/meshviewer/scenesetup.h b/doc/samples/meshviewer/scenesetup.h index 5a80c397..9b6ffc29 100644 --- a/doc/samples/meshviewer/scenesetup.h +++ b/doc/samples/meshviewer/scenesetup.h @@ -115,21 +115,21 @@ public: virtual ~SceneSetupLuaObject(); //------------------------------------------------------------------------- - static SceneSetupLuaObject* New(LuaState* l, int arg_nb); + static SceneSetupLuaObject* New(lua_State* l, int arg_nb); static const LuaObjectLib* GetLib(); //------------------------------------------------------------------------- public: //-- Setup command - static int AddLight(LuaState* l); - static int SetupScene(LuaState* l); + static int AddLight(lua_State* l); + static int SetupScene(lua_State* l); //-- main funcs - static int SetPosition(LuaState* l); - static int SetLookAt(LuaState* l); - static int SetColor(LuaState* l); - static int Show(LuaState* l); - static int Hide(LuaState* l); - static int Toggle(LuaState* l); + static int SetPosition(lua_State* l); + static int SetLookAt(lua_State* l); + static int SetColor(lua_State* l); + static int Show(lua_State* l); + static int Hide(lua_State* l); + static int Toggle(lua_State* l); //-- Setup command void AddLight(LightType type); diff --git a/doc/tutorial/14_lol_lua.cpp b/doc/tutorial/14_lol_lua.cpp index b9034cf7..653354c6 100644 --- a/doc/tutorial/14_lol_lua.cpp +++ b/doc/tutorial/14_lol_lua.cpp @@ -27,7 +27,7 @@ class DemoObject : public LuaObject public: DemoObject() : LuaObject() {} virtual ~DemoObject() {} - static DemoObject* New(LuaState* l, int arg_nb) + static DemoObject* New(lua_State* l, int arg_nb) { UNUSED(l); UNUSED(arg_nb); @@ -35,13 +35,13 @@ public: } //------------------------------------------------------------------------- - static int AddFive(LuaState* l) + static int AddFive(lua_State* l) { LuaInt32 i; i.Get(l, 1); i += 5; return i.Return(l); } - static int AddTenInstance(LuaState* l) + static int AddTenInstance(lua_State* l) { LuaStack stack(l); LuaDemoObjectPtr obj; @@ -55,7 +55,7 @@ public: return (f + 10); } - static int GetX(LuaState* l) + static int GetX(lua_State* l) { LuaStack stack(l); LuaDemoObjectPtr obj; @@ -64,7 +64,7 @@ public: i = obj->m_x; return stack << i; } - static int SetX(LuaState* l) + static int SetX(lua_State* l) { LuaStack stack(l); LuaDemoObjectPtr obj; @@ -89,7 +89,7 @@ public: }; //----------------------------------------------------------------------------- -static int GlobalAddString(LuaState* l) +static int GlobalAddString(lua_State* l) { LuaString s; s.Get(l, 1); s() += "_added"; @@ -102,7 +102,7 @@ class LoluaDemoLoader : public LuaLoader public: LoluaDemoLoader() : LuaLoader() { - LuaState* l = GetLuaState(); + lua_State* l = GetLuaState(); //Registering demo object LuaObjectDef::Register(l); @@ -116,7 +116,7 @@ public: } void TestStuff() { - LuaState* l = GetLuaState(); + lua_State* l = GetLuaState(); /* //create property diff --git a/src/easymesh/easymeshlua.cpp b/src/easymesh/easymeshlua.cpp index ebe7180e..258b3182 100644 --- a/src/easymesh/easymeshlua.cpp +++ b/src/easymesh/easymeshlua.cpp @@ -24,7 +24,7 @@ using namespace lol; //----------------------------------------------------------------------------- EasyMeshLuaLoader::EasyMeshLuaLoader() : LuaLoader() { - LuaState* l = GetLuaState(); + lua_State* l = GetLuaState(); //Registering demo object LuaObjectDef::Register(l); @@ -77,7 +77,7 @@ EasyMeshLuaObject::~EasyMeshLuaObject() } //----------------------------------------------------------------------------- -EasyMeshLuaObject* EasyMeshLuaObject::New(LuaState* l, int arg_nb) +EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State* l, int arg_nb) { UNUSED(l); UNUSED(arg_nb); diff --git a/src/easymesh/easymeshlua.h b/src/easymesh/easymeshlua.h index 2903e23c..3632e2d4 100644 --- a/src/easymesh/easymeshlua.h +++ b/src/easymesh/easymeshlua.h @@ -27,11 +27,11 @@ public: EasyMesh& GetMesh() { return m_instance; } //------------------------------------------------------------------------- - static EasyMeshLuaObject* New(LuaState* l, int arg_nb); + static EasyMeshLuaObject* New(lua_State* l, int arg_nb); static const LuaObjectLib* GetLib(); //------------------------------------------------------------------------- - static int AppendCylinder(LuaState* l) + static int AppendCylinder(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -42,7 +42,7 @@ public: m->m_instance.AppendCylinder(nsides, h, d1, d2, dualside, smooth, close); return 0; } - static int AppendSphere(LuaState* l) + static int AppendSphere(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -52,7 +52,7 @@ public: m->m_instance.AppendSphere(ndivisions, d); return 0; } - static int AppendCapsule(LuaState* l) + static int AppendCapsule(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -62,7 +62,7 @@ public: m->m_instance.AppendCapsule(ndivisions, h, d); return 0; } - static int AppendTorus(LuaState* l) + static int AppendTorus(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -72,7 +72,7 @@ public: m->m_instance.AppendTorus(ndivisions, d1, d2); return 0; } - static int AppendBox(LuaState* l) + static int AppendBox(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -83,7 +83,7 @@ public: m->m_instance.AppendBox(size, chamf, smooth); return 0; } - static int AppendStar(LuaState* l) + static int AppendStar(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -94,7 +94,7 @@ public: m->m_instance.AppendStar(nbranches, d1, d2, fade, fade2); return 0; } - static int AppendExpandedStar(LuaState* l) + static int AppendExpandedStar(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -104,7 +104,7 @@ public: m->m_instance.AppendExpandedStar(nbranches, d1, d2, extrad); return 0; } - static int AppendDisc(LuaState* l) + static int AppendDisc(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -115,7 +115,7 @@ public: m->m_instance.AppendDisc(nsides, d, fade); return 0; } - static int AppendSimpleTriangle(LuaState* l) + static int AppendSimpleTriangle(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -125,7 +125,7 @@ public: m->m_instance.AppendSimpleTriangle(d, fade); return 0; } - static int AppendSimpleQuad(LuaState* l) + static int AppendSimpleQuad(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -135,7 +135,7 @@ public: m->m_instance.AppendSimpleQuad(size, fade); return 0; } - static int AppendCog(LuaState* l) + static int AppendCog(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -148,7 +148,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int TranslateX(LuaState* l) + static int TranslateX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -157,7 +157,7 @@ public: m->m_instance.TranslateX(f); return 0; } - static int TranslateY(LuaState* l) + static int TranslateY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -166,7 +166,7 @@ public: m->m_instance.TranslateY(f); return 0; } - static int TranslateZ(LuaState* l) + static int TranslateZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -175,7 +175,7 @@ public: m->m_instance.TranslateZ(f); return 0; } - static int Translate(LuaState* l) + static int Translate(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -185,7 +185,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int RotateX(LuaState* l) + static int RotateX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -194,7 +194,7 @@ public: m->m_instance.RotateX(a); return 0; } - static int RotateY(LuaState* l) + static int RotateY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -203,7 +203,7 @@ public: m->m_instance.RotateY(a); return 0; } - static int RotateZ(LuaState* l) + static int RotateZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -212,7 +212,7 @@ public: m->m_instance.RotateZ(a); return 0; } - static int Rotate(LuaState* l) + static int Rotate(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -223,7 +223,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int ScaleX(LuaState* l) + static int ScaleX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -232,7 +232,7 @@ public: m->m_instance.ScaleX(x); return 0; } - static int ScaleY(LuaState* l) + static int ScaleY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -241,7 +241,7 @@ public: m->m_instance.ScaleY(y); return 0; } - static int ScaleZ(LuaState* l) + static int ScaleZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -250,7 +250,7 @@ public: m->m_instance.ScaleZ(z); return 0; } - static int Scale(LuaState* l) + static int Scale(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -260,7 +260,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int RadialJitter(LuaState* l) + static int RadialJitter(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -270,7 +270,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int TaperX(LuaState* l) + static int TaperX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -280,7 +280,7 @@ public: m->m_instance.TaperX(y, z, xoff, abs); return 0; } - static int TaperY(LuaState* l) + static int TaperY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -290,7 +290,7 @@ public: m->m_instance.TaperY(x, z, yoff, abs); return 0; } - static int TaperZ(LuaState* l) + static int TaperZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -301,7 +301,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int TwistX(LuaState* l) + static int TwistX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -310,7 +310,7 @@ public: m->m_instance.TwistX(t, toff); return 0; } - static int TwistY(LuaState* l) + static int TwistY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -319,7 +319,7 @@ public: m->m_instance.TwistY(t, toff); return 0; } - static int TwistZ(LuaState* l) + static int TwistZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -329,7 +329,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int ShearX(LuaState* l) + static int ShearX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -339,7 +339,7 @@ public: m->m_instance.ShearX(y, z, xoff, abs); return 0; } - static int ShearY(LuaState* l) + static int ShearY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -349,7 +349,7 @@ public: m->m_instance.ShearY(x, z, yoff, abs); return 0; } - static int ShearZ(LuaState* l) + static int ShearZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -360,7 +360,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int StretchX(LuaState* l) + static int StretchX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -369,7 +369,7 @@ public: m->m_instance.StretchX(y, z, xoff); return 0; } - static int StretchY(LuaState* l) + static int StretchY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -378,7 +378,7 @@ public: m->m_instance.StretchY(x, z, yoff); return 0; } - static int StretchZ(LuaState* l) + static int StretchZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -388,7 +388,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int BendXY(LuaState* l) + static int BendXY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -397,7 +397,7 @@ public: m->m_instance.BendXY(t, toff); return 0; } - static int BendXZ(LuaState* l) + static int BendXZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -406,7 +406,7 @@ public: m->m_instance.BendXZ(t, toff); return 0; } - static int BendYX(LuaState* l) + static int BendYX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -415,7 +415,7 @@ public: m->m_instance.BendYX(t, toff); return 0; } - static int BendYZ(LuaState* l) + static int BendYZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -424,7 +424,7 @@ public: m->m_instance.BendYZ(t, toff); return 0; } - static int BendZX(LuaState* l) + static int BendZX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -433,7 +433,7 @@ public: m->m_instance.BendZX(t, toff); return 0; } - static int BendZY(LuaState* l) + static int BendZY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -443,7 +443,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int MirrorX(LuaState* l) + static int MirrorX(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -451,7 +451,7 @@ public: m->m_instance.MirrorX(); return 0; } - static int MirrorY(LuaState* l) + static int MirrorY(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -459,7 +459,7 @@ public: m->m_instance.MirrorY(); return 0; } - static int MirrorZ(LuaState* l) + static int MirrorZ(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -468,7 +468,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int LoopStart(LuaState* l) + static int LoopStart(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -477,7 +477,7 @@ public: m->m_instance.LoopStart(loopnb); return 0; } - static int LoopEnd(LuaState* l) + static int LoopEnd(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -485,7 +485,7 @@ public: m->m_instance.LoopEnd(); return 0; } - static int OpenBrace(LuaState* l) + static int OpenBrace(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -493,7 +493,7 @@ public: m->m_instance.OpenBrace(); return 0; } - static int CloseBrace(LuaState* l) + static int CloseBrace(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -502,7 +502,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int ToggleScaleWinding(LuaState* l) + static int ToggleScaleWinding(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -510,7 +510,7 @@ public: m->m_instance.ToggleScaleWinding(); return 0; } - static int ToggleQuadWeighting(LuaState* l) + static int ToggleQuadWeighting(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -518,7 +518,7 @@ public: m->m_instance.ToggleQuadWeighting(); return 0; } - static int TogglePostBuildNormal(LuaState* l) + static int TogglePostBuildNormal(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -526,7 +526,7 @@ public: m->m_instance.TogglePostBuildNormal(); return 0; } - static int ToggleVerticeNoCleanup(LuaState* l) + static int ToggleVerticeNoCleanup(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -535,7 +535,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int VerticesMerge(LuaState* l) + static int VerticesMerge(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -543,7 +543,7 @@ public: m->m_instance.VerticesMerge(); return 0; } - static int VerticesSeparate(LuaState* l) + static int VerticesSeparate(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -551,7 +551,7 @@ public: m->m_instance.VerticesSeparate(); return 0; } - static int VerticesCleanup(LuaState* l) + static int VerticesCleanup(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -560,7 +560,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int Duplicate(LuaState* l) + static int Duplicate(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -569,7 +569,7 @@ public: m->m_instance.DupAndScale(ds, true); return 0; } - static int Smooth(LuaState* l) + static int Smooth(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -578,7 +578,7 @@ public: m->m_instance.SmoothMesh(pass, split_per_pass, smooth_per_pass); return 0; } - static int SplitTriangles(LuaState* l) + static int SplitTriangles(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -587,7 +587,7 @@ public: m->m_instance.SplitTriangles(pass); return 0; } - static int Chamfer(LuaState* l) + static int Chamfer(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -597,7 +597,7 @@ public: return 0; } //------------------------------------------------------------------------- - static int SetCurColor(LuaState* l) + static int SetCurColor(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -606,7 +606,7 @@ public: m->m_instance.SetCurColor(c); return 0; } - static int SetCurColorA(LuaState* l) + static int SetCurColorA(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -615,7 +615,7 @@ public: m->m_instance.SetCurColorA(c); return 0; } - static int SetCurColorB(LuaState* l) + static int SetCurColorB(lua_State* l) { LuaStack s(l); EzMeshPtr m; @@ -623,7 +623,7 @@ public: m->m_instance.SetCurColorB(c); return 0; } - static int SetVertColor(LuaState* l) + static int SetVertColor(lua_State* l) { LuaStack s(l); EzMeshPtr m; diff --git a/src/lolua/baselua.cpp b/src/lolua/baselua.cpp index e61679bc..8a1c035d 100644 --- a/src/lolua/baselua.cpp +++ b/src/lolua/baselua.cpp @@ -26,7 +26,7 @@ class LuaBaseData friend class Lolua::Loader; //PANIC PANIC ------------------------------------------------------------- - static int LuaPanic(LuaState* l) + static int LuaPanic(lua_State* l) { char const *message = lua_tostring(l, -1); msg::error("%s\n", message); @@ -35,7 +35,7 @@ class LuaBaseData } //Exec lua code ----------------------------------------------------------- - static int LuaDoCode(LuaState *l, String const& s) + static int LuaDoCode(lua_State *l, String const& s) { int status = luaL_dostring(l, s.C()); if (status == 1) @@ -48,7 +48,7 @@ class LuaBaseData } //Open a file and exec lua code ------------------------------------------- - static int LuaDoFile(LuaState *l) + static int LuaDoFile(lua_State *l) { if (lua_isnoneornil(l, 1)) return LUA_ERRFILE; @@ -114,14 +114,14 @@ Loader::~Loader() } //Store loader ------------------------------------------------------------ -static array g_loaders; +static array g_loaders; -void Loader::Store(LuaState* l, Lolua::Loader* loader) +void Loader::Store(lua_State* l, Lolua::Loader* loader) { g_loaders.push(l, loader); } -void Loader::Release(LuaState* l, Lolua::Loader* loader) +void Loader::Release(lua_State* l, Lolua::Loader* loader) { for (int i = 0; i < g_loaders.count(); ++i) { @@ -134,7 +134,7 @@ void Loader::Release(LuaState* l, Lolua::Loader* loader) } //Store lua object -------------------------------------------------------- -void Loader::StoreObject(LuaState* l, Object* obj) +void Loader::StoreObject(lua_State* l, Object* obj) { for (auto loader : g_loaders) { @@ -161,7 +161,7 @@ bool Loader::ExecLuaCode(String const &lua) } //----------------------------------------------------------------------------- -LuaState* Loader::GetLuaState() +lua_State* Loader::GetLuaState() { return m_lua_state; } diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index 2774423d..54cc511b 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -19,8 +19,6 @@ namespace lol { -typedef lua_State LuaState; - //----------------------------------------------------------------------------- namespace Lolua { @@ -101,7 +99,7 @@ class Object public: Object() { } virtual ~Object() { } - static Object* New(LuaState* l, int arg_nb) + static Object* New(lua_State* l, int arg_nb) { UNUSED(l); UNUSED(arg_nb); @@ -123,7 +121,7 @@ public: //------------------------------------------------------------------------- template - static void Register(LuaState *l) + static void Register(lua_State *l) { //Default statics static const luaL_Reg default_statics[] @@ -210,7 +208,7 @@ public: protected: //------------------------------------------------------------------------- template - static int New(LuaState* l) + static int New(lua_State* l) { //Number of arguments int n_args = lua_gettop(l); @@ -228,15 +226,15 @@ protected: } //------------------------------------------------------------------------- - template static int Store(LuaState * l); - template static int Del(LuaState * l); + template static int Store(lua_State * l); + template static int Del(lua_State * l); }; //----------------------------------------------------------------------------- class Function { public: - Function(LuaState* l, const char* name, int(*function)(LuaState*)) + Function(lua_State* l, const char* name, int(*function)(lua_State*)) { lua_pushcfunction(l, function); lua_setglobal(l, name); @@ -261,12 +259,12 @@ public: { m_value = value; } - VarPtr(LuaState* l, int& index, bool optional = false) + VarPtr(lua_State* l, int& index, bool optional = false) : VarPtr(optional) { GetInc(l, index); } - VarPtr(T* value, LuaState* l, int& index, bool optional = false) + VarPtr(T* value, lua_State* l, int& index, bool optional = false) : VarPtr(value, optional) { GetInc(l, index); @@ -276,7 +274,7 @@ public: inline T* operator ->() { return m_value; } inline T* operator=(T* value) { m_value = value; } inline T* GetValue() { return m_value; } - inline bool IsValid(LuaState* l, int index) + inline bool IsValid(lua_State* l, int index) { return InnerIsValid(l, index); } @@ -285,7 +283,7 @@ public: return m_optional; } private: - inline void GetInc(LuaState* l, int& index) + inline void GetInc(lua_State* l, int& index) { bool is_nil = lua_isnil(l, index); if (!m_optional || (!is_nil && InnerIsValid(l, index))) @@ -295,28 +293,28 @@ private: } } public: - inline void Get(LuaState* l, int index) + inline void Get(lua_State* l, int index) { int idx = index; GetInc(l, idx); } - inline int Return(LuaState* l) + inline int Return(lua_State* l) { InnerPush(l); return 1; } protected: - virtual bool InnerIsValid(LuaState* l, int index) + virtual bool InnerIsValid(lua_State* l, int index) { return !!lua_isuserdata(l, index); } - virtual void InnerGet(LuaState* l, int& index) + virtual void InnerGet(lua_State* l, int& index) { T** obj = static_cast(luaL_checkudata(l, index++, ObjectDef::GetMethodName())); m_value = obj ? *obj : nullptr; } - void InnerPush(LuaState* l) + void InnerPush(lua_State* l) { T** data = (T**)lua_newuserdata(l, sizeof(T*)); *data = m_value; @@ -331,10 +329,10 @@ class VarPtrLight public: VarPtrLight(bool optional = false) : VarPtr(optional) { } VarPtrLight(T* value, bool optional = false) : VarPtr(value, optional) { } - VarPtrLight(LuaState* l, int& index, bool optional = false) : VarPtr(l, index, optional) { } - VarPtrLight(T* value, LuaState* l, int& index, bool optional = false) : VarPtr(value, l, index, 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(LuaState* l, int& index) + virtual void InnerGet(lua_State* l, int& index) { T** obj = static_cast(luaL_testudata(l, index++, ObjectDef::GetMethodName())); m_value = obj ? *obj : nullptr; @@ -360,12 +358,12 @@ public: m_optional = optional; m_value = value; } - Var(LuaState* l, int& index, bool optional = false) + Var(lua_State* l, int& index, bool optional = false) { m_optional = optional; GetInc(l, index); } - Var(T value, LuaState* l, int& index, bool optional = false) + Var(T value, lua_State* l, int& index, bool optional = false) { m_optional = optional; m_value = value; @@ -374,7 +372,7 @@ public: inline operator T() { return m_value; } inline T& operator ()() { return m_value; } inline T& GetValue() { return m_value; } - inline bool IsValid(LuaState* l, int index) + inline bool IsValid(lua_State* l, int index) { return InnerIsValid(l, index); } @@ -383,7 +381,7 @@ public: return m_optional; } private: - void GetInc(LuaState* l, int& index) + void GetInc(lua_State* l, int& index) { bool is_nil = lua_isnil(l, index); if (!m_optional || (!is_nil && InnerIsValid(l, index))) @@ -393,12 +391,12 @@ private: } } public: - inline void Get(LuaState* l, int index) + inline void Get(lua_State* l, int index) { int idx = index; GetInc(l, idx); } - inline int Return(LuaState* l) + inline int Return(lua_State* l) { return InnerPush(l); } @@ -427,35 +425,35 @@ public: protected: void InnerInit() { m_value = T(0); } - bool InnerIsValid(LuaState* l, int index) { UNUSED(l); UNUSED(index); ASSERT(false); return false; } - void InnerGet(LuaState* l, int& index) { UNUSED(l); UNUSED(index); ASSERT(false); } - int InnerPush(LuaState* l) { UNUSED(l); ASSERT(false); return 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; } }; //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { return lua_isboolean(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& index) +template<> inline void Var::InnerGet(lua_State* l, int& index) { m_value = !!lua_toboolean(l, index++); } -template<> inline int Var::InnerPush(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { lua_pushboolean(l, m_value); return 1; } //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { return !!lua_isstring(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& index) +template<> inline void Var::InnerGet(lua_State* l, int& index) { m_value = lua_tostring(l, index++); } -template<> inline int Var::InnerPush(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { lua_pushstring(l, m_value); return 1; @@ -465,48 +463,48 @@ template<> inline void Var::InnerInit() { m_value = String(); } -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { Var v; return v.IsValid(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& index) +template<> inline void Var::InnerGet(lua_State* l, int& index) { Var v(l, index); m_value = v(); } -template<> inline int Var::InnerPush(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { Var v; v = m_value.C(); return v.Return(l); } //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { return !!lua_isnumber(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& index) +template<> inline void Var::InnerGet(lua_State* l, int& index) { m_value = lua_tonumber(l, index++); } -template<> inline int Var::InnerPush(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { lua_pushnumber(l, m_value); return 1; } //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { Var v; return v.IsValid(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& index) +template<> inline void Var::InnerGet(lua_State* l, int& index) { Var v(l, index); m_value = (float)v(); } -template<> inline int Var::InnerPush(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { Var v = (double)m_value; return v.Return(l); @@ -514,15 +512,15 @@ template<> inline int Var::InnerPush(LuaState* l) #if 0 //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { return !!lua_isnumber(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& index) +template<> inline void Var::InnerGet(lua_State* l, int& index) { m_value = lua_tointeger(l, index++); } -template<> inline int Var::InnerPush(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { lua_pushinteger(l, m_value); return 1; @@ -530,32 +528,32 @@ template<> inline int Var::InnerPush(LuaState* l) #endif //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { Var v; return v.IsValid(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& 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(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { Var v = (int64_t)m_value; return v.Return(l); } //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { return !!lua_isnumber(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& 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(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { lua_pushinteger(l, (lua_Integer)m_value); return 1; @@ -563,17 +561,17 @@ template<> inline int Var::InnerPush(LuaState* l) #if 0 //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { Var v; return v.IsValid(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& 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(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { Var v = (uint32_t)m_value; return v.Return(l); @@ -581,37 +579,37 @@ template<> inline int Var::InnerPush(LuaState* l) #endif //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { Var x; return x.IsValid(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& 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(LuaState* l) +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(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { Var x; return x.IsValid(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& 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(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { Var x = m_value.x; Var y = m_value.y; @@ -619,12 +617,12 @@ template<> inline int Var::InnerPush(LuaState* l) return (x.Return(l) + y.Return(l) + z.Return(l)); } //----------------------------------------------------------------------------- -template<> inline bool Var::InnerIsValid(LuaState* l, int index) +template<> inline bool Var::InnerIsValid(lua_State* l, int index) { Var x; return x.IsValid(l, index); } -template<> inline void Var::InnerGet(LuaState* l, int& index) +template<> inline void Var::InnerGet(lua_State* l, int& index) { Var x(l, index); Var y(x(), l, index, true); @@ -632,7 +630,7 @@ template<> inline void Var::InnerGet(LuaState* l, int& index) Var w(x(), l, index, true); m_value = vec4(x, y, z, w); } -template<> inline int Var::InnerPush(LuaState* l) +template<> inline int Var::InnerPush(lua_State* l) { Var x = m_value.x; Var y = m_value.y; @@ -657,12 +655,12 @@ public: { m_value = Var(value, optional); } - VarColor(LuaState* l, int& index, bool optional = false) + VarColor(lua_State* l, int& index, bool optional = false) : VarColor(optional) { GetInc(l, index); } - VarColor(vec4 value, LuaState* l, int& index, bool optional = false) + VarColor(vec4 value, lua_State* l, int& index, bool optional = false) : VarColor(value, optional) { GetInc(l, index); @@ -671,7 +669,7 @@ public: inline operator vec4() { return m_value; } inline vec4& operator ()() { return m_value(); } inline vec4& GetValue() { return m_value.GetValue(); } - inline bool IsValid(LuaState* l, int index) + inline bool IsValid(lua_State* l, int index) { return InnerIsValid(l, index); } @@ -680,7 +678,7 @@ public: return m_value.IsOptional(); } private: - void GetInc(LuaState* l, int& index) + void GetInc(lua_State* l, int& index) { bool is_nil = lua_isnil(l, index); if (!m_value.IsOptional() || (!is_nil && InnerIsValid(l, index))) @@ -690,12 +688,12 @@ private: } } public: - inline void Get(LuaState* l, int index) + inline void Get(lua_State* l, int index) { int idx = index; GetInc(l, idx); } - inline int Return(LuaState* l) + inline int Return(lua_State* l) { return InnerPush(l); } @@ -738,12 +736,12 @@ protected: { m_value = vec4::zero; } - bool InnerIsValid(LuaState* l, int index) + bool InnerIsValid(lua_State* l, int index) { Var s; return m_value.IsValid(l, index) || s.IsValid(l, index); } - void InnerGet(LuaState* l, int& index) + void InnerGet(lua_State* l, int& index) { //Try vec4 first if (m_value.IsValid(l, index)) @@ -756,7 +754,7 @@ protected: *this = Color::C8BppHexString(c); } } - int InnerPush(LuaState* l) + int InnerPush(lua_State* l) { Var c = Color::HexString8Bpp(m_value); return c.Return(l); @@ -782,12 +780,12 @@ public: { m_value = value; } - VarEnum(LuaState* l, int& index, bool optional = false) + VarEnum(lua_State* l, int& index, bool optional = false) : VarEnum(optional) { GetInc(l, index); } - VarEnum(SafeEnum value, LuaState* l, int& index, bool optional = false) + VarEnum(SafeEnum value, lua_State* l, int& index, bool optional = false) : VarEnum(value, optional) { GetInc(l, index); @@ -796,7 +794,7 @@ public: inline operator SafeEnum() { return m_value; } inline SafeEnum& operator ()() { return m_value; } inline SafeEnum& GetValue() { return m_value; } - inline bool IsValid(LuaState* l, int index) + inline bool IsValid(lua_State* l, int index) { return InnerIsValid(l, index); } @@ -805,7 +803,7 @@ public: return m_optional; } private: - void GetInc(LuaState* l, int& index) + void GetInc(lua_State* l, int& index) { bool is_nil = lua_isnil(l, index); if (!m_optional || (!is_nil && InnerIsValid(l, index))) @@ -815,12 +813,12 @@ private: } } public: - inline void Get(LuaState* l, int index) + inline void Get(lua_State* l, int index) { int idx = index; GetInc(l, idx); } - inline int Return(LuaState* l) + inline int Return(lua_State* l) { return InnerPush(l); } @@ -852,17 +850,17 @@ protected: { m_value = SafeEnum(0); } - bool InnerIsValid(LuaState* l, int index) + bool InnerIsValid(lua_State* l, int index) { Var s; return s.IsValid(l, index); } - void InnerGet(LuaState* l, int& index) + void InnerGet(lua_State* l, int& index) { Var c(l, index); *this = FindValue >(c); } - int InnerPush(LuaState* l) + int InnerPush(lua_State* l) { Var s = this->GetValue().ToString(); return s.Return(l); @@ -873,7 +871,7 @@ protected: class Stack { public: - Stack(LuaState* l, int32_t start_index = 1) + Stack(lua_State* l, int32_t start_index = 1) { m_state = l; m_index = start_index; @@ -959,7 +957,7 @@ public: */ private: - LuaState* m_state = nullptr; + lua_State* m_state = nullptr; int32_t m_index = 1; int32_t m_result = 0; }; @@ -993,22 +991,22 @@ public: } protected: - LuaState* GetLuaState(); - static void Store(LuaState* l, Loader* loader); - static void Release(LuaState* l, Loader* loader); - static void StoreObject(LuaState* l, Object* obj); + lua_State* GetLuaState(); + static void Store(lua_State* l, Loader* loader); + static void Release(lua_State* l, Loader* loader); + static void StoreObject(lua_State* l, Object* obj); //Virtual Store lua object ------------------------------------------------ virtual void Store(Object* obj) { UNUSED(obj); } private: - LuaState* m_lua_state; + lua_State* m_lua_state; }; //----------------------------------------------------------------------------- // ObjectDef member implementations that require VarPtr template -int ObjectDef::Store(LuaState * l) +int ObjectDef::Store(lua_State * l) { VarPtr obj; obj.Get(l, 1); @@ -1018,7 +1016,7 @@ int ObjectDef::Store(LuaState * l) } template -int ObjectDef::Del(LuaState * l) +int ObjectDef::Del(lua_State * l) { VarPtr obj; obj.Get(l, 1);