From 1ab2501db0f9e14f138292880e37120e7a6184de Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 16 Mar 2019 13:03:50 +0800 Subject: *luax --- Bin/win64/LuaxTest.exe | Bin 541184 -> 544768 bytes Build/Asura.Editor/Asura.Editor.vcxproj | 41 +++--- Build/Asura.Editor/Asura.Editor.vcxproj.filters | 107 +++++++------- Build/Asura.Engine/Asura.Engine.vcxproj | 18 +-- Build/Asura.Engine/Asura.Engine.vcxproj.filters | 54 +++---- Build/Asura.sln | 11 ++ Build/Samples/AsuraTest/AsuraTest.vcxproj | 122 ++++++++++++++++ Build/Samples/AsuraTest/AsuraTest.vcxproj.filters | 2 + Build/Samples/AsuraTest/AsuraTest.vcxproj.user | 4 + Build/Samples/LuaxTest/LuaxTest.vcxproj | 3 + Build/Samples/LuaxTest/LuaxTest.vcxproj.filters | 3 + Source/3rdParty/Lua51/loadlib.c | 2 +- Source/3rdParty/Luax/luax.h | 1 + Source/3rdParty/Luax/luax_class.hpp | 34 +++-- Source/3rdParty/Luax/luax_class.inl | 161 +++++++++++++-------- Source/3rdParty/Luax/luax_context.cpp | 19 +-- Source/3rdParty/Luax/luax_context.h | 8 +- Source/3rdParty/Luax/luax_enum.cpp | 8 +- Source/3rdParty/Luax/luax_memberref.h | 2 +- Source/3rdParty/Luax/luax_ref.h | 4 +- Source/3rdParty/Luax/luax_runtime.cpp | 20 +-- Source/3rdParty/Luax/luax_runtime.h | 4 +- Source/3rdParty/Luax/luax_state.cpp | 87 ++++++++--- Source/3rdParty/Luax/luax_state.h | 39 ++++- Source/3rdParty/Luax/luax_state.inl | 56 +++---- Source/Asura.Editor/source/events/events.h | 24 +++ Source/Asura.Engine/Graphics/Image.h | 22 ++- Source/Asura.Engine/Graphics/Shader.h | 6 + .../graphics/binding/canvas.binding.cpp | 0 Source/Asura.Engine/graphics/binding/canvas.cpp | 0 .../graphics/binding/color.binding.cpp | 0 Source/Asura.Engine/graphics/binding/color.cpp | 0 .../graphics/binding/image.binding.cpp | 0 Source/Asura.Engine/graphics/binding/image.cpp | 0 .../graphics/binding/image_data.binding.cpp | 35 +++++ .../Asura.Engine/graphics/binding/image_data.cpp | 0 .../graphics/binding/mesh2d.binding.cpp | 0 Source/Asura.Engine/graphics/binding/mesh2d.cpp | 0 .../graphics/binding/mesh2d_data.binding.cpp | 0 .../Asura.Engine/graphics/binding/mesh2d_data.cpp | 0 .../graphics/binding/shader.binding.cpp | 119 +++++++++++++++ Source/Asura.Engine/graphics/binding/shader.cpp | 119 --------------- .../graphics/binding/sprite_batch.binding.cpp | 0 .../Asura.Engine/graphics/binding/sprite_batch.cpp | 0 .../graphics/binding/window.binding.cpp | 11 ++ Source/Asura.Engine/graphics/binding/window.cpp | 11 -- Source/Asura.Engine/graphics/image.h | 22 ++- Source/Asura.Engine/graphics/shader.h | 6 + Source/Samples/LuaxTest/main.cpp | 64 +------- Source/Samples/LuaxTest/script.lua | 63 ++++++++ 50 files changed, 825 insertions(+), 487 deletions(-) create mode 100644 Build/Samples/AsuraTest/AsuraTest.vcxproj create mode 100644 Build/Samples/AsuraTest/AsuraTest.vcxproj.filters create mode 100644 Build/Samples/AsuraTest/AsuraTest.vcxproj.user create mode 100644 Source/Asura.Editor/source/events/events.h create mode 100644 Source/Asura.Engine/graphics/binding/canvas.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/canvas.cpp create mode 100644 Source/Asura.Engine/graphics/binding/color.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/color.cpp create mode 100644 Source/Asura.Engine/graphics/binding/image.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/image.cpp create mode 100644 Source/Asura.Engine/graphics/binding/image_data.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/image_data.cpp create mode 100644 Source/Asura.Engine/graphics/binding/mesh2d.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/mesh2d.cpp create mode 100644 Source/Asura.Engine/graphics/binding/mesh2d_data.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/mesh2d_data.cpp create mode 100644 Source/Asura.Engine/graphics/binding/shader.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/shader.cpp create mode 100644 Source/Asura.Engine/graphics/binding/sprite_batch.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/sprite_batch.cpp create mode 100644 Source/Asura.Engine/graphics/binding/window.binding.cpp delete mode 100644 Source/Asura.Engine/graphics/binding/window.cpp create mode 100644 Source/Samples/LuaxTest/script.lua diff --git a/Bin/win64/LuaxTest.exe b/Bin/win64/LuaxTest.exe index a27e619..ef7c0b0 100644 Binary files a/Bin/win64/LuaxTest.exe and b/Bin/win64/LuaxTest.exe differ diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj b/Build/Asura.Editor/Asura.Editor.vcxproj index 1f4991e..be57c07 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj +++ b/Build/Asura.Editor/Asura.Editor.vcxproj @@ -131,28 +131,29 @@ - - - - - - - - - + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj.filters b/Build/Asura.Editor/Asura.Editor.vcxproj.filters index 8f54d96..393e51b 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/Build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -1,90 +1,93 @@  - - {99018b81-eb4c-423f-87ac-fe6ef75debb3} - - + {df219ecb-2a99-443c-9313-5a6dc80a3255} - - {09171ec2-27ed-4124-9ca0-40c867d685b0} + + {6ac40386-308a-4f94-a870-5aed5d6f27e3} + + + {99018b81-eb4c-423f-87ac-fe6ef75debb3} - + {90dd768b-56f8-43b2-adef-c92ebcb635f0} - - {b499aa99-d018-40dd-9c3c-d60d5f9b6079} + + {09171ec2-27ed-4124-9ca0-40c867d685b0} - - {6ac40386-308a-4f94-a870-5aed5d6f27e3} + + {b499aa99-d018-40dd-9c3c-d60d5f9b6079} - - Source\Widgets + + source\events + + + source\widgets - - Source\Window + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\window - Source + source - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets - - Source\Widgets + + source\widgets \ No newline at end of file diff --git a/Build/Asura.Engine/Asura.Engine.vcxproj b/Build/Asura.Engine/Asura.Engine.vcxproj index 93f627d..37fa479 100644 --- a/Build/Asura.Engine/Asura.Engine.vcxproj +++ b/Build/Asura.Engine/Asura.Engine.vcxproj @@ -198,15 +198,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/Build/Asura.Engine/Asura.Engine.vcxproj.filters b/Build/Asura.Engine/Asura.Engine.vcxproj.filters index 8ca292f..ccf7fed 100644 --- a/Build/Asura.Engine/Asura.Engine.vcxproj.filters +++ b/Build/Asura.Engine/Asura.Engine.vcxproj.filters @@ -261,33 +261,6 @@ graphics - - graphics\binding - - - graphics\binding - - - graphics\binding - - - graphics\binding - - - graphics\binding - - - graphics\binding - - - graphics\binding - - - graphics\binding - - - graphics\binding - input @@ -335,6 +308,33 @@ + + graphics\binding + + + graphics\binding + + + graphics\binding + + + graphics\binding + + + graphics\binding + + + graphics\binding + + + graphics\binding + + + graphics\binding + + + graphics\binding + diff --git a/Build/Asura.sln b/Build/Asura.sln index 0b0c07e..a02fd7d 100644 --- a/Build/Asura.sln +++ b/Build/Asura.sln @@ -61,6 +61,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "physfs", "3rdParty\physfs\p EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LuaxTest", "Samples\LuaxTest\LuaxTest.vcxproj", "{87A4F855-66F2-4DBF-B86C-416E88DAC88A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AsuraTest", "Samples\AsuraTest\AsuraTest.vcxproj", "{D1039E03-DF4E-4CA2-8829-AE841B616E8E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -285,6 +287,14 @@ Global {87A4F855-66F2-4DBF-B86C-416E88DAC88A}.Release|x64.Build.0 = Release|x64 {87A4F855-66F2-4DBF-B86C-416E88DAC88A}.Release|x86.ActiveCfg = Release|Win32 {87A4F855-66F2-4DBF-B86C-416E88DAC88A}.Release|x86.Build.0 = Release|Win32 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Debug|x64.ActiveCfg = Debug|x64 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Debug|x64.Build.0 = Debug|x64 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Debug|x86.ActiveCfg = Debug|Win32 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Debug|x86.Build.0 = Debug|Win32 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Release|x64.ActiveCfg = Release|x64 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Release|x64.Build.0 = Release|x64 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Release|x86.ActiveCfg = Release|Win32 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -309,6 +319,7 @@ Global {294889EA-93DE-4580-BF9D-87F605B229AA} = {64D4E4B2-4A60-46F4-A500-370EFED4524F} {AEE37589-DE0D-4139-8BDB-8179FDEFB835} = {64D4E4B2-4A60-46F4-A500-370EFED4524F} {87A4F855-66F2-4DBF-B86C-416E88DAC88A} = {E068D138-C824-4365-B5A3-27C65E8FD0B5} + {D1039E03-DF4E-4CA2-8829-AE841B616E8E} = {E068D138-C824-4365-B5A3-27C65E8FD0B5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {331032D8-F7CC-43E3-A03B-67108767F96B} diff --git a/Build/Samples/AsuraTest/AsuraTest.vcxproj b/Build/Samples/AsuraTest/AsuraTest.vcxproj new file mode 100644 index 0000000..105b5e4 --- /dev/null +++ b/Build/Samples/AsuraTest/AsuraTest.vcxproj @@ -0,0 +1,122 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {D1039E03-DF4E-4CA2-8829-AE841B616E8E} + AsuraTest + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + \ No newline at end of file diff --git a/Build/Samples/AsuraTest/AsuraTest.vcxproj.filters b/Build/Samples/AsuraTest/AsuraTest.vcxproj.filters new file mode 100644 index 0000000..9cd8510 --- /dev/null +++ b/Build/Samples/AsuraTest/AsuraTest.vcxproj.filters @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Build/Samples/AsuraTest/AsuraTest.vcxproj.user b/Build/Samples/AsuraTest/AsuraTest.vcxproj.user new file mode 100644 index 0000000..be25078 --- /dev/null +++ b/Build/Samples/AsuraTest/AsuraTest.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Build/Samples/LuaxTest/LuaxTest.vcxproj b/Build/Samples/LuaxTest/LuaxTest.vcxproj index 0ab395d..694fb2d 100644 --- a/Build/Samples/LuaxTest/LuaxTest.vcxproj +++ b/Build/Samples/LuaxTest/LuaxTest.vcxproj @@ -134,6 +134,9 @@ + + + diff --git a/Build/Samples/LuaxTest/LuaxTest.vcxproj.filters b/Build/Samples/LuaxTest/LuaxTest.vcxproj.filters index 0dc8d61..a3134a4 100644 --- a/Build/Samples/LuaxTest/LuaxTest.vcxproj.filters +++ b/Build/Samples/LuaxTest/LuaxTest.vcxproj.filters @@ -6,4 +6,7 @@ + + + \ No newline at end of file diff --git a/Source/3rdParty/Lua51/loadlib.c b/Source/3rdParty/Lua51/loadlib.c index 6158c53..9455c53 100644 --- a/Source/3rdParty/Lua51/loadlib.c +++ b/Source/3rdParty/Lua51/loadlib.c @@ -654,7 +654,7 @@ LUALIB_API int luaopen_package (lua_State *L) { lua_setfield(L, -2, "config"); /* set field `loaded' */ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); - lua_setfield(L, -2, "loaded"); + lua_setfield(L, -2, "loaded"); // LUA_REGISTRYINDEX["_LOADED"]ÉèÖÃΪpackage.loaded\LUA_ENVIRONINDEX["loaded"] /* set field `preload' */ lua_newtable(L); lua_setfield(L, -2, "preload"); diff --git a/Source/3rdParty/Luax/luax.h b/Source/3rdParty/Luax/luax.h index ed67bdc..9a6b0b9 100644 --- a/Source/3rdParty/Luax/luax.h +++ b/Source/3rdParty/Luax/luax.h @@ -6,6 +6,7 @@ #include "luax_namespace.h" #include "luax_ref.h" #include "luax_reftable.h" +#include "luax_memberref.h" #include "luax_enum.h" #include "luax_class.hpp" #include "luax_class.inl" diff --git a/Source/3rdParty/Luax/luax_class.hpp b/Source/3rdParty/Luax/luax_class.hpp index 0d3dc5b..a76d501 100644 --- a/Source/3rdParty/Luax/luax_class.hpp +++ b/Source/3rdParty/Luax/luax_class.hpp @@ -53,7 +53,9 @@ namespace Luax /// /// ½«userdata pushµ½Õ»¶¥£¬Èç¹ûûÓгõʼ»¯mUserdata£¬³õʼ»¯ÉèÖúÃÔª±í²¢°Ñ³õʼ»¯ºÃµÄuserdataÁôÔÚÕ»¶¥¡£²¢Ìí¼ÓÒ»¸öÒýÓᣠ/// - bool PushLuaUserdata(LuaxState& state); + bool PushLuaxUserdata(LuaxState& state); + bool PushLuaxMemberTable(LuaxState& state); + bool PushLuaxRefTable(LuaxState& state); private: @@ -62,15 +64,15 @@ namespace Luax static void RegisterLuaxClass(LuaxState& state); static void RegisterLuaxFactoryClass(LuaxState& state); static void RegisterLuaxSingletonClass(LuaxState& state); - static void RegisterLuaxInterface(LuaxState& state); - static void SetInterfaceTableRef(LuaxState& state, int idx); - static void SetClassTableRef(LuaxState& state, int idx); + static void RegisterLuaxInterface(LuaxState& state); - static void PushInterfaceTable(LuaxState& state); - static void PushClassTable(LuaxState& state); - static void PushRefTable(LuaxState& state); + static void SetLuaxInterfaceTableRef(LuaxState& state, int idx); + static void SetLuaxClassTableRef(LuaxState& state, int idx); + static void PushLuaxInterfaceTable(LuaxState& state); + static void PushLuaxClassTable(LuaxState& state); + /// /// ÆÁ±ÎÈ¡µØÖ·ÔËËã·û£¬Èç¹ûÐèÒªµØÖ·£¬Ö»ÄÜͨ¹ýÔÚ¶ÑÉÏ´´½¨ÊµÀýµÃµ½¡£ÔÚÕ»ÉϺ;²Ì¬ÇøµÄ±äÁ¿²»ÄÜÈ¡µØÖ·¡£±£Ö¤ÒýÓüÆÊýµÄ׼ȷ¡£Èç /// ¹ûÐèÒª´©ÒýÓã¬Ê¹ÓÃÒýÓô«µÝ¶ø²»ÊÇ´«µÝµØÖ·¡£ @@ -87,12 +89,16 @@ namespace Luax /// /// ËùÓÐLuaxClassÀàÐ͵ÄʵÀý¹²ÏíµÄÄÚÈÝ /// - static LuaxStrongRef mInterfaceTable; // interface table - static LuaxStrongRef mClassTable; // class table - static LuaxStrongRef mRefTable; // µ¥Àý - + static LuaxStrongRef mClassTable; // class table£¬¹¤³§ºÍµ¥Àý¶¼ÓÐ + static LuaxStrongRef mInterfaceTable; // Èç¹ûÀàÊǹ¤³§£¬interface tableÓÃÀ´±£´æÀàʵÀý»¯µÄ¶ÔÏóµÄ¹²Óз½·¨ + static LuaxStrongRef mSingletonRefTable; // Èç¹ûÀàÊǵ¥Àý£¬Õâ¸öÓÃÀ´±£´æsingletonµÄ³ÉÔ±£¬ÒÔ±£Ö¤²»»á±»»ØÊÕÀàËÆÆÕͨÀàµÄ + // ref table¡£µ¥ÀýµÄ³ÉÔ±ÊÇÈ«ÉúÃüÖÜÆÚµÄ£¬ËùÒÔÖ±½ÓÔÚ_LUAX_STRONGREF_TABLE + /// - /// ͨ¹ýuserdata¿ÉÒÔÄõ½ref table\member table\interface table + /// ͨ¹ýuserdata¿ÉÒÔÄõ½: + /// 1: ref table + /// 2: member table + /// 3: interface table /// LuaxWeakRef mUserdata; @@ -113,13 +119,13 @@ namespace Luax LUAX_DECL_METHOD( l_GetClassName ); LUAX_DECL_METHOD( l_GetInterfaceTable ); - LUAX_DECL_METHOD( l_ToString ); + LUAX_DECL_METHOD( l___tostring ); //------------------------------------------------------------------------------------------------------------ // ¹¤³§ÀàÏà¹Ø LUAX_DECL_METHOD( l_ExtendFactory ); - LUAX_DECL_METHOD( l_GC ); + LUAX_DECL_METHOD( l___gc ); //------------------------------------------------------------------------------------------------------------ // µ¥ÀýÀàÏà¹Ø diff --git a/Source/3rdParty/Luax/luax_class.inl b/Source/3rdParty/Luax/luax_class.inl index 2d28d68..8cf0f55 100644 --- a/Source/3rdParty/Luax/luax_class.inl +++ b/Source/3rdParty/Luax/luax_class.inl @@ -56,8 +56,8 @@ namespace Luax void LuaxClass::RegisterLuaxInterface(LuaxState& state) { luaL_Reg regTable[] = { - { "__gc", l_GC }, - { NULL, NULL } + { "__gc", l___gc }, + { NULL, NULL } }; state.RegisterMethods(regTable); @@ -78,7 +78,7 @@ namespace Luax } template - void LuaxClass::PushInterfaceTable(LuaxState& state) + void LuaxClass::PushLuaxInterfaceTable(LuaxState& state) { assert(mInterfaceTable); @@ -86,7 +86,7 @@ namespace Luax } template - void LuaxClass::PushClassTable(LuaxState& state) + void LuaxClass::PushLuaxClassTable(LuaxState& state) { assert(mClassTable); @@ -94,21 +94,13 @@ namespace Luax } template - void LuaxClass::PushRefTable(LuaxState& state) - { - assert(mRefTable); - - mRefTable.Push(state); - } - - template - void LuaxClass::SetInterfaceTableRef(LuaxState& state, int idx) + void LuaxClass::SetLuaxInterfaceTableRef(LuaxState& state, int idx) { mInterfaceTable.SetRef(state, idx); } template - void LuaxClass::SetClassTableRef(LuaxState& state, int idx) + void LuaxClass::SetLuaxClassTableRef(LuaxState& state, int idx) { mClassTable.SetRef(state, idx); } @@ -143,8 +135,9 @@ namespace Luax } template - bool LuaxClass::PushLuaUserdata(LuaxState& state) + bool LuaxClass::PushLuaxUserdata(LuaxState& state) { + assert(!T::IsLuaxClassSingleton()); if (!mUserdata) { BindToLua(state); @@ -153,59 +146,103 @@ namespace Luax return mUserdata.PushRef(state); } + template + bool LuaxClass::PushLuaxMemberTable(LuaxState& state) + { + int top = state.GetTop(); + if (this->PushLuaxUserdata(state)) + { + if (lua_getmetatable(state, -1)) // ref table + { + lua_replace(state, -2); + if (lua_getmetatable(state, -1)) // member table + { + lua_replace(state, -2); + return true; + } + } + } + state.SetTop(top); + lua_pushnil(state); + return false; + } + + template + bool LuaxClass::PushLuaxRefTable(LuaxState& state) + { + // Singleton + if (T::IsLuaxClassSingleton()) + { + if (!this->mSingletonRefTable) { + lua_newtable(state); + this->mSingletonRefTable.SetRef(state, -1); // strong ref to member table won't be garbage collected + } + else { + this->mSingletonRefTable.PushRef(state); + } + return true; + } + // Factory + else + { + if (this->PushLuaxUserdata(state)) + { + if (lua_getmetatable(state, -1)) + { + lua_replace(state, -2); + return true; + } + } + } + return false; + } + template void LuaxClass::BindToLua(LuaxState& state) { + // µ¥Àý²»Äܰó¶¨userdata + assert(!T::IsLuaxClassSingleton()); assert(!mUserdata); // ´´½¨userdata²¢ÁôÔÚÕ»¶¥ state.PushPtrUserData(this); - // ¹¤³§ - if (!T::IsLuaxClassSingleton()) - { - lua_newtable(state); // ref table - lua_newtable(state); // member table - LuaxClass::PushInterfaceTable(state); // interface table - - // stack: - // -1: interface table - // -2: member table - // -3: ref table - // -4: userdata - - int top = state.GetTop(); - int memberTable = top - 1; - int refTable = top - 2; - - // ref table ×¢²á __gcºÍ__tostring - lua_pushcfunction(state, LuaxClass::l_GC); - lua_setfield(state, refTable, "__gc"); - - lua_pushcfunction(state, LuaxClass::l_ToString); - lua_setfield(state, refTable, "__tostring"); - - // member table ÉèΪ ref table µÄ __index ºÍ __newindex - lua_pushvalue(state, memberTable); - lua_setfield(state, refTable, "__index"); - - lua_pushvalue(state, memberTable); - lua_setfield(state, refTable, "__newindex"); - - // ÉèÖÃÔª±í - lua_setmetatable(state, -2); // interface is meta of member - lua_setmetatable(state, -2); // member is meta of ref - lua_setmetatable(state, -2); // ref is meta of userdata - } + lua_newtable(state); // ref table£¬ÎÞ·¨ÔÚlua´¦·ÃÎÊ£¬ÓÃÀ´¹ÜÀíC¶ÔÏóµÄÉúÃüÖÜÆÚ + lua_newtable(state); // member table£¬luaÖд´½¨µÄ¶ÔÏó³ÉÔ±¶¼±£´æÔÚÕâÀï + PushLuaxInterfaceTable(state); // interface table£¬Èç¹ûmember tableÀïûÓÐÕâ¸ö³ÉÔ±£¬ÔÚinterface tableÀïÕÒ¡£ - // ÉèÖÃÒ»¸öuserdataµÄÈõÒýÓ㬷½±ãͨ¹ýnativeÖ¸Õë·µ»Ølua¶ÔÏó - mUserdata.SetRef(state, -1); - assert(mUserdata); + // stack: + // -1: interface table + // -2: member table + // -3: ref table + // -4: userdata - if (T::IsLuaxClassSingleton()) - { + int top = state.GetTop(); + int memberTable = top - 1; + int refTable = top - 2; - } + // ref table ×¢²á __gcºÍ__tostring + lua_pushcfunction(state, l___gc); + lua_setfield(state, refTable, "__gc"); + + lua_pushcfunction(state, l___tostring); + lua_setfield(state, refTable, "__tostring"); + + // member table ÉèΪ ref table µÄ __index ºÍ __newindex + lua_pushvalue(state, memberTable); + lua_setfield(state, refTable, "__index"); + + lua_pushvalue(state, memberTable); + lua_setfield(state, refTable, "__newindex"); + + // ÉèÖÃÔª±í + lua_setmetatable(state, -2); // interface is meta of member + lua_setmetatable(state, -2); // member is meta of ref + lua_setmetatable(state, -2); // ref is meta of userdata + + // ÉèÖÃÒ»¸öuserdataµÄÈõÒýÓ㬷½±ãͨ¹ýPushLuaUserdata·½·¨·µ»Ølua¶ÔÏó + mUserdata.SetRef(state, -1); + assert(mUserdata); } //-------------------------------------------------------------------------------------------------------------- @@ -214,7 +251,7 @@ namespace Luax /// Êͷʤ³§´´½¨µÄʵÀý /// template - int LuaxClass::l_GC(lua_State* L) + int LuaxClass::l___gc(lua_State* L) { LUAX_SETUP(L, "U"); @@ -222,7 +259,7 @@ namespace Luax } template - int LuaxClass::l_ToString(lua_State* L) + int LuaxClass::l___tostring(lua_State* L) { return 0; } @@ -242,8 +279,8 @@ namespace Luax return 0; } - template LuaxStrongRef LuaxClass::mInterfaceTable; // interface table - template LuaxStrongRef LuaxClass::mClassTable; // class table - template LuaxStrongRef LuaxClass::mRefTable; // µ¥Àý + template LuaxStrongRef LuaxClass::mInterfaceTable; // interface table + template LuaxStrongRef LuaxClass::mClassTable; // class table + template LuaxStrongRef LuaxClass::mSingletonRefTable; // µ¥Àý } \ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_context.cpp b/Source/3rdParty/Luax/luax_context.cpp index c0fb2f5..d41c24f 100644 --- a/Source/3rdParty/Luax/luax_context.cpp +++ b/Source/3rdParty/Luax/luax_context.cpp @@ -3,34 +3,27 @@ namespace Luax { - // Èç¹ûµ÷ÓÃÁ˴˺¯Êý£¬±¨´í¡£ - int l_Errfunc(lua_State* L) - { - cc8* err = lua_tostring(L, lua_upvalueindex(1)); - return luaL_error(L, err); - } - - Context::Context(lua_State* L) + LuaxContext::LuaxContext(lua_State* L) : state(L) { assert(state); } - Context::~Context() + LuaxContext::~LuaxContext() { } // ³õʼ»¯context - void Context::Setup() + void LuaxContext::Setup() { SetupRefTables(); } - void Context::SetupRefTables() + void LuaxContext::SetupRefTables() { // strong refºÍ weak ref - strongRefTable.Init(state, "LUAX_STRONGREF_TABLE"); - weakRefTable.Init(state, "LUAX_WEAKREF_TABLE", "v"); + strongRefTable.Init(state, "_LUAX_STRONGREF_TABLE"); + weakRefTable.Init(state, "_LUAX_WEAKREF_TABLE", "v"); } } \ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_context.h b/Source/3rdParty/Luax/luax_context.h index 5746cf1..01c5937 100644 --- a/Source/3rdParty/Luax/luax_context.h +++ b/Source/3rdParty/Luax/luax_context.h @@ -11,11 +11,11 @@ namespace Luax /// /// µ¥¸ölua_stateÏà¹ØµÄcontext¡£ÊÇһϵÁдúÀíµÄ¼¯ºÏ£¬¿½±´Ò²Ã»¹ØÏµ£¬Ö÷ÒªÊÇΪÁ˽ÚÔ¼ÄÚ´æ¡£ /// - class Context + class LuaxContext { public: - Context(lua_State* L); - ~Context(); + LuaxContext(lua_State* L); + ~LuaxContext(); void Setup(); @@ -23,7 +23,7 @@ namespace Luax LuaxRefTable strongRefTable; // strong ref table LuaxRefTable weakRefTable; // weak ref table - size_t objectCount; // ͳ¼ÆËùÓÐÔÚ´ËstateÖд´½¨µÄʵÀý + size_t objectCount; // ͳ¼ÆËùÓÐÔÚ´ËstateÖд´½¨µÄʵÀý private: diff --git a/Source/3rdParty/Luax/luax_enum.cpp b/Source/3rdParty/Luax/luax_enum.cpp index 1ccc900..a58593a 100644 --- a/Source/3rdParty/Luax/luax_enum.cpp +++ b/Source/3rdParty/Luax/luax_enum.cpp @@ -11,11 +11,11 @@ namespace Luax int l_rmt__index(lua_State* L) { // params: - // 1. enum table - // 2. key + // 1: enum table + // 2: key // upvalues: - // 1. metatable + // 1: metatable int mt = lua_upvalueindex(1); lua_pushvalue(L, 2); @@ -27,7 +27,7 @@ namespace Luax int l_rmt__newindex(lua_State* L) { // upvalue: - // 1. enum table name + // 1: enum table name cc8* name = lua_tostring(L, lua_upvalueindex(1)); diff --git a/Source/3rdParty/Luax/luax_memberref.h b/Source/3rdParty/Luax/luax_memberref.h index baebd06..a7ff1f6 100644 --- a/Source/3rdParty/Luax/luax_memberref.h +++ b/Source/3rdParty/Luax/luax_memberref.h @@ -5,7 +5,7 @@ namespace Luax { /// - /// LuaxClassµÄ³ÉÔ±ÒýÓ㬴æÔÚinterface tableÀ±£Ö¤ÕýÈ·ÊÍ·Å£¬ÊÇÇ¿ÒýÓᣠ+ /// LuaxClassµÄ³ÉÔ±ÒýÓ㬴æÔÚref tableÀ±£Ö¤ÕýÈ·ÊÍ·Å£¬ÊÇÇ¿ÒýÓᣠ/// class LuaxMemberRef { diff --git a/Source/3rdParty/Luax/luax_ref.h b/Source/3rdParty/Luax/luax_ref.h index 7b484e9..b7aabe5 100644 --- a/Source/3rdParty/Luax/luax_ref.h +++ b/Source/3rdParty/Luax/luax_ref.h @@ -38,7 +38,7 @@ namespace Luax }; /// - /// Ç¿ÒýÓã¬ÔÚLUA_REGISTRYINDEX["LUAX_STRONGREF_TABLE"]Àï + /// Ç¿ÒýÓã¬ÔÚLUA_REGISTRYINDEX["_LUAX_STRONGREF_TABLE"]À±£Ö¤lua object²»»á±»»ØÊÕ¡£ /// class LuaxStrongRef: public LuaxRef { @@ -48,7 +48,7 @@ namespace Luax }; /// - /// ÈõÒýÓã¬ÔÚLUA_REGISTRYINDEX["LUAX_WEAKREF_TABLE"]Àï + /// ÈõÒýÓã¬ÔÚLUA_REGISTRYINDEX["_LUAX_WEAKREF_TABLE"]À²»Ó°Ïìlua objectµÄ»ØÊÕ£¬Ö»ÊÇ×÷Ϊһ¸ö·½±ãÈ¡lua objectµÄÓ³Éä¡£ /// class LuaxWeakRef : public LuaxRef { diff --git a/Source/3rdParty/Luax/luax_runtime.cpp b/Source/3rdParty/Luax/luax_runtime.cpp index 47b20cb..b45d36a 100644 --- a/Source/3rdParty/Luax/luax_runtime.cpp +++ b/Source/3rdParty/Luax/luax_runtime.cpp @@ -26,9 +26,9 @@ namespace Luax lua_State* L = lua_open(); assert(L); - // 1. ¼ÓÈë - mContexts.insert(pair(L, Context(L))); - // 2. ³õʼ»¯context + // 1) ¼ÓÈë + mContexts.insert(pair(L, LuaxContext(L))); + // 2) ³õʼ»¯context (*this)[L].Setup(); return L; @@ -36,7 +36,7 @@ namespace Luax void LuaxRuntime::Close(lua_State* L) { - map::iterator it = mContexts.find(L); + map::iterator it = mContexts.find(L); if (it != mContexts.end()) { lua_close(it->second.state); @@ -46,13 +46,13 @@ namespace Luax bool LuaxRuntime::HasLuaxState(lua_State* L) { - map::iterator it = mContexts.find(L); + map::iterator it = mContexts.find(L); return it != mContexts.end(); } LuaxState& LuaxRuntime::GetLuaxState(lua_State* L) { - map::iterator it = mContexts.find(L); + map::iterator it = mContexts.find(L); if (it != mContexts.end()) { return it->second.state; @@ -61,7 +61,7 @@ namespace Luax LuaxRefTable& LuaxRuntime::GetStrongRefTable(lua_State* L) { - map::iterator it = mContexts.find(L); + map::iterator it = mContexts.find(L); if (it != mContexts.end()) { return it->second.strongRefTable; @@ -70,16 +70,16 @@ namespace Luax LuaxRefTable& LuaxRuntime::GetWeaksRefTable(lua_State* L) { - map::iterator it = mContexts.find(L); + map::iterator it = mContexts.find(L); if (it != mContexts.end()) { return it->second.weakRefTable; } } - Context& LuaxRuntime::operator[](lua_State* L) + LuaxContext& LuaxRuntime::operator[](lua_State* L) { - map::iterator it = mContexts.find(L); + map::iterator it = mContexts.find(L); assert(it != mContexts.end()); return it->second; } diff --git a/Source/3rdParty/Luax/luax_runtime.h b/Source/3rdParty/Luax/luax_runtime.h index cb8b66b..1234627 100644 --- a/Source/3rdParty/Luax/luax_runtime.h +++ b/Source/3rdParty/Luax/luax_runtime.h @@ -35,7 +35,7 @@ namespace Luax LuaxRefTable& GetStrongRefTable(lua_State* L); LuaxRefTable& GetWeaksRefTable(lua_State* L); - Context& operator[](lua_State* L); + LuaxContext& operator[](lua_State* L); private: @@ -47,7 +47,7 @@ namespace Luax /// /// ´Ólua_State handleµ½contextµÄÓ³Éä /// - std::map mContexts; + std::map mContexts; }; diff --git a/Source/3rdParty/Luax/luax_state.cpp b/Source/3rdParty/Luax/luax_state.cpp index 5253a2c..1414591 100644 --- a/Source/3rdParty/Luax/luax_state.cpp +++ b/Source/3rdParty/Luax/luax_state.cpp @@ -27,23 +27,47 @@ namespace Luax luaL_openlibs(mState); } + void LuaxState::PushGlobalNamespace() + { + int top = GetTop(); + + lua_newtable(mState); // pseudo namespace table + int pnt = GetTop(); + + lua_newtable(mState); // metatable + int mt = GetTop(); + + // __index = _G + // __newindex = _G + lua_pushvalue(mState, LUA_GLOBALSINDEX); + lua_pushvalue(mState, LUA_GLOBALSINDEX); + lua_setfield(mState, mt, "__index"); + lua_setfield(mState, mt, "__newindex"); + + lua_setmetatable(mState, pnt); + + // stack: + // -1 pseudo global namespace + } + void LuaxState::PushNamespace(cc8* name) { - bool isG = !lua_istable(mState, -1); - int idx = isG ? LUA_GLOBALSINDEX : -1; - lua_getfield(mState, idx, name); + assert(IsNamespace(-1)); + + int top = GetTop(); + + lua_getfield(mState, -1, name); if (lua_isnil(mState, -1)) { lua_pop(mState, 1); + lua_newtable(mState); - assert(lua_istable(mState, -1)); lua_pushvalue(mState, -1); - int t = isG ? LUA_GLOBALSINDEX : -3; - lua_setfield(mState, t, name); + lua_setfield(mState, top, name); } // stack: - // -1 namespace + // -1 namespace } void LuaxState::PopNamespace() @@ -52,6 +76,11 @@ namespace Luax lua_pop(mState, 1); } + bool LuaxState::IsNamespace(int idx) + { + return lua_istable(mState, idx); + } + void LuaxState::DoString(const std::string& code) { luaL_dostring(mState, code.c_str()); @@ -146,11 +175,6 @@ namespace Luax lua_pop(mState, n); } - void LuaxState::Settop(int idx) - { - lua_settop(mState, idx); - } - bool LuaxState::IsNil(int idx) { return lua_isnil(mState, idx); @@ -191,6 +215,11 @@ namespace Luax return (mState != 0); } + void LuaxState::Settop(int idx) + { + lua_settop(mState, idx); + } + int LuaxState::GetTop() { return lua_gettop(mState); @@ -244,11 +273,6 @@ namespace Luax return false; } - void LuaxState::RegisterMethods(const luaL_Reg *l) - { - luaL_register(mState, 0, l); - } - void LuaxState::GetField(int idx, cc8* name) { lua_getfield(mState, idx, name); @@ -646,4 +670,33 @@ namespace Luax lua_setfield(L, top, name); } + + void LuaxState::RegisterMethods(const luaL_Reg *l) + { + assert(lua_istable(mState, -1)); + // luaL_registerµÚ¶þ¸ö²ÎÊýΪ¿Õ£¬ÔòÏò-1λÖÃ×¢²áluaL_RegÖÐÕâЩº¯Êý + luaL_register(mState, 0, l); + } + + void LuaxState::RegisterMethod(cc8* fname, lua_CFunction func) + { + assert(lua_istable(mState, -1)); + lua_pushcfunction(mState, func); + lua_setfield(mState, -1, fname); + } + + void LuaxState::RegisterPreloader(cc8* libname, lua_CFunction preloader) + { + lua_getglobal(mState, "package"); + lua_getfield(mState, -1, "preload"); + lua_pushcfunction(mState, preloader); + lua_setfield(mState, -2, libname); + lua_pop(mState, 2); + } + + void LuaxState::RegisterLib(cc8* libname, const luaL_Reg* l) + { + luaL_register(mState, libname, l); + } + } \ No newline at end of file diff --git a/Source/3rdParty/Luax/luax_state.h b/Source/3rdParty/Luax/luax_state.h index 166ac26..a936ea6 100644 --- a/Source/3rdParty/Luax/luax_state.h +++ b/Source/3rdParty/Luax/luax_state.h @@ -9,7 +9,7 @@ namespace Luax { - class Context; + class LuaxContext; class LuaxEnum; class LuaxStrongRef; class LuaxWeakRef; @@ -43,11 +43,14 @@ namespace Luax //------------------------------------------------------------------------------------------------------------ // Ãû³Æ¿Õ¼ä¹ÜÀí£¬Ãû³Æ¿Õ¼ä¾ÍÊÇÒ»¸ö±í£¬_GÊÇ×îÉÏÃæµÄ±í + void PushGlobalNamespace(); void PushNamespace(cc8* name); void PopNamespace(); - + bool IsNamespace(int idx); + //------------------------------------------------------------------------------------------------------------ + void SetTop(int top); int GetTop(); bool CheckParams(int idx, cc8* format); int AbsIndex(int idx); @@ -55,11 +58,6 @@ namespace Luax //------------------------------------------------------------------------------------------------------------ - /// - /// ×¢²áCº¯Êý£¬×¢ÒâºóÃæ¼ÓÒ»ÐÐ{0£¬ 0} - /// - void RegisterMethods(const luaL_Reg *l); - void GetField(int idx, cc8* name); void GetField(int idx, int key); std::string GetField(int idx, cc8* key, cc8* value); @@ -126,6 +124,7 @@ namespace Luax void DoFile(const std::string& file); //------------------------------------------------------------------------------------------------------------ + // ×¢²á·½·¨ /// /// ×¢²á¹¤³§£¬ÊÊÓÃÓÚÆÕͨÀ࣬ÓÐNew·½·¨ @@ -142,9 +141,33 @@ namespace Luax /// void RegisterEnum(cc8* name, LuaxEnum* enums); + /// + /// ×¢²áCº¯Êý£¬×¢ÒâºóÃæ¼ÓÒ»ÐÐ{0£¬ 0} + /// + void RegisterMethods(const luaL_Reg *l); + + /// + /// ×¢²áµ¥¸öCº¯Êý + /// + void RegisterMethod(cc8* fname, lua_CFunction func); + + /// + /// °Ñpreloader¼Óµ½package.preloadÀµ±require"libname"ʱluaµÄloader_preload¸ù¾ÝlibnameÕÒµ½preloaderÖ±½Ó¼ÓÔØ¡£ + /// ÓÃÀ´ÊµÏÖÐèÒªrequireµÄʱºò²Å¼ÓÔØ£¬²¢ÇÒ¼ÓÔØ¹ýÒ»´Îºópackage.loaded¼Ç¼ÏÂÀ´£¬Ï´β»»áÔÙ¼ÓÔØ¡£Í¨¹ýrequire»áµ÷ÓÃÕâ¸ö + /// preloader¡£ + /// + void RegisterPreloader(cc8* libname, lua_CFunction preloader); + + /// + /// ¸ù¾ÝluaL_Reg½¨Á¢lib table£¬²¢ÔÚ_GºÍpackage.loaded½¨Á¢¶ÔlibnameµÄË÷Òý£¬Ö¸Ïòlib table¡£ + /// + void RegisterLib(cc8* libname, const luaL_Reg* l); + + //------------------------------------------------------------------------------------------------------------ + private: - friend class Context; + friend class LuaxContext; LuaxState(lua_State* state); LuaxState(const LuaxState& state); diff --git a/Source/3rdParty/Luax/luax_state.inl b/Source/3rdParty/Luax/luax_state.inl index b5ee5aa..bd7ca9a 100644 --- a/Source/3rdParty/Luax/luax_state.inl +++ b/Source/3rdParty/Luax/luax_state.inl @@ -1,10 +1,10 @@ namespace Luax { - // Õë¶ÔÆÕͨÀàºÍµ¥ÀýÀàÓв»Í¬µÄ×¢²á¹ý³Ì£¬Í¨¹ýLuaxStateµÄÁ½¸ö¹¤³§·½·¨Register_ʵÏÖ - - // ×¢²á¹¤³§£¬·ÖΪע²áinterface tableºÍclass table£¬ÒÔtype nameΪ¼üÉèÖÃÔÚÃû³Æ¿Õ¼äÉÏ¡£ÔÚ×¢²á½×¶Î²»»áÉèÖÃÔª±í£¬µÈµ½New·½·¨µ÷ÓõÄʱºò²Å»á¡£ - + /// + /// ×¢²á¹¤³§£¬·ÖΪע²áinterface tableºÍclass table£¬ÒÔtype nameΪ¼üÉèÖÃÔÚÃû³Æ¿Õ¼äÉÏ¡£ÔÚ×¢²á½×¶Î²»»áÉèÖÃÔª±í£¬µÈµ½New·½ + /// ·¨µ÷ÓõÄʱºò²Å»á¡£ + /// template void LuaxState::RegisterFactory() { @@ -12,56 +12,51 @@ namespace Luax LuaxState& state = *this; int top = lua_gettop(L); // namespace table - assert(lua_istable(L, top)); - const char* type = T::GetLuaxFactoryName(); - - // interface table + // 1) interface table lua_newtable(L); + LuaxClass::RegisterLuaxInterface(state); + T::RegisterLuaxInterface(state); // interface table[__index] = interface table lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - LuaxClass::RegisterLuaxInterface(state); - T::RegisterLuaxInterface(state); - - LuaxClass::SetInterfaceTableRef(state, -1); + LuaxClass::SetLuaxInterfaceTableRef(state, -1); lua_settop(L, top); - // class table + // 2) class table lua_newtable(L); - LuaxClass::RegisterLuaxClass(state); LuaxClass::RegisterLuaxFactoryClass(state); T::RegisterLuaxClass(state); // ¼ì²âTÀïÃæÊÇ·ñûÓÐ×¢²á±ØÐëµÄ·½·¨ -#define _assertmethod(I, NAME) \ - GetField(I, NAME); \ - assert(IsType(-1, LUA_TFUNCTION)); \ - Pop(); + #define _assertmethod(I, NAME) \ + GetField(I, NAME); \ + assert(IsType(-1, LUA_TFUNCTION)); \ + Pop(); - // New·½·¨¿ÉÒÔûÓУ¬Èç¹ûûÓеϰ±íʾÕâÊÇÒ»¸ö³éÏóÀà - //_assertmethod(-1, "New"); + _assertmethod(-1, "New"); -#undef _assertmethod + #undef _assertmethod // .Extend() lua_pushvalue(state, -1); // class table - LuaxClass::PushInterfaceTable(state); // interface table + LuaxClass::PushLuaxInterfaceTable(state); // interface table lua_pushcclosure(state, LuaxClass::l_ExtendFactory, 2); lua_setfield(state, -2, "Extend"); // .GetInterfaceTable() - LuaxClass::PushInterfaceTable(state); // interface table + LuaxClass::PushLuaxInterfaceTable(state); // interface table lua_pushcclosure(state, LuaxClass::l_GetInterfaceTable, 1); lua_setfield(state, -2, "GetInterfaceTable"); - LuaxClass::SetClassTableRef(state, -1); + LuaxClass::SetLuaxClassTableRef(state, -1); + const char* type = T::GetLuaxFactoryName(); SetField(top, type); // reset top @@ -71,7 +66,9 @@ namespace Luax T::RegisterLuaxPostprocess(state); } - // ×¢²áµ¥Àý + /// + /// SingletonÖ»ÓÐÒ»¸öclass table£¬Ã»ÓÐinterface table¡£ + /// template void LuaxState::RegisterSingleton() { @@ -85,11 +82,18 @@ namespace Luax // class table. lua_newtable(L); - LuaxClass::RegisterLuaxClass(state); LuaxClass::RegisterLuaxFactoryClass(state); T::RegisterLuaxClass(state); + LuaxClass::SetLuaxClassTableRef(state, -1); + + // class tableµÄ__indexºÍ__newindexÖ¸Ïò×ÔÉí + lua_pushvalue(state, -1); + lua_setfield(state, -2, "__index"); + lua_pushvalue(state, -1); + lua_setfield(state, -2, "__newindex"); + SetField(top, type); // reset top diff --git a/Source/Asura.Editor/source/events/events.h b/Source/Asura.Editor/source/events/events.h new file mode 100644 index 0000000..bbe5cc3 --- /dev/null +++ b/Source/Asura.Editor/source/events/events.h @@ -0,0 +1,24 @@ +#ifndef __ASUSRA_EDITOR_EVENT_H__ +#define __ASUSRA_EDITOR_EVENT_H__ + +namespace AsuraEditor +{ + namespace Events + { + + enum EventType + { + GRAPHIC_EVENT, + KEYBOARD_EVENT, + MOUSE_EVENT + }; + + enum GraphicEvent + { + EVENT_PAINT, + }; + + } +} + +#endif \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h index 66c7ae1..2607969 100644 --- a/Source/Asura.Engine/Graphics/Image.h +++ b/Source/Asura.Engine/Graphics/Image.h @@ -1,14 +1,14 @@ #ifndef __ASURA_ENGINE_IMAGE_H__ #define __ASURA_ENGINE_IMAGE_H__ -#include "Math/Vector2.hpp" -#include "Scripting/Portable.h" -#include "FileSystem/Reloadable.h" -#include "StringMap.hpp" -#include "Manager.hpp" -#include "Texture.h" -#include "Color.h" -#include "ImageData.h" +#include "math/vector2.hpp" +#include "scripting/portable.h" +#include "fileSystem/reloadable.h" +#include "stringmap.hpp" +#include "manager.hpp" +#include "texture.h" +#include "color.h" +#include "image_data.h" namespace AsuraEngine { @@ -23,7 +23,7 @@ namespace AsuraEngine /// class Image ASURA_FINAL : public Drawable - , public Scripting::Portable + , public Scripting::Portable , public Filesystem::Reloadable { public: @@ -59,8 +59,6 @@ namespace AsuraEngine public: - //---------------------------------------------------------------------------------------------------------- - LUAX_DECL_FACTORY(SimImage); LUAX_DECL_METHOD(l_Load); @@ -68,8 +66,6 @@ namespace AsuraEngine LUAX_DECL_METHOD(l_GetHeight); LUAX_DECL_METHOD(l_GetSize); - //---------------------------------------------------------------------------------------------------------- - }; } diff --git a/Source/Asura.Engine/Graphics/Shader.h b/Source/Asura.Engine/Graphics/Shader.h index 7c00dda..4976106 100644 --- a/Source/Asura.Engine/Graphics/Shader.h +++ b/Source/Asura.Engine/Graphics/Shader.h @@ -94,6 +94,8 @@ namespace AsuraEngine /// GLuint mProgramHandle; + //------------------------------------------------------------------------------------------------------------ + public: LUAX_DECL_FACTORY(SimShader); @@ -111,6 +113,10 @@ namespace AsuraEngine LUAX_DECL_METHOD(l_SetUniformVector4); LUAX_DECL_METHOD(l_SetUniformColor); + private: + + Luax::LuaxMemberRef mCodeLuaRef; + }; } diff --git a/Source/Asura.Engine/graphics/binding/canvas.binding.cpp b/Source/Asura.Engine/graphics/binding/canvas.binding.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Asura.Engine/graphics/binding/canvas.cpp b/Source/Asura.Engine/graphics/binding/canvas.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/graphics/binding/color.binding.cpp b/Source/Asura.Engine/graphics/binding/color.binding.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Asura.Engine/graphics/binding/color.cpp b/Source/Asura.Engine/graphics/binding/color.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/graphics/binding/image.binding.cpp b/Source/Asura.Engine/graphics/binding/image.binding.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Asura.Engine/graphics/binding/image.cpp b/Source/Asura.Engine/graphics/binding/image.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/graphics/binding/image_data.binding.cpp b/Source/Asura.Engine/graphics/binding/image_data.binding.cpp new file mode 100644 index 0000000..d576718 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/image_data.binding.cpp @@ -0,0 +1,35 @@ +#include "../image.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace Graphics + { + + void Image::RegisterLuaxInterface(LuaxState& state) + { + + } + + void Image::RegisterLuaxClass(LuaxState& state) + { + + } + + void Image::RegisterLuaxPostprocess(LuaxState& state) + { + // blend·½·¨Ã¶¾Ù£¬AsuraEngine.EBlendMode + LuaxEnum EBlendMode[] = { + { "Additive", 1 }, + { "PreBlend", 2 }, + { "Substruction", 3 }, + { "Multiplied", 4 }, + {0, 0} + }; + + state.RegisterEnum("EBlendMode", EBlendMode); + } + + } +} \ No newline at end of file diff --git a/Source/Asura.Engine/graphics/binding/image_data.cpp b/Source/Asura.Engine/graphics/binding/image_data.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/graphics/binding/mesh2d.binding.cpp b/Source/Asura.Engine/graphics/binding/mesh2d.binding.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Asura.Engine/graphics/binding/mesh2d.cpp b/Source/Asura.Engine/graphics/binding/mesh2d.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/graphics/binding/mesh2d_data.binding.cpp b/Source/Asura.Engine/graphics/binding/mesh2d_data.binding.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Asura.Engine/graphics/binding/mesh2d_data.cpp b/Source/Asura.Engine/graphics/binding/mesh2d_data.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/graphics/binding/shader.binding.cpp b/Source/Asura.Engine/graphics/binding/shader.binding.cpp new file mode 100644 index 0000000..3f24bb7 --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/shader.binding.cpp @@ -0,0 +1,119 @@ +#include "../Shader.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// ½«´ËshaderÉèÖÃΪ»î¶¯¡£ + /// + int Shader::l_Use(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// ½«´ËshaderÉèÖÃΪ·Ç»î¶¯¡£ + /// + int Shader::l_Unuse(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// ´Ó×ÅÉ«Æ÷´úÂëÖй¹½¨shader³ÌÐò¡£Èç¹û³É¹¦·µ»Øtrue£¬Ê§°Ü·µ»Øfalse¡£ + /// + int Shader::l_Load(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// ÅжÏshaderÊÇ·ñÓÐÕâ¸öuniform£¬Èç¹ûÓзµ»Øtrue,·ñÔò·µ»Øfalse + /// + int Shader::l_HasUniform(lua_State* L) + { + LUAX_STATE(L); + + } + + /// + /// ºóµÄuniformsµÄlocation£¬Èç¹ûûÓÐÕâ¸öuniform£¬·µ»Ønil£¬·ñÔò·µ»Ø¶ÔÓ¦µÄloc + /// + int Shader::l_GetUniformLocation(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetBuiltInUniforms(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformFloat(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformTexture(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformVector2(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformVector3(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformVector4(lua_State* L) + { + LUAX_STATE(L); + + } + + int Shader::l_SetUniformColor(lua_State* L) + { + LUAX_STATE(L); + + } + + void Shader::RegisterLuaxInterface(LuaxState& state) + { + + } + + void Shader::RegisterLuaxClass(LuaxState& state) + { + + LuaxEnum EBuiltIn[] = { + {0, 0} + }; + + state.RegisterEnum("EBuiltIn", EBuiltIn); + + } + + void Shader::RegisterLuaxPostprocess(LuaxState& state) + { + + } + + } +} \ No newline at end of file diff --git a/Source/Asura.Engine/graphics/binding/shader.cpp b/Source/Asura.Engine/graphics/binding/shader.cpp deleted file mode 100644 index 27ed856..0000000 --- a/Source/Asura.Engine/graphics/binding/shader.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "../Shader.h" - -using namespace Luax; - -namespace AsuraEngine -{ - namespace Graphics - { - - /// - /// ½«´ËshaderÉèÖÃΪ»î¶¯¡£ - /// - int Shader::l_Use(lua_State* L) - { - LUAX_STATE(L); - - } - - /// - /// ½«´ËshaderÉèÖÃΪ·Ç»î¶¯¡£ - /// - int Shader::l_Unuse(lua_State* L) - { - LUAX_STATE(L); - - } - - /// - /// ´Ó×ÅÉ«Æ÷´úÂëÖй¹½¨shader³ÌÐò¡£Èç¹û³É¹¦·µ»Øtrue£¬Ê§°Ü·µ»Øfalse¡£ - /// - int Shader::l_Load(lua_State* L) - { - LUAX_STATE(L); - - } - - /// - /// ÅжÏshaderÊÇ·ñÓÐÕâ¸öuniform£¬Èç¹ûÓзµ»Øtrue,·ñÔò·µ»Øfalse - /// - int Shader::l_HasUniform(lua_State* L) - { - LUAX_STATE(L); - - } - - /// - /// ºóµÄuniformsµÄlocation£¬Èç¹ûûÓÐÕâ¸öuniform£¬·µ»Ønil£¬·ñÔò·µ»Ø¶ÔÓ¦µÄloc - /// - int Shader::l_GetUniformLocation(lua_State* L) - { - LUAX_STATE(L); - - } - - int Shader::l_SetBuiltInUniforms(lua_State* L) - { - LUAX_STATE(L); - - } - - int Shader::l_SetUniformFloat(lua_State* L) - { - LUAX_STATE(L); - - } - - int Shader::l_SetUniformTexture(lua_State* L) - { - LUAX_STATE(L); - - } - - int Shader::l_SetUniformVector2(lua_State* L) - { - LUAX_STATE(L); - - } - - int Shader::l_SetUniformVector3(lua_State* L) - { - LUAX_STATE(L); - - } - - int Shader::l_SetUniformVector4(lua_State* L) - { - LUAX_STATE(L); - - } - - int Shader::l_SetUniformColor(lua_State* L) - { - LUAX_STATE(L); - - } - - void Shader::RegisterLuaxClass(LuaxState& state) - { - - } - - void Shader::RegisterLuaxInterface(LuaxState& state) - { - - } - - void Shader::RegisterLuaxClass(LuaxState& state) - { - - LuaxEnum EBuiltIn[] = { - {0, 0} - }; - - state.RegisterEnum("EBuiltIn", EBuiltIn); - - } - - } -} \ No newline at end of file diff --git a/Source/Asura.Engine/graphics/binding/sprite_batch.binding.cpp b/Source/Asura.Engine/graphics/binding/sprite_batch.binding.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Source/Asura.Engine/graphics/binding/sprite_batch.cpp b/Source/Asura.Engine/graphics/binding/sprite_batch.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Source/Asura.Engine/graphics/binding/window.binding.cpp b/Source/Asura.Engine/graphics/binding/window.binding.cpp new file mode 100644 index 0000000..3befc8c --- /dev/null +++ b/Source/Asura.Engine/graphics/binding/window.binding.cpp @@ -0,0 +1,11 @@ +#include "../Window.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + + + } +} diff --git a/Source/Asura.Engine/graphics/binding/window.cpp b/Source/Asura.Engine/graphics/binding/window.cpp deleted file mode 100644 index 3befc8c..0000000 --- a/Source/Asura.Engine/graphics/binding/window.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "../Window.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - - - } -} diff --git a/Source/Asura.Engine/graphics/image.h b/Source/Asura.Engine/graphics/image.h index 66c7ae1..2607969 100644 --- a/Source/Asura.Engine/graphics/image.h +++ b/Source/Asura.Engine/graphics/image.h @@ -1,14 +1,14 @@ #ifndef __ASURA_ENGINE_IMAGE_H__ #define __ASURA_ENGINE_IMAGE_H__ -#include "Math/Vector2.hpp" -#include "Scripting/Portable.h" -#include "FileSystem/Reloadable.h" -#include "StringMap.hpp" -#include "Manager.hpp" -#include "Texture.h" -#include "Color.h" -#include "ImageData.h" +#include "math/vector2.hpp" +#include "scripting/portable.h" +#include "fileSystem/reloadable.h" +#include "stringmap.hpp" +#include "manager.hpp" +#include "texture.h" +#include "color.h" +#include "image_data.h" namespace AsuraEngine { @@ -23,7 +23,7 @@ namespace AsuraEngine /// class Image ASURA_FINAL : public Drawable - , public Scripting::Portable + , public Scripting::Portable , public Filesystem::Reloadable { public: @@ -59,8 +59,6 @@ namespace AsuraEngine public: - //---------------------------------------------------------------------------------------------------------- - LUAX_DECL_FACTORY(SimImage); LUAX_DECL_METHOD(l_Load); @@ -68,8 +66,6 @@ namespace AsuraEngine LUAX_DECL_METHOD(l_GetHeight); LUAX_DECL_METHOD(l_GetSize); - //---------------------------------------------------------------------------------------------------------- - }; } diff --git a/Source/Asura.Engine/graphics/shader.h b/Source/Asura.Engine/graphics/shader.h index 7c00dda..4976106 100644 --- a/Source/Asura.Engine/graphics/shader.h +++ b/Source/Asura.Engine/graphics/shader.h @@ -94,6 +94,8 @@ namespace AsuraEngine /// GLuint mProgramHandle; + //------------------------------------------------------------------------------------------------------------ + public: LUAX_DECL_FACTORY(SimShader); @@ -111,6 +113,10 @@ namespace AsuraEngine LUAX_DECL_METHOD(l_SetUniformVector4); LUAX_DECL_METHOD(l_SetUniformColor); + private: + + Luax::LuaxMemberRef mCodeLuaRef; + }; } diff --git a/Source/Samples/LuaxTest/main.cpp b/Source/Samples/LuaxTest/main.cpp index 3d5eb34..63daa1c 100644 --- a/Source/Samples/LuaxTest/main.cpp +++ b/Source/Samples/LuaxTest/main.cpp @@ -93,7 +93,7 @@ int Boy::l_New(lua_State* L) const char* name = state.GetValue(2, ""); Boy* boy = new Boy(age, name); - boy->PushLuaUserdata(state); + boy->PushLuaxUserdata(state); return 1; } @@ -179,64 +179,8 @@ class Girl : public LuaxClass }; //---------------------------------------------------------------------------------------------------------------- -string script = R"( -function main() - local a = 19 - print(Asura.version) - print(Asura.author.name) - print("ok") - print(Asura.author.func()) --- local boy = Asura.SimBoy.New("I am peter!", 19) --- boy:Say() --- print(Asura.SimSchool.GetName()) - print(Asura.SimBoy.Class) - print(Asura.SimBoy.Gender) - print(Asura.SimBoy.GetClassName()) - print(Asura.School.GetName()) - print(Asura.School.Region) ---[[ - local Kid = Asura.SimBoy.Extend() - Asura.Kid = Kid - Kid.New = function(self, height, age) - self.base(age) - self.height = height - end - Kid.GetHeight = function(self) - print(self.height) - end - local kid = Kid.New(110, 12) - kid:GetHeight() - ]] - local kid = Asura.SimBoy.New(23, "Chai") - print(kid:GetAge()) - print(kid:GetName()) - kid.fruit = function() - return "apple" - end - print(kid.fruit()) - print(Asura.SimBoy.GetGender()) - Asura.SimBoy.Havefun = function() - return "Boys have some fun!" - end - print(Asura.SimBoy.Havefun()) - --- ÐÞ¸ÄÀà·½·¨ - Asura.SimBoy.Foo = function() - return "SimBoy.Foo" - end - print(Asura.SimBoy.Foo()) - - print(Asura.EGender.BOY) - Asura.EGender.BOY = 2 - print(Asura.EGender.BOY) - print(Asura.SimBoy.EHabits.Girls) - print(Asura.EHabits.Girls) -end -function err(msg) - print(msg) -end -xpcall(main, err) -)"; + +#include "script.lua" //---------------------------------------------------------------------------------------------------------------- @@ -254,6 +198,7 @@ int main() Luax::LuaxState& state = runtime[L].state; state.OpenLibs(); + state.PushGlobalNamespace(); state.PushNamespace("Asura"); //×¢²áenum @@ -277,6 +222,7 @@ int main() state.RegisterFactory(); state.PopNamespace(); // Asura + state.PopNamespace(); // Global state.DoString(script); runtime.Close(L); diff --git a/Source/Samples/LuaxTest/script.lua b/Source/Samples/LuaxTest/script.lua new file mode 100644 index 0000000..84bcba9 --- /dev/null +++ b/Source/Samples/LuaxTest/script.lua @@ -0,0 +1,63 @@ +string script = R"scriptcode( +-- start script + +function main() + local a = 19 + print(Asura.version) + print(Asura.author.name) + print("ok") + print(Asura.author.func()) +-- local boy = Asura.SimBoy.New("I am peter!", 19) +-- boy:Say() +-- print(Asura.SimSchool.GetName()) + print(Asura.SimBoy.Class) + print(Asura.SimBoy.Gender) + print(Asura.SimBoy.GetClassName()) + print(Asura.School.GetName()) + print(Asura.School.Region) +--[[ + local Kid = Asura.SimBoy.Extend() + Asura.Kid = Kid + Kid.New = function(self, height, age) + self.base(age) + self.height = height + end + Kid.GetHeight = function(self) + print(self.height) + end + local kid = Kid.New(110, 12) + kid:GetHeight() + ]] + local kid = Asura.SimBoy.New(23, "Chai") + print(kid:GetAge()) + print(kid:GetName()) + kid.fruit = function() + return "apple" + end + print(kid.fruit()) + print(Asura.SimBoy.GetGender()) + Asura.SimBoy.Havefun = function() + return "Boys have some fun!" + end + print(Asura.SimBoy.Havefun()) + +-- ÐÞ¸ÄÀà·½·¨ + Asura.SimBoy.Foo = function() + return "SimBoy.Foo" + end + print(Asura.SimBoy.Foo()) + + print(Asura.EGender.BOY) + --Asura.EGender.BOY = 2 + print(Asura.EGender.BOY) + print(Asura.SimBoy.EHabits.Girls) + print(Asura.EHabits.Girls) +end +function err(msg) + print(msg) +end +xpcall(main, err) + + +-- end script +)scriptcode"; \ No newline at end of file -- cgit v1.1-26-g67d0