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