From 893ab7b6f505ed109c68cdc8cb3744b1845ca09b Mon Sep 17 00:00:00 2001 From: touky Date: Sun, 23 Oct 2016 18:54:46 -0400 Subject: [PATCH 1/5] first little pass, everything is broken. Will resume on other computer. --- .vscode/c_cpp_properties.json | 28 +++++++++++++ build/Lol (vs2015).sln | 15 +++++++ doc/tutorial/14_lol_lua.cpp | 22 ++++++---- doc/tutorial/imgui.ini | 4 +- src/lolua/baselua.h | 75 +++++++++-------------------------- 5 files changed, 78 insertions(+), 66 deletions(-) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..972446b0 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,28 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": ["/usr/include"], + "browse" : { + "limitSymbolsToIncludedHeaders" : true, + "databaseFilename" : "" + } + }, + { + "name": "Linux", + "includePath": ["/usr/include"], + "browse" : { + "limitSymbolsToIncludedHeaders" : true, + "databaseFilename" : "" + } + }, + { + "name": "Win32", + "includePath": ["c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include", "src"], + "browse" : { + "limitSymbolsToIncludedHeaders" : true, + "databaseFilename" : "" + } + } + ] +} diff --git a/build/Lol (vs2015).sln b/build/Lol (vs2015).sln index 22c0ffe0..d24d0a1d 100644 --- a/build/Lol (vs2015).sln +++ b/build/Lol (vs2015).sln @@ -66,6 +66,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{B629 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "15_lolimgui", "..\doc\tutorial\15_lolimgui.vcxproj", "{81C83B42-D00A-4FA3-9A3D-80F9D46524BF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "14_lol_lua", "..\doc\tutorial\14_lol_lua.vcxproj", "{31B96262-1C41-43B9-BA38-27AA385B05DB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ORBIS = Debug|ORBIS @@ -308,6 +310,18 @@ Global {81C83B42-D00A-4FA3-9A3D-80F9D46524BF}.Release|Win32.Build.0 = Release|Win32 {81C83B42-D00A-4FA3-9A3D-80F9D46524BF}.Release|x64.ActiveCfg = Release|x64 {81C83B42-D00A-4FA3-9A3D-80F9D46524BF}.Release|x64.Build.0 = Release|x64 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Debug|ORBIS.ActiveCfg = Debug|ORBIS + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Debug|ORBIS.Build.0 = Debug|ORBIS + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Debug|Win32.ActiveCfg = Debug|Win32 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Debug|Win32.Build.0 = Debug|Win32 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Debug|x64.ActiveCfg = Debug|x64 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Debug|x64.Build.0 = Debug|x64 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Release|ORBIS.ActiveCfg = Release|ORBIS + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Release|ORBIS.Build.0 = Release|ORBIS + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Release|Win32.ActiveCfg = Release|Win32 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Release|Win32.Build.0 = Release|Win32 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Release|x64.ActiveCfg = Release|x64 + {31B96262-1C41-43B9-BA38-27AA385B05DB}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -341,5 +355,6 @@ Global {73F1A804-1116-46C3-922A-9C0ADEB33F52} = {4C4BD478-3767-4C27-BD91-DAAFE7CD03A2} {B6297FF2-63D0-41EE-BE13-EFF720C9B0FA} = {1AFD580B-98B8-4689-B661-38C41132C60E} {81C83B42-D00A-4FA3-9A3D-80F9D46524BF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} + {31B96262-1C41-43B9-BA38-27AA385B05DB} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} EndGlobalSection EndGlobal diff --git a/doc/tutorial/14_lol_lua.cpp b/doc/tutorial/14_lol_lua.cpp index 653354c6..e9311ac3 100644 --- a/doc/tutorial/14_lol_lua.cpp +++ b/doc/tutorial/14_lol_lua.cpp @@ -37,18 +37,26 @@ public: //------------------------------------------------------------------------- static int AddFive(lua_State* l) { - LuaInt32 i; i.Get(l, 1); + LuaStack stack(l); + int32_t i = stack.GetVar(); + //LuaInt32 i; i.Get(l, 1); i += 5; - return i.Return(l); - } + //return i.Return(l); + return stack.SetVar(i).Return(); + } static int AddTenInstance(lua_State* l) { LuaStack stack(l); - LuaDemoObjectPtr obj; - LuaFloat f; - stack >> obj >> f; + DemoObject* obj = nullptr; // stack.GetPtr(); + float f = stack.GetVar(); + + //LuaDemoObjectPtr obj; + //LuaFloat f; + //stack >> obj >> f; f = obj->AddTenMethod(f); - return f.Return(l); + + //return f.Return(l); + return 0;// stack.SetVar(f).SetPtr().Return(); } float AddTenMethod(float f) { diff --git a/doc/tutorial/imgui.ini b/doc/tutorial/imgui.ini index c39d8823..f11877b3 100644 --- a/doc/tutorial/imgui.ini +++ b/doc/tutorial/imgui.ini @@ -4,12 +4,12 @@ Size=400,400 Collapsed=0 [testature] -Pos=266,15 +Pos=187,98 Size=494,359 Collapsed=0 [SO FUN !!] -Pos=30,24 +Pos=16,24 Size=113,99 Collapsed=0 diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index 54cc511b..aaf6cb84 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -883,6 +883,24 @@ public: return lua_gettop(m_state); } + //------------------------------------------------------------------------- + template + T GetVar(T defaultValue = 0, bool isOptional = false) + { + return Var(defaultValue, m_state, m_index, isOptional).GetValue(); + } + + //------------------------------------------------------------------------- + template + Stack& SetVar(T& value) + { + m_result += Var(value, m_state, m_index).Return(m_state); + return *this; + } + + //------------------------------------------------------------------------- + int32_t Return() { return m_result; } + //------------------------------------------------------------------------- template Stack& operator>>(T& var) @@ -891,42 +909,6 @@ public: return *this; } - /* - template - Stack& operator>>(Var& var) - { - var = Var(var.GetValue(), m_state, m_index, var.IsOptional()); - return *this; - } - template - Stack& operator>>(Var& var) - { - var = Var(var.GetValue(), m_state, m_index, var.IsOptional()); - return *this; - } - template - Stack& operator>>(VarPtr& var) - { - var = VarPtr(m_state, m_index); - return *this; - } - */ - /* - template - Stack& operator>>(T& var) - { - Var ret(m_state, m_index); - var = ret.GetValue(); - return *this; - } - template - Stack& operator>>(VarPtrLight& var) - { - var = VarPtrLight(m_state, m_index); - return *this; - } - */ - //------------------------------------------------------------------------- template Stack& operator<<(T& var) @@ -934,27 +916,6 @@ public: m_result += var.Return(m_state); return *this; } - /* - template - Stack& operator<<(T& var) - { - Var ret(var, false); - m_result += ret.Return(m_state); - return *this; - } - template - Stack& operator<<(VarPtr& var) - { - m_result += var.Return(m_state); - return *this; - } - template - Stack& operator<<(VarPtrLight& var) - { - m_result += var.Return(m_state); - return *this; - } - */ private: lua_State* m_state = nullptr; From 4d78d62a70e78e3db6c4ea2a5a87ef2479b459ab Mon Sep 17 00:00:00 2001 From: touky Date: Sat, 29 Oct 2016 23:33:08 -0400 Subject: [PATCH 2/5] Lolua refactor 2nd pass: New version is much simpler and practical Next pass is clean-up and fix of all the old usage --- doc/samples/meshviewer/scenesetup.cpp | 6 +- doc/samples/meshviewer/scenesetup.h | 2 +- doc/tutorial/14_lol_lua.cpp | 80 ++-- src/easymesh/easymeshlua.cpp | 6 +- src/easymesh/easymeshlua.h | 2 +- src/lolimgui.cpp | 2 +- src/lolua/baselua.h | 501 +++++++++++++++++++++----- src/utils.h | 10 +- 8 files changed, 465 insertions(+), 144 deletions(-) diff --git a/doc/samples/meshviewer/scenesetup.cpp b/doc/samples/meshviewer/scenesetup.cpp index 46806349..74e942dd 100644 --- a/doc/samples/meshviewer/scenesetup.cpp +++ b/doc/samples/meshviewer/scenesetup.cpp @@ -242,10 +242,10 @@ int SceneSetupLuaObject::Toggle(lua_State* l) } //----------------------------------------------------------------------------- -const LuaObjectLib* SceneSetupLuaObject::GetLib() +const LuaObjectLibrary* SceneSetupLuaObject::GetLib() { typedef SceneSetupLuaObject SSLO; - static const LuaObjectLib lib = LuaObjectLib( + static const LuaObjectLibrary lib = LuaObjectLibrary( "SceneSetup", //Statics { { nullptr, nullptr } }, @@ -273,7 +273,7 @@ SceneSetupLuaLoader::SceneSetupLuaLoader() : LuaLoader() { lua_State* l = GetLuaState(); - LuaObjectDef::Register(l); + LuaObjectHelper::Register(l); } //----------------------------------------------------------------------------- diff --git a/doc/samples/meshviewer/scenesetup.h b/doc/samples/meshviewer/scenesetup.h index 9b6ffc29..39165715 100644 --- a/doc/samples/meshviewer/scenesetup.h +++ b/doc/samples/meshviewer/scenesetup.h @@ -116,7 +116,7 @@ public: //------------------------------------------------------------------------- static SceneSetupLuaObject* New(lua_State* l, int arg_nb); - static const LuaObjectLib* GetLib(); + static const LuaObjectLibrary* GetLib(); //------------------------------------------------------------------------- public: diff --git a/doc/tutorial/14_lol_lua.cpp b/doc/tutorial/14_lol_lua.cpp index e9311ac3..de5b5cd0 100644 --- a/doc/tutorial/14_lol_lua.cpp +++ b/doc/tutorial/14_lol_lua.cpp @@ -37,27 +37,25 @@ public: //------------------------------------------------------------------------- static int AddFive(lua_State* l) { - LuaStack stack(l); - int32_t i = stack.GetVar(); - //LuaInt32 i; i.Get(l, 1); + auto stack = LuaStack::Begin(l); + int32_t i = stack.Get(); + i += 5; - //return i.Return(l); - return stack.SetVar(i).Return(); - } + + return (stack << i).End(); + } + static int AddTenInstance(lua_State* l) { - LuaStack stack(l); - DemoObject* obj = nullptr; // stack.GetPtr(); - float f = stack.GetVar(); + auto stack = LuaStack::Begin(l); + DemoObject* obj = stack.GetPtr(); + float f = stack.Get(); - //LuaDemoObjectPtr obj; - //LuaFloat f; - //stack >> obj >> f; f = obj->AddTenMethod(f); - //return f.Return(l); - return 0;// stack.SetVar(f).SetPtr().Return(); + return (stack << f).End(); } + float AddTenMethod(float f) { return (f + 10); @@ -65,27 +63,30 @@ public: static int GetX(lua_State* l) { - LuaStack stack(l); - LuaDemoObjectPtr obj; - LuaInt32 i; - stack >> obj; + auto stack = LuaStack::Begin(l); + DemoObject* obj = stack.GetPtr(); + auto i = stack.Get(); + i = obj->m_x; - return stack << i; + + return (stack << i).End(); } + static int SetX(lua_State* l) { - LuaStack stack(l); - LuaDemoObjectPtr obj; - LuaInt32 i; - stack >> obj >> i; + auto stack = LuaStack::Begin(l); + DemoObject* obj = stack.GetPtr(); + auto i = stack.Get(); + obj->m_x = i; - return 0; + + return stack.End(); } //------------------------------------------------------------------------- - static const LuaObjectLib* GetLib() + static const LuaObjectLibrary* GetLib() { - static const LuaObjectLib lib = LuaObjectLib( + static const LuaObjectLibrary lib = LuaObjectLibrary( "LoluaDemo", { { "AddFive", &DemoObject::AddFive } }, { { "AddTenInstance", &DemoObject::AddTenInstance } }, @@ -99,9 +100,12 @@ public: //----------------------------------------------------------------------------- static int GlobalAddString(lua_State* l) { - LuaString s; s.Get(l, 1); - s() += "_added"; - return s.Return(l); + auto stack = LuaStack::Begin(l); + auto s = stack.Get(); + + s += "_added"; + + return (stack << s).End(); } //----------------------------------------------------------------------------- @@ -113,7 +117,7 @@ public: lua_State* l = GetLuaState(); //Registering demo object - LuaObjectDef::Register(l); + LuaObjectHelper::Register(l); //Registering function LuaFunction add_string(l, "GlobalAddString", &GlobalAddString); @@ -166,18 +170,18 @@ public: demo_loader->TestStuff(); //Grab global test values - float testvalue_num = demo_loader->GetVar("testvalue_num"); - int32_t testvalue_int = demo_loader->GetVar("testvalue_int"); - uint32_t testvalue_uint = demo_loader->GetVar("testvalue_uint"); - String testvalue_str = demo_loader->GetVar("testvalue_str"); + float testvalue_num = demo_loader->Get("testvalue_num"); + int32_t testvalue_int = demo_loader->Get("testvalue_int"); + uint32_t testvalue_uint = demo_loader->Get("testvalue_uint"); + String testvalue_str = demo_loader->Get("testvalue_str"); //Grab string modified with function - String function_return = demo_loader->GetVar("function_return"); + String function_return = demo_loader->Get("function_return"); //Grab global values modified with DemoObject - int32_t loluademo_return = demo_loader->GetVar("loluademo_return"); - int32_t loluademo_getx = demo_loader->GetVar("loluademo_getx"); - float loluademo_inst_return = demo_loader->GetVar("loluademo_inst_return"); + int32_t loluademo_return = demo_loader->Get("loluademo_return"); + int32_t loluademo_getx = demo_loader->Get("loluademo_getx"); + float loluademo_inst_return = demo_loader->Get("loluademo_inst_return"); DemoObject* loluademo_inst = demo_loader->GetPtr("loluademo_inst"); msg::info("Lua Vars: \ diff --git a/src/easymesh/easymeshlua.cpp b/src/easymesh/easymeshlua.cpp index 258b3182..a68c6a7e 100644 --- a/src/easymesh/easymeshlua.cpp +++ b/src/easymesh/easymeshlua.cpp @@ -27,7 +27,7 @@ EasyMeshLuaLoader::EasyMeshLuaLoader() : LuaLoader() lua_State* l = GetLuaState(); //Registering demo object - LuaObjectDef::Register(l); + LuaObjectHelper::Register(l); } //----------------------------------------------------------------------------- @@ -88,10 +88,10 @@ EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State* l, int arg_nb) } //----------------------------------------------------------------------------- -const LuaObjectLib* EasyMeshLuaObject::GetLib() +const LuaObjectLibrary* EasyMeshLuaObject::GetLib() { typedef EasyMeshLuaObject EMLO; - static const LuaObjectLib lib = LuaObjectLib( + static const LuaObjectLibrary lib = LuaObjectLibrary( "EasyMesh", //Statics { { nullptr, nullptr } }, diff --git a/src/easymesh/easymeshlua.h b/src/easymesh/easymeshlua.h index 3632e2d4..35e76140 100644 --- a/src/easymesh/easymeshlua.h +++ b/src/easymesh/easymeshlua.h @@ -28,7 +28,7 @@ public: //------------------------------------------------------------------------- static EasyMeshLuaObject* New(lua_State* l, int arg_nb); - static const LuaObjectLib* GetLib(); + static const LuaObjectLibrary* GetLib(); //------------------------------------------------------------------------- static int AppendCylinder(lua_State* l) diff --git a/src/lolimgui.cpp b/src/lolimgui.cpp index ab47cc89..70a612b1 100644 --- a/src/lolimgui.cpp +++ b/src/lolimgui.cpp @@ -375,7 +375,7 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) m_vdecl->SetStream(vbo, m_attribs[0], m_attribs[1], m_attribs[2]); const ImDrawIdx* idx_buffer_offset = 0; - for (size_t cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[(int)cmd_i]; #ifdef SHOW_IMGUI_DEBUG diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index aaf6cb84..035a641b 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -16,6 +16,9 @@ #pragma once +#define OLD_VAR_SYSTEM true +#define NEW_VAR_SYSTEM true + namespace lol { @@ -33,69 +36,70 @@ typedef struct ClassVar } ClassVar; //----------------------------------------------------------------------------- -struct ObjectLib +class Object { - typedef struct ClassVarStr +public: + //----------------------------------------------------------------------------- + struct Library { - ClassVarStr() { } - ClassVarStr(String var_name, lua_CFunction get, lua_CFunction set) + typedef struct ClassVarStr { - m_get_name = String("Get") + var_name; - m_set_name = String("Set") + var_name; - m_get = get; - m_set = set; - } - String m_get_name = ""; - String m_set_name = ""; - lua_CFunction m_get = nullptr; - lua_CFunction m_set = nullptr; - } ClassVarStr; - - ObjectLib(String class_name, - array const& statics, - array const& methods, - array const& variables) - { - m_class_name = class_name; - m_static_name = class_name + "_lib"; - m_method_name = class_name + "_inst"; - - m_statics = statics; - if (m_statics.count() == 0 - || m_statics.last().name != nullptr - || m_statics.last().func != nullptr) - m_statics.push({ nullptr, nullptr }); - - m_methods = methods; - if (m_methods.count() == 0 - || m_methods.last().name != nullptr - || m_methods.last().func != nullptr) - m_methods.push({ nullptr, nullptr }); - - for (ClassVar const& cv : variables) + ClassVarStr() { } + ClassVarStr(String var_name, lua_CFunction get, lua_CFunction set) + { + m_get_name = String("Get") + var_name; + m_set_name = String("Set") + var_name; + m_get = get; + m_set = set; + } + String m_get_name = ""; + String m_set_name = ""; + lua_CFunction m_get = nullptr; + lua_CFunction m_set = nullptr; + } ClassVarStr; + + Library(String class_name, + array const& statics, + array const& methods, + array const& variables) { - if (cv.name && cv.get && cv.set) + m_class_name = class_name; + m_static_name = class_name + "_lib"; + m_method_name = class_name + "_inst"; + + m_statics = statics; + if (m_statics.count() == 0 + || m_statics.last().name != nullptr + || m_statics.last().func != nullptr) + m_statics.push({ nullptr, nullptr }); + + m_methods = methods; + if (m_methods.count() == 0 + || m_methods.last().name != nullptr + || m_methods.last().func != nullptr) + m_methods.push({ nullptr, nullptr }); + + for (ClassVar const& cv : variables) { - m_variables.push({ cv.name, cv.get, cv.set }); + if (cv.name && cv.get && cv.set) + { + m_variables.push({ cv.name, cv.get, cv.set }); + } } + if (m_variables.count() == 0 + || variables.last().name != nullptr + || variables.last().get != nullptr + || variables.last().set != nullptr) + m_variables.push(ClassVarStr()); } - if (m_variables.count() == 0 - || variables.last().name != nullptr - || variables.last().get != nullptr - || variables.last().set != nullptr) - m_variables.push(ClassVarStr()); - } - String m_class_name = ""; - String m_static_name = ""; - String m_method_name = ""; - array m_statics; - array m_methods; - array m_variables; -}; + String m_class_name = ""; + String m_static_name = ""; + String m_method_name = ""; + array m_statics; + array m_methods; + array m_variables; + }; -//----------------------------------------------------------------------------- -class Object -{ public: Object() { } virtual ~Object() { } @@ -106,19 +110,20 @@ public: ASSERT(false); return nullptr; } - static const ObjectLib* GetLib() { ASSERT(false); return nullptr; } + static const Library* GetLib() { ASSERT(false); return nullptr; } }; //----------------------------------------------------------------------------- // Class available to link C++ class to Lua methods //-- -class ObjectDef +class ObjectHelper { -public: +private: //------------------------------------------------------------------------- - ObjectDef() { } - virtual ~ObjectDef() { } + ObjectHelper() { } + virtual ~ObjectHelper() { } +public: //------------------------------------------------------------------------- template static void Register(lua_State *l) @@ -163,8 +168,8 @@ public: lua_setfield(l, -1, "__index"); //Create variables Get/Set - const array& variables = GetVariables(); - for (const ObjectLib::ClassVarStr& var : variables) + const array& variables = GetVariables(); + for (const Object::Library::ClassVarStr& var : variables) { if (!var.m_get || !var.m_set) continue; @@ -183,27 +188,29 @@ public: } private: + //------------------------------------------------------------------------- template - static const ObjectLib* GetLib() + static const Object::Library* GetLibrary() { - const ObjectLib* lib = TLuaClass::GetLib(); + const Object::Library* lib = TLuaClass::GetLib(); ASSERT(lib); return lib; } public: + //------------------------------------------------------------------------- template - static const char* GetObjectName() { return GetLib()->m_class_name.C(); } + static const char* GetObjectName() { return GetLibrary()->m_class_name.C(); } template - static const char* GetStaticName() { return GetLib()->m_static_name.C(); } + static const char* GetStaticName() { return GetLibrary()->m_static_name.C(); } template - static const char* GetMethodName() { return GetLib()->m_method_name.C(); } + static const char* GetMethodName() { return GetLibrary()->m_method_name.C(); } template - static const ClassMethod* GetStaticMethods() { return GetLib()->m_statics.data(); } + static const ClassMethod* GetStaticMethods() { return GetLibrary()->m_statics.data(); } template - static const ClassMethod* GetInstanceMethods() { return GetLib()->m_methods.data(); } + static const ClassMethod* GetInstanceMethods() { return GetLibrary()->m_methods.data(); } template - static const array& GetVariables() { return GetLib()->m_variables; } + static const array& GetVariables() { return GetLibrary()->m_variables; } protected: //------------------------------------------------------------------------- @@ -241,6 +248,9 @@ public: } }; +//----------------------------------------------------------------------------- +#if OLD_VAR_SYSTEM + //----------------------------------------------------------------------------- template class VarPtr @@ -311,7 +321,7 @@ protected: } virtual void InnerGet(lua_State* l, int& index) { - T** obj = static_cast(luaL_checkudata(l, index++, ObjectDef::GetMethodName())); + T** obj = static_cast(luaL_checkudata(l, index++, ObjectHelper::GetMethodName())); m_value = obj ? *obj : nullptr; } void InnerPush(lua_State* l) @@ -339,6 +349,7 @@ protected: } }; */ + //----------------------------------------------------------------------------- template class Var @@ -431,6 +442,7 @@ protected: }; //----------------------------------------------------------------------------- +#ifndef BASE_TYPES template<> inline bool Var::InnerIsValid(lua_State* l, int index) { return lua_isboolean(l, index); @@ -638,8 +650,10 @@ template<> inline int Var::InnerPush(lua_State* l) 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: @@ -866,42 +880,150 @@ protected: return s.Return(l); } }; +#endif //CUSTOM_TYPES + +#endif //OLD_VAR_SYSTEM +//----------------------------------------------------------------------------- +// Stack: Main class that encapsulates everything ----------------------------- //----------------------------------------------------------------------------- class Stack { public: + +#if NEW_VAR_SYSTEM + + //------------------------------------------------------------------------- + static Stack Begin(lua_State* state, int32_t start_index = 1) + { + return Stack(state, start_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; } virtual ~Stack() { } - inline operator int32_t() { return m_result; } + int32_t GetArgs() { return lua_gettop(m_state); } - //------------------------------------------------------------------------- - template - T GetVar(T defaultValue = 0, bool isOptional = false) - { - return Var(defaultValue, m_state, m_index, isOptional).GetValue(); - } +#if NEW_VAR_SYSTEM - //------------------------------------------------------------------------- - template - Stack& SetVar(T& value) - { - m_result += Var(value, m_state, m_index).Return(m_state); - return *this; - } +public: + //------------------------------------------------------------------------- + //The encapsulating struct for pointers + template + struct Ptr + { + public: + T* m_value = nullptr; + bool m_throw_error = false; + + //--------------------------------------------------------------------- + //m_value: Your stored value + //throw_error: If true, lua will throw an error if the value get fails + Ptr(T* value, bool throw_error = false) + { + m_value = value; + m_throw_error = throw_error; + } + Ptr(const T*& value) { m_value = value; } + inline operator T*() { return m_value; } + inline Ptr& operator=(T const*& value) { m_value = value; return *this; } + }; //------------------------------------------------------------------------- - int32_t Return() { return m_result; } + template T Get(bool isOptional = false) { return Get(InnerDefault(), isOptional); } + template SafeEnum GetEnum(bool isOptional = false) { return GetEnum(InnerDefaultSafeEnum(), isOptional); } + template Ptr

GetPtr(bool isOptional = false) { return GetPtr(InnerDefaultPtr

(), isOptional); } + + //------------------------------------------------------------------------- +#define DECLARE_STACK_GET(T0, T1, GET_NAME, INNER_IS_VALID, INNER_GET) \ + template \ + T1 GET_NAME(T1 value, bool isOptional = false) \ + { \ + bool is_nil = lua_isnil(m_state, m_index); \ + if (!isOptional || (!is_nil && INNER_IS_VALID())) \ + { \ + ASSERT(!is_nil); /* touky: should assert, though ? */ \ + return INNER_GET(value); \ + } \ + return value; \ + } + DECLARE_STACK_GET(T, T, Get, InnerIsValid, InnerGet); + DECLARE_STACK_GET(E, SafeEnum, GetEnum, InnerIsValidSafeEnum, InnerGetSafeEnum); + DECLARE_STACK_GET(P, Ptr

, GetPtr, InnerIsValidPtr, InnerGetPtr); + +#undef DECLARE_STACK_GET + + //------------------------------------------------------------------------- + template Stack& operator<<(T& value) { m_result += InnerPush(value); return *this; } + template Stack& operator<<(SafeEnum& value) { m_result += InnerPushSafeEnum(value); return *this; } + template Stack& operator<<(Ptr

& value) { m_result += InnerPushPtr

(value); return *this; } + +protected: + #define INNER_ERROR "Your type is not implemented. For pointers, use LuaPtr()" + template T InnerDefault() { return T(0); } + template bool InnerIsValid() { ASSERT(false, INNER_ERROR); return false; } + 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(); } + template SafeEnum InnerGetSafeEnum(SafeEnum value) { return FindValue >(InnerGet(value.ToString())); } + template int InnerPushSafeEnum(SafeEnum value) { return InnerPush(value.ToString()); } +#endif //STACK_STRING + +#ifndef INNER_PTR + template inline Ptr

InnerDefaultPtr() { return Ptr

(nullptr); } + template inline bool InnerIsValidPtr() { return !!lua_isuserdata(m_state, m_index); } + template inline Ptr

InnerGetPtr(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 Ptr

(obj ? *obj : value.m_value); + } + template inline int InnerPushPtr(Ptr

value) + { + P** data = (P**)lua_newuserdata(m_state, sizeof(P*)); + *data = value.m_value; + } +#endif //STACK_STRING + +#endif //NEW_VAR_SYSTEM + + //------------------------------------------------------------------------- +#if OLD_VAR_SYSTEM +public: + inline operator int32_t() { return m_result; } //------------------------------------------------------------------------- + template Stack& operator>>(T& var) { @@ -909,6 +1031,8 @@ public: return *this; } +#if !NEW_VAR_SYSTEM + //------------------------------------------------------------------------- template Stack& operator<<(T& var) @@ -917,16 +1041,152 @@ public: return *this; } +#endif //NEW_VAR_SYSTEM + +#endif //OLD_VAR_SYSTEM + private: lua_State* m_state = nullptr; int32_t m_index = 1; int32_t m_result = 0; }; +//----------------------------------------------------------------------------- +#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++); } +template<> inline int Stack::InnerPush(bool value) { lua_pushboolean(m_state, value); return 1; } +#endif // STACK_BOOL + +//----------------------------------------------------------------------------- +#ifndef STACK_CHAR_CONST +template<> inline bool Stack::InnerIsValid() { return !!lua_isstring(m_state, m_index); } +template<> inline char const* Stack::InnerGet(char const* value) { UNUSED(value); return lua_tostring(m_state, m_index++); } +template<> inline int Stack::InnerPush(char const* value) { lua_pushstring(m_state, value); return 1; } +#endif // STACK_CHAR_CONST + +//----------------------------------------------------------------------------- +#ifndef STACK_STRING +template<> inline String Stack::InnerDefault() { return String(); } +template<> inline bool Stack::InnerIsValid() { return InnerIsValid(); } +template<> inline String Stack::InnerGet(String value) { return String(InnerGet(value.C())); } +template<> inline int Stack::InnerPush(String value) { return InnerPush(value.C()); } +#endif //STACK_STRING + +//----------------------------------------------------------------------------- +#ifndef STACK_STRING +template<> inline bool Stack::InnerIsValid() { return !!lua_isnumber(m_state, m_index); } +template<> inline double Stack::InnerGet(double value) { UNUSED(value); return lua_tonumber(m_state, m_index++); } +template<> inline int Stack::InnerPush(double value) { lua_pushnumber(m_state, value); return 1; } +#endif //STACK_STRING + +//----------------------------------------------------------------------------- +#ifndef STACK_FLOAT +template<> inline bool Stack::InnerIsValid() { return InnerIsValid(); } +template<> inline float Stack::InnerGet(float value) { return (float)InnerGet((double)value); } +template<> inline int Stack::InnerPush(float value) { return InnerPush((double)value); } +#endif //STACK_FLOAT + +//----------------------------------------------------------------------------- +//DO NOT REMOVE: IT IS THE BASIS FOR INT 32 +#ifndef STACK_INT64 +template<> 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++); } +template<> inline int Stack::InnerPush(int64_t value) { lua_pushinteger(m_state, value); return 1; } +#endif //STACK_INT64 + +//----------------------------------------------------------------------------- +#ifndef STACK_UINT64 +template<> inline bool Stack::InnerIsValid() { return !!lua_isnumber(m_state, m_index); } +template<> inline uint64_t Stack::InnerGet(uint64_t value) { UNUSED(value); return (uint64_t)lua_tointeger(m_state, m_index++); } +template<> inline int Stack::InnerPush(uint64_t value) { lua_pushinteger(m_state, (lua_Unsigned)value); return 1; } +#endif //STACK_UINT64 + +//----------------------------------------------------------------------------- +#ifndef STACK_INT32 +template<> inline bool Stack::InnerIsValid() { return !!lua_isnumber(m_state, m_index); } +template<> inline int32_t Stack::InnerGet(int32_t value) { UNUSED(value); return (int32_t)lua_tointeger(m_state, m_index++); } +template<> inline int Stack::InnerPush(int32_t value) { lua_pushinteger(m_state, (lua_Integer)value); return 1; } +#endif STACK_INT32 + +//----------------------------------------------------------------------------- +#ifndef STACK_UINT32 +template<> inline bool Stack::InnerIsValid() { return !!lua_isnumber(m_state, m_index); } +template<> inline uint32_t Stack::InnerGet(uint32_t value) { UNUSED(value); return (uint32_t)(lua_Unsigned)lua_tointeger(m_state, m_index++); } +template<> inline int Stack::InnerPush(uint32_t value) { lua_pushinteger(m_state, (lua_Unsigned)value); return 1; } +#endif //STACK_UINT32 + +//----------------------------------------------------------------------------- +#ifndef STACK_VEC2 +template<> inline bool Stack::InnerIsValid() { return InnerIsValid(); } +template<> inline vec2 Stack::InnerGet(vec2 value) { return vec2(InnerGet(value.x), Get(value.y, true)); } +template<> inline int Stack::InnerPush(vec2 value) { return (InnerPush(value.x) + InnerPush(value.y)); } +#endif //STACK_VEC2 + +//----------------------------------------------------------------------------- +#ifndef STACK_VEC3 +template<> inline bool Stack::InnerIsValid() { return InnerIsValid(); } +template<> inline vec3 Stack::InnerGet(vec3 value) { return vec3(InnerGet(value.x), Get(value.y, true), Get(value.z, true)); } +template<> inline int Stack::InnerPush(vec3 value) { return (InnerPush(value.x) + InnerPush(value.y) + InnerPush(value.z)); } +#endif //STACK_VEC3 + +//----------------------------------------------------------------------------- +#ifndef STACK_VEC4 +template<> inline bool Stack::InnerIsValid() { return InnerIsValid(); } +template<> inline vec4 Stack::InnerGet(vec4 value) { return vec4(InnerGet(value.x), Get(value.y, true), Get(value.z, true), Get(value.w, true)); } +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 { - friend class ObjectDef; + friend class ObjectHelper; public: Loader(); virtual ~Loader(); @@ -934,6 +1194,27 @@ public: bool ExecLuaFile(String const &lua); bool ExecLuaCode(String const &lua); +#if NEW_VAR_SYSTEM + //------------------------------------------------------------------------- +#define DECLARE_LOADER_GET(T0, T1, GET_NAME) \ + template \ + T1 GET_NAME(String const &name) \ + { \ + lua_getglobal(m_lua_state, name.C()); \ + auto stack = LuaStack::Begin(m_lua_state, -1); \ + auto result = stack.GET_NAME(); \ + lua_pop(m_lua_state, 1); \ + return result; \ + } + + DECLARE_LOADER_GET(T, T, Get); + DECLARE_LOADER_GET(E, SafeEnum, GetEnum); + DECLARE_LOADER_GET(P, P*, GetPtr); + +#undef DECLARE_LOADER_GET + +#else //OLD_VAR_SYSTEM + template T GetVar(String const &name) { @@ -951,6 +1232,8 @@ public: return var(); } +#endif //OLD_VAR_SYSTEM + protected: lua_State* GetLuaState(); static void Store(lua_State* l, Loader* loader); @@ -964,10 +1247,33 @@ private: }; //----------------------------------------------------------------------------- -// ObjectDef member implementations that require VarPtr +// ObjectHelper member implementations that require VarPtr +#if NEW_VAR_SYSTEM template -int ObjectDef::Store(lua_State * l) +int ObjectHelper::Store(lua_State * l) +{ + auto stack = LuaStack::Begin(l); + auto obj = stack.Get >(); + ASSERT(obj); + Loader::StoreObject(l, obj); + return 0; +} + +template +int ObjectHelper::Del(lua_State * l) +{ + auto stack = LuaStack::Begin(l); + auto obj = stack.Get >(); + ASSERT(obj); + delete obj; + return 0; +} + +#else //OLD_VAR_SYSTEM + +template +int ObjectHelper::Store(lua_State * l) { VarPtr obj; obj.Get(l, 1); @@ -977,7 +1283,7 @@ int ObjectDef::Store(lua_State * l) } template -int ObjectDef::Del(lua_State * l) +int ObjectHelper::Del(lua_State * l) { VarPtr obj; obj.Get(l, 1); @@ -986,13 +1292,22 @@ int ObjectDef::Del(lua_State * l) return 0; } +#endif //OLD_VAR_SYSTEM + + } /* namespace Lolua */ +//TYPEDEFS typedef Lolua::Function LuaFunction; -typedef Lolua::ObjectDef LuaObjectDef; +typedef Lolua::ObjectHelper LuaObjectHelper; typedef Lolua::Object LuaObject; -typedef Lolua::ObjectLib LuaObjectLib; +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; @@ -1006,6 +1321,6 @@ typedef Lolua::Var LuaVec2; typedef Lolua::Var LuaVec3; typedef Lolua::Var LuaVec4; typedef Lolua::VarColor LuaColor; -typedef Lolua::Stack LuaStack; +#endif //OLD_VAR_SYSTEM } /* namespace lol */ diff --git a/src/utils.h b/src/utils.h index 3faf9d84..5929394e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -61,6 +61,12 @@ template< class T > inline int GetRandom(array src) // Gets the value for the given enum type. template inline T FindValue(const char* name) +{ + auto str = String(name); + return FindValue(str); +} + +template inline T FindValue(String const& name) { String n = name; n.to_lower(); @@ -72,10 +78,6 @@ template inline T FindValue(const char* name) } return T::Max; } -template inline T FindValue(String const& name) -{ - return FindValue(name.C()); -} } /* namespace lol */ From 0cdeb424d95d4608817b03424f9596d195d5d57d Mon Sep 17 00:00:00 2001 From: touky Date: Sun, 30 Oct 2016 19:56:23 -0400 Subject: [PATCH 3/5] 2nd pass, removed all old code, and fixed all the wrong usages --- doc/samples/meshviewer/scenesetup.cpp | 82 ++- doc/samples/meshviewer/scenesetup.h | 2 - doc/tutorial/14_lol_lua.cpp | 1 - src/easymesh/easymeshlua.cpp | 7 +- src/easymesh/easymeshlua.h | 642 ++++++++++---------- src/lolua/baselua.cpp | 14 +- src/lolua/baselua.h | 844 ++------------------------ 7 files changed, 394 insertions(+), 1198 deletions(-) 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 */ From eb943fc5e332ac65fb5e3e2264ac23dc809fb030 Mon Sep 17 00:00:00 2001 From: touky Date: Mon, 31 Oct 2016 19:31:34 -0400 Subject: [PATCH 4/5] Lolua small simplification getter default params are better now --- doc/samples/meshviewer/imgui.ini | 10 +++ doc/tutorial/14_lol_lua.cpp | 29 ++++++-- doc/tutorial/14_lol_lua.lua | 2 +- src/easymesh/easymeshlua.cpp | 2 +- src/easymesh/easymeshlua.h | 76 ++++++++++---------- src/lolua/baselua.h | 115 ++++++++++++++++++++++++------- 6 files changed, 166 insertions(+), 68 deletions(-) create mode 100644 doc/samples/meshviewer/imgui.ini diff --git a/doc/samples/meshviewer/imgui.ini b/doc/samples/meshviewer/imgui.ini new file mode 100644 index 00000000..0e0a9153 --- /dev/null +++ b/doc/samples/meshviewer/imgui.ini @@ -0,0 +1,10 @@ +[Debug] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Camera Setup] +Pos=60,60 +Size=307,314 +Collapsed=0 + diff --git a/doc/tutorial/14_lol_lua.cpp b/doc/tutorial/14_lol_lua.cpp index ce0348ab..4c4d3d39 100644 --- a/doc/tutorial/14_lol_lua.cpp +++ b/doc/tutorial/14_lol_lua.cpp @@ -43,20 +43,24 @@ public: return (stack << i).End(); } - - static int AddTenInstance(lua_State* l) + + LOLUA_DECLARE_RETURN_METHOD(AddTenInstance, GetPtr(), AddTenMethod, Get(), Get(), Get()); + static int _AddTenInstance(lua_State* l) { auto stack = LuaStack::Begin(l); DemoObject* obj = stack.GetPtr(); - float f = stack.Get(); + float f = stack.Get(); + int32_t i = stack.Get(); + int32_t i2 = stack.Get(); - f = obj->AddTenMethod(f); + f = obj->AddTenMethod(f, i, i2); return (stack << f).End(); } - float AddTenMethod(float f) + float AddTenMethod(float f, int32_t i, int32_t i2) { + UNUSED(i, i2); return (f + 10); } @@ -71,7 +75,8 @@ public: return (stack << i).End(); } - static int SetX(lua_State* l) + LOLUA_DECLARE_VOID_METHOD(SetX, GetPtr(), SetXMethod, Get()); + static int _SetX(lua_State* l) { auto stack = LuaStack::Begin(l); DemoObject* obj = stack.GetPtr(); @@ -82,6 +87,12 @@ public: return stack.End(); } + void SetXMethod(int32_t i) + { + m_x = i; + } + + //------------------------------------------------------------------------- static const LuaObjectLibrary* GetLib() { @@ -190,6 +201,12 @@ public: function_return: %s, loluademo_return: %i, loluademo_inst_return: %.f, loluademo_getx: %i, loluademo_inst->m_x: %i.\n", function_return.C(), loluademo_return, loluademo_inst_return, loluademo_getx, loluademo_inst->m_x); +#define /***/ _LOLUA_ARG_1(a00) (float)a00 +#define /***/ _LOLUA_ARG_2(a00, a01) _LOLUA_ARG_1(a00), _LOLUA_ARG_1(a01) +#define /***/ _LOLUA_ARG_3(a00, a01, a02) _LOLUA_ARG_1(a00), _LOLUA_ARG_2(a01, a02) +#define /***/ _LOLUA_ARG_4(a00, a01, a02, a03) _LOLUA_ARG_1(a00), _LOLUA_ARG_3(a01, a02, a03) + msg::info("_LOLUA_ARG_1: %f, %f, %f, %f\n", _LOLUA_ARG_4(0, 1, 2, 3)); + delete demo_loader; Ticker::Shutdown(); diff --git a/doc/tutorial/14_lol_lua.lua b/doc/tutorial/14_lol_lua.lua index cea94073..0b0a0428 100644 --- a/doc/tutorial/14_lol_lua.lua +++ b/doc/tutorial/14_lol_lua.lua @@ -13,4 +13,4 @@ loluademo_return = LoluaDemo.AddFive(1); loluademo_inst = LoluaDemo.New(); loluademo_inst:SetX(10); loluademo_getx = loluademo_inst:GetX(); -loluademo_inst_return = loluademo_inst:AddTenInstance(2.0); +loluademo_inst_return = loluademo_inst:AddTenInstance(2.5, 4, 6); diff --git a/src/easymesh/easymeshlua.cpp b/src/easymesh/easymeshlua.cpp index a36ab4d8..4edd141c 100644 --- a/src/easymesh/easymeshlua.cpp +++ b/src/easymesh/easymeshlua.cpp @@ -82,7 +82,7 @@ EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State* l, int arg_nb) UNUSED(l); UNUSED(arg_nb); LuaStack s = LuaStack::Begin(l); - String str = s.Get("", true); + String str = s.Get(""); return new EasyMeshLuaObject(str); } diff --git a/src/easymesh/easymeshlua.h b/src/easymesh/easymeshlua.h index 5fb32ea8..5409fab3 100644 --- a/src/easymesh/easymeshlua.h +++ b/src/easymesh/easymeshlua.h @@ -38,12 +38,13 @@ public: 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); + auto dualside = s.Get(false); + auto smooth = s.Get(false); + auto close = s.Get(false); m->m_instance.AppendCylinder(nsides, h, d1, d2, dualside, smooth, close); return s.End(); } + //LOLUA_DECLARE_VOID_METHOD(AppendSphere, GetPtr(), m_instance.AppendSphere, Get(), Get()); static int AppendSphere(lua_State* l) { auto s = LuaStack::Begin(l); @@ -53,6 +54,7 @@ public: m->m_instance.AppendSphere(ndivisions, d); return s.End(); } + static int AppendCapsule(lua_State* l) { auto s = LuaStack::Begin(l); @@ -78,8 +80,8 @@ public: 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); + auto chamf = s.Get(0.f); + auto smooth = s.Get(false); m->m_instance.AppendBox(size, chamf, smooth); return s.End(); } @@ -90,8 +92,8 @@ public: auto nbranches = s.Get(); auto d1 = s.Get(); auto d2 = s.Get(); - auto fade = s.Get(false, true); - auto fade2 = s.Get(false, true); + auto fade = s.Get(false); + auto fade2 = s.Get(false); m->m_instance.AppendStar(nbranches, d1, d2, fade, fade2); return s.End(); } @@ -102,7 +104,7 @@ public: auto nbranches = s.Get(); auto d1 = s.Get(); auto d2 = s.Get(); - auto extrad = s.Get(0.f, true); + auto extrad = s.Get(0.f); m->m_instance.AppendExpandedStar(nbranches, d1, d2, extrad); return s.End(); } @@ -112,7 +114,7 @@ public: auto m = s.GetPtr(); auto nsides = s.Get(); auto d = s.Get(); - auto fade = s.Get(false, true); + auto fade = s.Get(false); m->m_instance.AppendDisc(nsides, d, fade); return s.End(); } @@ -121,7 +123,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto d = s.Get(); - auto fade = s.Get(false, true); + auto fade = s.Get(false); m->m_instance.AppendSimpleTriangle(d, fade); return s.End(); } @@ -130,7 +132,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto size = s.Get(); - auto fade = s.Get(false, true); + auto fade = s.Get(false); m->m_instance.AppendSimpleQuad(size, fade); return s.End(); } @@ -140,11 +142,11 @@ public: auto m = s.GetPtr(); auto nbsides = s.Get(); auto h = s.Get(); - auto sidemul = s.Get(0.f, true); + auto sidemul = s.Get(0.f); auto d0 = s.Get(); auto d1 = s.Get(); auto d2 = s.Get(); - auto offset = s.Get(false, true); + auto offset = s.Get(false); m->m_instance.AppendCog(nbsides, h, d0.x, d0.y, d1.x, d1.y, d2.x, d2.y, sidemul, offset); return s.End(); } @@ -264,8 +266,8 @@ public: 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); + auto xoff = s.Get(0.f); + auto abs = s.Get(true); m->m_instance.TaperX(y, z, xoff, abs); return s.End(); } @@ -275,8 +277,8 @@ public: 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); + auto yoff = s.Get(0.f); + auto abs = s.Get(true); m->m_instance.TaperY(x, z, yoff, abs); return s.End(); } @@ -286,8 +288,8 @@ public: 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); + auto zoff = s.Get(0.f); + auto abs = s.Get(true); m->m_instance.TaperZ(x, y, zoff, abs); return s.End(); } @@ -297,7 +299,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.TwistX(t, toff); return s.End(); } @@ -306,7 +308,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.TwistY(t, toff); return s.End(); } @@ -315,7 +317,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.TwistZ(t, toff); return s.End(); } @@ -326,8 +328,8 @@ public: 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); + auto xoff = s.Get(0.f); + auto abs = s.Get(true); m->m_instance.ShearX(y, z, xoff, abs); return s.End(); } @@ -337,8 +339,8 @@ public: 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); + auto yoff = s.Get(0.f); + auto abs = s.Get(true); m->m_instance.ShearY(x, z, yoff, abs); return s.End(); } @@ -348,8 +350,8 @@ public: 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); + auto zoff = s.Get(0.f); + auto abs = s.Get(true); m->m_instance.ShearZ(x, y, zoff, abs); return s.End(); } @@ -360,7 +362,7 @@ public: auto m = s.GetPtr(); auto y = s.Get(); auto z = s.Get(); - auto xoff = s.Get(0.f, true); + auto xoff = s.Get(0.f); m->m_instance.StretchX(y, z, xoff); return s.End(); } @@ -370,7 +372,7 @@ public: auto m = s.GetPtr(); auto x = s.Get(); auto z = s.Get(); - auto yoff = s.Get(0.f, true); + auto yoff = s.Get(0.f); m->m_instance.StretchY(x, z, yoff); return s.End(); } @@ -380,7 +382,7 @@ public: auto m = s.GetPtr(); auto x = s.Get(); auto y = s.Get(); - auto zoff = s.Get(0.f, true); + auto zoff = s.Get(0.f); m->m_instance.StretchZ(x, y, zoff); return s.End(); } @@ -390,7 +392,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.BendXY(t, toff); return s.End(); } @@ -399,7 +401,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.BendXZ(t, toff); return s.End(); } @@ -408,7 +410,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.BendYX(t, toff); return s.End(); } @@ -417,7 +419,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.BendYZ(t, toff); return s.End(); } @@ -426,7 +428,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.BendZX(t, toff); return s.End(); } @@ -435,7 +437,7 @@ public: auto s = LuaStack::Begin(l); auto m = s.GetPtr(); auto t = s.Get(); - auto toff = s.Get(0.f, true); + auto toff = s.Get(0.f); m->m_instance.BendZY(t, toff); return s.End(); } diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index c4316558..bf5d25c6 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -321,37 +321,56 @@ public: inline Ptr& operator=(T const*& value) { m_value = value; return *this; } }; +private: + bool AllowGet(bool is_optional, bool value_validity) + { + bool is_nil = lua_isnil(m_state, m_index); + if (!is_optional || (!is_nil && value_validity)) + { + ASSERT(!is_nil); /* touky: should it assert, though ? */ + return true; + } + return false; + } + +public: //------------------------------------------------------------------------- - template T Get(bool isOptional = false) { return Get(InnerDefault(), isOptional); } - template SafeEnum GetEnum(bool isOptional = false) { return GetEnum(InnerDefaultSafeEnum(), isOptional); } - template Ptr

GetPtr(bool isOptional = false) { return GetPtr(InnerDefaultPtr

(), isOptional); } + template T Get() { return Get(InnerDefault(), false); } + template T Get(T default_value) { return Get(default_value, true); } + template SafeEnum GetEnum() { return GetEnum(InnerDefaultSafeEnum(), false); } + template SafeEnum GetEnum(SafeEnum default_value) { return GetEnum(default_value, true); } + template Ptr

GetPtr() { return GetPtr(InnerDefaultPtr

(), false); } + template Ptr

GetPtr(Ptr

default_value) { return GetPtr(default_value, true); } +private: //------------------------------------------------------------------------- -#define DECLARE_STACK_GET(T0, T1, GET_NAME, INNER_IS_VALID, INNER_GET) \ - template \ - T1 GET_NAME(T1 value, bool isOptional = false) \ - { \ - bool is_nil = lua_isnil(m_state, m_index); \ - if (!isOptional || (!is_nil && INNER_IS_VALID())) \ - { \ - ASSERT(!is_nil); /* touky: should assert, though ? */ \ - return INNER_GET(value); \ - } \ - return value; \ + template T Get(T default_value, bool is_optional) + { + if (AllowGet(is_optional, InnerIsValid())) + return InnerGet(default_value); + return default_value; + } + template SafeEnum GetEnum(SafeEnum default_value, bool is_optional) + { + if (AllowGet(is_optional, InnerIsValidSafeEnum())) + return InnerGetSafeEnum(default_value); + return default_value; + } + template Ptr

GetPtr(Ptr

default_value, bool is_optional) + { + if (AllowGet(is_optional, InnerIsValidPtr

())) + return InnerGetPtr(default_value); + return default_value; } - DECLARE_STACK_GET(T, T, Get, InnerIsValid, InnerGet); - DECLARE_STACK_GET(E, SafeEnum, GetEnum, InnerIsValidSafeEnum, InnerGetSafeEnum); - DECLARE_STACK_GET(P, Ptr

, GetPtr, InnerIsValidPtr, InnerGetPtr); - -#undef DECLARE_STACK_GET - +public: //------------------------------------------------------------------------- - template Stack& operator<<(T& value) { m_result += InnerPush(value); return *this; } - template Stack& operator<<(SafeEnum& value) { m_result += InnerPushSafeEnum(value); return *this; } - template Stack& operator<<(Ptr

& value) { m_result += InnerPushPtr

(value); return *this; } + template Stack& operator<<(T value) { m_result += InnerPush(value); return *this; } + template Stack& operator<<(SafeEnum value) { m_result += InnerPushSafeEnum(value); return *this; } + template Stack& operator<<(Ptr

value) { m_result += InnerPushPtr

(value); return *this; } protected: + //------------------------------------------------------------------------- #define INNER_ERROR "Your type is not implemented. For pointers, use LuaPtr()" template T InnerDefault() { return T(0); } template bool InnerIsValid() { ASSERT(false, INNER_ERROR); return false; } @@ -389,6 +408,56 @@ private: int32_t m_result = 0; }; +//----------------------------------------------------------------------------- +#define /***/ LOLUA_VAR_1(a00) auto v00 = s.a00; +#define /***/ LOLUA_VAR_2(a00, a01) LOLUA_VAR_1(a00) auto v01 = s.a01; +#define /***/ LOLUA_VAR_3(a00, a01, a02) LOLUA_VAR_2(a00, a01) auto v02 = s.a02; +#define /***/ LOLUA_VAR_4(a00, a01, a02, a03) LOLUA_VAR_3(a00, a01, a02) auto v03 = s.a03; +#define /***/ LOLUA_VAR_5(a00, a01, a02, a03, a04) LOLUA_VAR_4(a00, a01, a02, a03) auto v04 = s.a04; +#define /***/ LOLUA_VAR_6(a00, a01, a02, a03, a04, a05) LOLUA_VAR_5(a00, a01, a02, a03, a04) auto v05 = s.a05; +#define /***/ LOLUA_VAR_7(a00, a01, a02, a03, a04, a05, a06) LOLUA_VAR_6(a00, a01, a02, a03, a04, a05) auto v06 = s.a06; +#define /***/ LOLUA_VAR_8(a00, a01, a02, a03, a04, a05, a06, a07) LOLUA_VAR_7(a00, a01, a02, a03, a04, a05, a06) auto v07 = s.a07; +#define /***/ LOLUA_VAR_9(a00, a01, a02, a03, a04, a05, a06, a07, a08) LOLUA_VAR_8(a00, a01, a02, a03, a04, a05, a06, a07) auto v08 = s.a08; +#define /**/ LOLUA_VAR_10(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09) LOLUA_VAR_9(a00, a01, a02, a03, a04, a05, a06, a07, a08) auto v09 = s.a09; +#define /**/ LOLUA_VAR_11(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09, a10) LOLUA_VAR_10(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09) auto v10 = s.a10; +#define /**/ LOLUA_VAR_12(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, a11) LOLUA_VAR_11(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09) auto v11 = s.a11; +//----------------------------------------------------------------------------- +#define /***/ LOLUA_ARG_1(a00) v00 +#define /***/ LOLUA_ARG_2(a00, a01) LOLUA_ARG_1(a00), v01 +#define /***/ LOLUA_ARG_3(a00, a01, a02) LOLUA_ARG_2(a00, a01), v02 +#define /***/ LOLUA_ARG_4(a00, a01, a02, a03) LOLUA_ARG_3(a00, a01, a02), v03 +#define /***/ LOLUA_ARG_5(a00, a01, a02, a03, a04) LOLUA_ARG_4(a00, a01, a02, a03), v04 +#define /***/ LOLUA_ARG_6(a00, a01, a02, a03, a04, a05) LOLUA_ARG_5(a00, a01, a02, a03, a04), v05 +#define /***/ LOLUA_ARG_7(a00, a01, a02, a03, a04, a05, a06) LOLUA_ARG_6(a00, a01, a02, a03, a04, a05), v06 +#define /***/ LOLUA_ARG_8(a00, a01, a02, a03, a04, a05, a06, a07) LOLUA_ARG_7(a00, a01, a02, a03, a04, a05, a06), v07 +#define /***/ LOLUA_ARG_9(a00, a01, a02, a03, a04, a05, a06, a07, a08) LOLUA_ARG_8(a00, a01, a02, a03, a04, a05, a06, a07), v08 +#define /**/ LOLUA_ARG_10(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09) LOLUA_ARG_9(a00, a01, a02, a03, a04, a05, a06, a07, a08), v09 +#define /**/ LOLUA_ARG_11(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09, a10) LOLUA_ARG_10(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09), v10 +#define /**/ LOLUA_ARG_12(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, a11) LOLUA_ARG_11(a00, a01, a02, a03, a04, a05, a06, a07, a08, a09), v11 +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +#define LOLUA_DECLARE_VOID_METHOD(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \ + static int LUA_FUNC_NAME(lua_State* l) \ + { \ + auto s = LuaStack::Begin(l); \ + auto o = s.INSTANCE_GET; \ + LOL_CALL(LOL_CAT(LOLUA_VAR_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__)) \ + o->INSTANCE_CALL(LOL_CALL(LOL_CAT(LOLUA_ARG_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__))); \ + return s.End(); \ + } + +//----------------------------------------------------------------------------- +#define LOLUA_DECLARE_RETURN_METHOD(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \ + static int LUA_FUNC_NAME(lua_State* l) \ + { \ + auto s = LuaStack::Begin(l); \ + auto o = s.INSTANCE_GET; \ + LOL_CALL(LOL_CAT(LOLUA_VAR_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__)) \ + s << o->INSTANCE_CALL(LOL_CALL(LOL_CAT(LOLUA_ARG_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__))); \ + return s.End(); \ + } + //----------------------------------------------------------------------------- #ifndef REGION_STACK_VAR From fab4610405ba6129528236a9bf8b47c764a6ad08 Mon Sep 17 00:00:00 2001 From: touky Date: Mon, 31 Oct 2016 20:31:48 -0400 Subject: [PATCH 5/5] lolua tweaks Added macros to help basic setup --- doc/tutorial/14_lol_lua.cpp | 6 +- src/easymesh/easymesh.h | 6 +- src/easymesh/easymeshlua.cpp | 5 +- src/easymesh/easymeshlua.h | 663 +++++------------------------------ src/lolua/baselua.h | 31 +- 5 files changed, 120 insertions(+), 591 deletions(-) diff --git a/doc/tutorial/14_lol_lua.cpp b/doc/tutorial/14_lol_lua.cpp index 4c4d3d39..412795e5 100644 --- a/doc/tutorial/14_lol_lua.cpp +++ b/doc/tutorial/14_lol_lua.cpp @@ -44,7 +44,7 @@ public: return (stack << i).End(); } - LOLUA_DECLARE_RETURN_METHOD(AddTenInstance, GetPtr(), AddTenMethod, Get(), Get(), Get()); + LOLUA_DECLARE_RETURN_METHOD_ARGS(AddTenInstance, GetPtr(), AddTenMethod, Get(), Get(), Get()); static int _AddTenInstance(lua_State* l) { auto stack = LuaStack::Begin(l); @@ -75,7 +75,7 @@ public: return (stack << i).End(); } - LOLUA_DECLARE_VOID_METHOD(SetX, GetPtr(), SetXMethod, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(SetX, GetPtr(), SetXMethod, Get()); static int _SetX(lua_State* l) { auto stack = LuaStack::Begin(l); @@ -198,7 +198,7 @@ public: testvalue_num: %.2f, testvalue_int: %i, testvalue_uint: %i, testvalue_str: %s.\n", testvalue_num, testvalue_int, testvalue_uint, testvalue_str.C()); msg::info("Lua Vars: \ - function_return: %s, loluademo_return: %i, loluademo_inst_return: %.f, loluademo_getx: %i, loluademo_inst->m_x: %i.\n", + function_return: %s, loluademo_return: %i, loluademo_inst_return: %.2f, loluademo_getx: %i, loluademo_inst->m_x: %i.\n", function_return.C(), loluademo_return, loluademo_inst_return, loluademo_getx, loluademo_inst->m_x); #define /***/ _LOLUA_ARG_1(a00) (float)a00 diff --git a/src/easymesh/easymesh.h b/src/easymesh/easymesh.h index 8f93def3..31198e37 100644 --- a/src/easymesh/easymesh.h +++ b/src/easymesh/easymesh.h @@ -392,7 +392,11 @@ public: - offset : useless */ void AppendCog(int nbsides, float h, float d10, float d20, float d11, - float d21, float d12, float d22, float sidemul=0.f, bool offset=false); + float d21, float d12, float d22, float sidemul = 0.f, bool offset = false); + void AppendCog(int nbsides, float h, vec2 d0, vec2 d1, vec2 d2, float sidemul = 0.f, bool offset = false) + { + AppendCog(nbsides, h, d0.x, d0.y, d1.x, d1.y, d2.x, d2.y, sidemul, offset); + } //------------------------------------------------------------------------- //TODO : Mesh Bone operations diff --git a/src/easymesh/easymeshlua.cpp b/src/easymesh/easymeshlua.cpp index 4edd141c..3c932b47 100644 --- a/src/easymesh/easymeshlua.cpp +++ b/src/easymesh/easymeshlua.cpp @@ -89,7 +89,8 @@ EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State* l, int arg_nb) //----------------------------------------------------------------------------- const LuaObjectLibrary* EasyMeshLuaObject::GetLib() { - typedef EasyMeshLuaObject EMLO; +#define EMLO EasyMeshLuaObject + static const LuaObjectLibrary lib = LuaObjectLibrary( "EasyMesh", //Statics @@ -181,6 +182,8 @@ const LuaObjectLibrary* EasyMeshLuaObject::GetLib() //Variables { { nullptr, nullptr, nullptr } }); return &lib; + +#undef EMLO } //----------------------------------------------------------------------------- diff --git a/src/easymesh/easymeshlua.h b/src/easymesh/easymeshlua.h index 5409fab3..6c786c55 100644 --- a/src/easymesh/easymeshlua.h +++ b/src/easymesh/easymeshlua.h @@ -29,589 +29,89 @@ public: static EasyMeshLuaObject* New(lua_State* l, int arg_nb); static const LuaObjectLibrary* GetLib(); - //------------------------------------------------------------------------- - static int AppendCylinder(lua_State* l) - { - 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); - auto smooth = s.Get(false); - auto close = s.Get(false); - m->m_instance.AppendCylinder(nsides, h, d1, d2, dualside, smooth, close); - return s.End(); - } - //LOLUA_DECLARE_VOID_METHOD(AppendSphere, GetPtr(), m_instance.AppendSphere, Get(), Get()); - static int AppendSphere(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto ndivisions = s.Get(); - auto d = s.Get(); - m->m_instance.AppendSphere(ndivisions, d); - return s.End(); - } +#define EMLO GetPtr() - static int AppendCapsule(lua_State* l) - { - 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 s.End(); - } - static int AppendTorus(lua_State* l) - { - 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 s.End(); - } - static int AppendBox(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto size = s.Get(); - auto chamf = s.Get(0.f); - auto smooth = s.Get(false); - m->m_instance.AppendBox(size, chamf, smooth); - return s.End(); - } - static int AppendStar(lua_State* l) - { - 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); - auto fade2 = s.Get(false); - m->m_instance.AppendStar(nbranches, d1, d2, fade, fade2); - return s.End(); - } - static int AppendExpandedStar(lua_State* l) - { - 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); - m->m_instance.AppendExpandedStar(nbranches, d1, d2, extrad); - return s.End(); - } - static int AppendDisc(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto nsides = s.Get(); - auto d = s.Get(); - auto fade = s.Get(false); - m->m_instance.AppendDisc(nsides, d, fade); - return s.End(); - } - static int AppendSimpleTriangle(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto d = s.Get(); - auto fade = s.Get(false); - m->m_instance.AppendSimpleTriangle(d, fade); - return s.End(); - } - static int AppendSimpleQuad(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto size = s.Get(); - auto fade = s.Get(false); - m->m_instance.AppendSimpleQuad(size, fade); - return s.End(); - } - static int AppendCog(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto nbsides = s.Get(); - auto h = s.Get(); - auto sidemul = s.Get(0.f); - auto d0 = s.Get(); - auto d1 = s.Get(); - auto d2 = s.Get(); - auto offset = s.Get(false); - 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) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto f = s.Get(); - m->m_instance.TranslateX(f); - return s.End(); - } - static int TranslateY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto f = s.Get(); - m->m_instance.TranslateY(f); - return s.End(); - } - static int TranslateZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto f = s.Get(); - m->m_instance.TranslateZ(f); - return s.End(); - } - static int Translate(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto v = s.Get(); - m->m_instance.Translate(v); - return s.End(); - } - //------------------------------------------------------------------------- - static int RotateX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto a = s.Get(); - m->m_instance.RotateX(a); - return s.End(); - } - static int RotateY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto a = s.Get(); - m->m_instance.RotateY(a); - return s.End(); - } - static int RotateZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto a = s.Get(); - m->m_instance.RotateZ(a); - return s.End(); - } - static int Rotate(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto a = s.Get(); - auto v = s.Get(); - m->m_instance.Rotate(a, v); - return s.End(); - } - //------------------------------------------------------------------------- - static int ScaleX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto x = s.Get(); - m->m_instance.ScaleX(x); - return s.End(); - } - static int ScaleY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto y = s.Get(); - m->m_instance.ScaleY(y); - return s.End(); - } - static int ScaleZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto z = s.Get(); - m->m_instance.ScaleZ(z); - return s.End(); - } - static int Scale(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto v = s.Get(); - m->m_instance.Scale(v); - return s.End(); - } - //------------------------------------------------------------------------- - static int RadialJitter(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto f = s.Get(); - m->m_instance.RadialJitter(f); - return s.End(); - } - //------------------------------------------------------------------------- - static int TaperX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto y = s.Get(); - auto z = s.Get(); - auto xoff = s.Get(0.f); - auto abs = s.Get(true); - m->m_instance.TaperX(y, z, xoff, abs); - return s.End(); - } - static int TaperY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto x = s.Get(); - auto z = s.Get(); - auto yoff = s.Get(0.f); - auto abs = s.Get(true); - m->m_instance.TaperY(x, z, yoff, abs); - return s.End(); - } - static int TaperZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto x = s.Get(); - auto y = s.Get(); - auto zoff = s.Get(0.f); - auto abs = s.Get(true); - m->m_instance.TaperZ(x, y, zoff, abs); - return s.End(); - } - //------------------------------------------------------------------------- - static int TwistX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.TwistX(t, toff); - return s.End(); - } - static int TwistY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.TwistY(t, toff); - return s.End(); - } - static int TwistZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.TwistZ(t, toff); - return s.End(); - } - //------------------------------------------------------------------------- - static int ShearX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto y = s.Get(); - auto z = s.Get(); - auto xoff = s.Get(0.f); - auto abs = s.Get(true); - m->m_instance.ShearX(y, z, xoff, abs); - return s.End(); - } - static int ShearY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto x = s.Get(); - auto z = s.Get(); - auto yoff = s.Get(0.f); - auto abs = s.Get(true); - m->m_instance.ShearY(x, z, yoff, abs); - return s.End(); - } - static int ShearZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto x = s.Get(); - auto y = s.Get(); - auto zoff = s.Get(0.f); - auto abs = s.Get(true); - m->m_instance.ShearZ(x, y, zoff, abs); - return s.End(); - } //------------------------------------------------------------------------- - static int StretchX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto y = s.Get(); - auto z = s.Get(); - auto xoff = s.Get(0.f); - m->m_instance.StretchX(y, z, xoff); - return s.End(); - } - static int StretchY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto x = s.Get(); - auto z = s.Get(); - auto yoff = s.Get(0.f); - m->m_instance.StretchY(x, z, yoff); - return s.End(); - } - static int StretchZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto x = s.Get(); - auto y = s.Get(); - auto zoff = s.Get(0.f); - m->m_instance.StretchZ(x, y, zoff); - return s.End(); - } - //------------------------------------------------------------------------- - static int BendXY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.BendXY(t, toff); - return s.End(); - } - static int BendXZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.BendXZ(t, toff); - return s.End(); - } - static int BendYX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.BendYX(t, toff); - return s.End(); - } - static int BendYZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.BendYZ(t, toff); - return s.End(); - } - static int BendZX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.BendZX(t, toff); - return s.End(); - } - static int BendZY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto t = s.Get(); - auto toff = s.Get(0.f); - m->m_instance.BendZY(t, toff); - return s.End(); - } - //------------------------------------------------------------------------- - static int MirrorX(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.MirrorX(); - return s.End(); - } - static int MirrorY(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.MirrorY(); - return s.End(); - } - static int MirrorZ(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.MirrorZ(); - return s.End(); - } - //------------------------------------------------------------------------- - static int LoopStart(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto loopnb = s.Get(); - m->m_instance.LoopStart(loopnb); - return s.End(); - } - static int LoopEnd(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.LoopEnd(); - return s.End(); - } - static int OpenBrace(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.OpenBrace(); - return s.End(); - } - static int CloseBrace(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.CloseBrace(); - return s.End(); - } - //------------------------------------------------------------------------- - static int ToggleScaleWinding(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.ToggleScaleWinding(); - return s.End(); - } - static int ToggleQuadWeighting(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.ToggleQuadWeighting(); - return s.End(); - } - static int TogglePostBuildNormal(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.TogglePostBuildNormal(); - return s.End(); - } - static int ToggleVerticeNoCleanup(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.ToggleVerticeNoCleanup(); - return s.End(); - } - //------------------------------------------------------------------------- - static int VerticesMerge(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.VerticesMerge(); - return s.End(); - } - static int VerticesSeparate(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.VerticesSeparate(); - return s.End(); - } - static int VerticesCleanup(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - m->m_instance.VerticesCleanup(); - return s.End(); - } - //------------------------------------------------------------------------- - static int Duplicate(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto ds = s.Get(vec3(1.f)); - m->m_instance.DupAndScale(ds, true); - return s.End(); - } - static int Smooth(lua_State* l) - { - 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 s.End(); - } - static int SplitTriangles(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto pass = s.Get(); - m->m_instance.SplitTriangles(pass); - return s.End(); - } - static int Chamfer(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto f = s.Get(); - m->m_instance.Chamfer(f); - return s.End(); - } - //------------------------------------------------------------------------- - static int SetCurColor(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto c = s.Get(); - m->m_instance.SetCurColor(c); - return s.End(); - } - static int SetCurColorA(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto c = s.Get(); - m->m_instance.SetCurColorA(c); - return s.End(); - } - static int SetCurColorB(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto c = s.Get(); - m->m_instance.SetCurColorB(c); - return s.End(); - } - static int SetVertColor(lua_State* l) - { - auto s = LuaStack::Begin(l); - auto m = s.GetPtr(); - auto c = s.Get(); - m->m_instance.SetVertColor(c); - return s.End(); - } + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendCylinder, EMLO, m_instance.AppendCylinder, Get(), Get(), Get(), Get(), Get(false), Get(false), Get(false)); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendSphere, EMLO, m_instance.AppendSphere, Get(), Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendCapsule, EMLO, m_instance.AppendCapsule, Get(), Get(), Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendTorus, EMLO, m_instance.AppendTorus, Get(), Get(), Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendBox, EMLO, m_instance.AppendBox, Get(), Get(0.f), Get(false)); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendStar, EMLO, m_instance.AppendStar, Get(), Get(), Get(), Get(false), Get(false)); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendExpandedStar, EMLO, m_instance.AppendExpandedStar, Get(), Get(), Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendDisc, EMLO, m_instance.AppendDisc, Get(), Get(), Get(false)); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendSimpleTriangle, EMLO, m_instance.AppendSimpleTriangle, Get(), Get(false)); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendSimpleQuad, EMLO, m_instance.AppendSimpleQuad, Get(), Get(false)); + LOLUA_DECLARE_VOID_METHOD_ARGS(AppendCog, EMLO, m_instance.AppendCog, Get(), Get(), Get(), Get(), Get(), Get(0.f), Get(false)); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(TranslateX, EMLO, m_instance.TranslateX, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(TranslateY, EMLO, m_instance.TranslateY, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(TranslateZ, EMLO, m_instance.TranslateZ, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(Translate, EMLO, m_instance.Translate, Get()); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(RotateX, EMLO, m_instance.RotateX, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(RotateY, EMLO, m_instance.RotateY, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(RotateZ, EMLO, m_instance.RotateZ, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(Rotate, EMLO, m_instance.Rotate, Get(), Get()); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(ScaleX, EMLO, m_instance.ScaleX, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(ScaleY, EMLO, m_instance.ScaleY, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(ScaleZ, EMLO, m_instance.ScaleZ, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(Scale, EMLO, m_instance.Scale, Get()); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(RadialJitter, EMLO, m_instance.RadialJitter, Get()); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(TaperX, EMLO, m_instance.TaperX, Get(), Get(), Get(0.f), Get(true)); + LOLUA_DECLARE_VOID_METHOD_ARGS(TaperY, EMLO, m_instance.TaperY, Get(), Get(), Get(0.f), Get(true)); + LOLUA_DECLARE_VOID_METHOD_ARGS(TaperZ, EMLO, m_instance.TaperZ, Get(), Get(), Get(0.f), Get(true)); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(TwistX, EMLO, m_instance.TwistX, Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(TwistY, EMLO, m_instance.TwistY, Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(TwistZ, EMLO, m_instance.TwistZ, Get(), Get(0.f)); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(ShearX, EMLO, m_instance.ShearX, Get(), Get(), Get(0.f), Get(true)); + LOLUA_DECLARE_VOID_METHOD_ARGS(ShearY, EMLO, m_instance.ShearY, Get(), Get(), Get(0.f), Get(true)); + LOLUA_DECLARE_VOID_METHOD_ARGS(ShearZ, EMLO, m_instance.ShearZ, Get(), Get(), Get(0.f), Get(true)); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(StretchX, EMLO, m_instance.StretchX, Get(), Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(StretchY, EMLO, m_instance.StretchY, Get(), Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(StretchZ, EMLO, m_instance.StretchZ, Get(), Get(), Get(0.f)); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(BendXY, EMLO, m_instance.BendXY, Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(BendXZ, EMLO, m_instance.BendXZ, Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(BendYX, EMLO, m_instance.BendYX, Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(BendYZ, EMLO, m_instance.BendYZ, Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(BendZX, EMLO, m_instance.BendZX, Get(), Get(0.f)); + LOLUA_DECLARE_VOID_METHOD_ARGS(BendZY, EMLO, m_instance.BendZY, Get(), Get(0.f)); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_VOID(MirrorX, EMLO, m_instance.MirrorX); + LOLUA_DECLARE_VOID_METHOD_VOID(MirrorY, EMLO, m_instance.MirrorY); + LOLUA_DECLARE_VOID_METHOD_VOID(MirrorZ, EMLO, m_instance.MirrorZ); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(LoopStart, EMLO, m_instance.LoopStart, Get()); + LOLUA_DECLARE_VOID_METHOD_VOID(LoopEnd, EMLO, m_instance.LoopEnd); + LOLUA_DECLARE_VOID_METHOD_VOID(OpenBrace, EMLO, m_instance.OpenBrace, Get()); + LOLUA_DECLARE_VOID_METHOD_VOID(CloseBrace, EMLO, m_instance.CloseBrace, Get()); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_VOID(ToggleScaleWinding, EMLO, m_instance.ToggleScaleWinding); + LOLUA_DECLARE_VOID_METHOD_VOID(ToggleQuadWeighting, EMLO, m_instance.ToggleQuadWeighting); + LOLUA_DECLARE_VOID_METHOD_VOID(TogglePostBuildNormal, EMLO, m_instance.TogglePostBuildNormal); + LOLUA_DECLARE_VOID_METHOD_VOID(ToggleVerticeNoCleanup, EMLO, m_instance.ToggleVerticeNoCleanup); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_VOID(VerticesMerge, EMLO, m_instance.VerticesMerge); + LOLUA_DECLARE_VOID_METHOD_VOID(VerticesSeparate, EMLO, m_instance.VerticesSeparate); + LOLUA_DECLARE_VOID_METHOD_VOID(VerticesCleanup, EMLO, m_instance.VerticesCleanup); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(Duplicate, EMLO, m_instance.DupAndScale, Get(vec3(1.f)), Get(true)); + LOLUA_DECLARE_VOID_METHOD_ARGS(Smooth, EMLO, m_instance.SmoothMesh, Get(), Get(), Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(SplitTriangles, EMLO, m_instance.SplitTriangles, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(Chamfer, EMLO, m_instance.Chamfer, Get()); + //------------------------------------------------------------------------- + LOLUA_DECLARE_VOID_METHOD_ARGS(SetCurColor, EMLO, m_instance.SetCurColor, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(SetCurColorA, EMLO, m_instance.SetCurColorA, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(SetCurColorB, EMLO, m_instance.SetCurColorB, Get()); + LOLUA_DECLARE_VOID_METHOD_ARGS(SetVertColor, EMLO, m_instance.SetVertColor, Get()); + /* (csgu|csgunion) { return token::T_CSGUNION; } (csgs|CsgSub) { return token::T_CSGSUBSTRACT; } @@ -620,6 +120,7 @@ public: (csgx|csgxor) { return token::T_CSGXOR; } */ + #undef EMLO }; //----------------------------------------------------------------------------- diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index bf5d25c6..ca30fa35 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -437,18 +437,39 @@ private: //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -#define LOLUA_DECLARE_VOID_METHOD(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \ +#define LOLUA_DECLARE_BEGIN(LUA_FUNC_NAME, INSTANCE_GET) \ static int LUA_FUNC_NAME(lua_State* l) \ { \ auto s = LuaStack::Begin(l); \ - auto o = s.INSTANCE_GET; \ - LOL_CALL(LOL_CAT(LOLUA_VAR_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__)) \ - o->INSTANCE_CALL(LOL_CALL(LOL_CAT(LOLUA_ARG_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__))); \ + auto o = s.INSTANCE_GET; + +#define LOLUA_DECLARE_VARS(...) \ + LOL_CALL(LOL_CAT(LOLUA_VAR_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__)); + +#define LOLUA_DECLARE_CALL(INSTANCE_CALL, ...) \ + o->INSTANCE_CALL(LOL_CALL(LOL_CAT(LOLUA_ARG_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__))); + +#define LOLUA_DECLARE_CALL_VOID(INSTANCE_CALL) \ + o->INSTANCE_CALL(); + +#define LOLUA_DECLARE_END \ return s.End(); \ } //----------------------------------------------------------------------------- -#define LOLUA_DECLARE_RETURN_METHOD(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \ +#define LOLUA_DECLARE_VOID_METHOD_VOID(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \ + LOLUA_DECLARE_BEGIN(LUA_FUNC_NAME, INSTANCE_GET); \ + LOLUA_DECLARE_CALL_VOID(INSTANCE_CALL) \ + LOLUA_DECLARE_END + +#define LOLUA_DECLARE_VOID_METHOD_ARGS(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \ + LOLUA_DECLARE_BEGIN(LUA_FUNC_NAME, INSTANCE_GET); \ + LOLUA_DECLARE_VARS(__VA_ARGS__) \ + LOLUA_DECLARE_CALL(INSTANCE_CALL, __VA_ARGS__) \ + LOLUA_DECLARE_END + +//----------------------------------------------------------------------------- +#define LOLUA_DECLARE_RETURN_METHOD_ARGS(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \ static int LUA_FUNC_NAME(lua_State* l) \ { \ auto s = LuaStack::Begin(l); \