diff options
author | chai <chaifix@163.com> | 2019-03-12 23:08:31 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-03-12 23:08:31 +0800 |
commit | 6016ece202eef94ed76bd20d4f7879ccc71cc2e6 (patch) | |
tree | da0d0be011ee24489174bde1ec1c436ce7aaa1b2 /Source/3rdParty/Luax/luax_class.h | |
parent | 9eba034f5c2ffd49f33d38c283b24230f9e362e0 (diff) |
*luax
Diffstat (limited to 'Source/3rdParty/Luax/luax_class.h')
-rw-r--r-- | Source/3rdParty/Luax/luax_class.h | 95 |
1 files changed, 64 insertions, 31 deletions
diff --git a/Source/3rdParty/Luax/luax_class.h b/Source/3rdParty/Luax/luax_class.h index d241030..bde9990 100644 --- a/Source/3rdParty/Luax/luax_class.h +++ b/Source/3rdParty/Luax/luax_class.h @@ -6,6 +6,7 @@ #include "lua.hpp" #include "luax_config.h" #include "luax_state.h" +#include "luax_runtime.h" namespace Luax { @@ -46,55 +47,80 @@ namespace Luax void Retain(); void Release(); - //------------------------------------------------------------------------------------------------------------ - // + protected: - template<class T> - static void RegisterLuaxClass(LuaxState& state); + LuaxClass(); + virtual ~LuaxClass(); - template<class T> - LUAX_DECL_METHOD(l_GetClassName); + /// + /// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջ + /// + bool PushLuaUserdata(LuaxState& state); //------------------------------------------------------------------------------------------------------------ - // - template<class T> - static void RegisterLuaxFactoryClass(LuaxState& state); + /// + /// reftableĹ + /// + void Ref(); - template<class T> - static void RegisterLuaxInterface(LuaxState& state); + private: - LUAX_DECL_METHOD(l_GC); + friend class LuaxState; - //------------------------------------------------------------------------------------------------------------ - // + template<class T> static void RegisterLuaxClass(LuaxState& state); + template<class T> static void RegisterLuaxFactoryClass(LuaxState& state); + template<class T> static void RegisterLuaxInterface(LuaxState& state); + template<class T> static void RegisterLuaxSingletonClass(LuaxState& state); - template<class T> - static void RegisterLuaxSingletonClass(LuaxState& state); + /// + /// ȡַҪַֻͨڶϴʵõջϺ;̬ıȡַ֤üȷ + /// ҪãʹôݶǴݵַ + /// + void* operator &(); - protected: + /// + /// stateǹ + /// + void BindFactoryToLua(LuaxState& state); - LuaxClass(); - ~LuaxClass(); + /// + /// stateǵ + /// + void BindSingletonToLua(LuaxState& state); + + //------------------------------------------------------------------------------------------------------------ + + LuaxStrongRef mInterfaceTable; // interface table + LuaxStrongRef mClassTable; // class table /// - /// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջ + /// ü̼߳乲 /// - bool PushLuaUserdata(LuaxState& state); - - private: + int mRC; /// - /// ȡַҪַֻͨڶϴʵõջϺ;̬ıȡַ֤üȷ - /// ҪãʹôݶǴݵַ + /// ȷֻͨReleaseõsaferֻҪ̳LuaxClass࣬ʹdeleteֱͻᱨ /// - void* operator &(); + bool mSafer; - void BindToLua(LuaxState& state); + public: - int mRefCount; + //------------------------------------------------------------------------------------------------------------ + // + + template<class T> LUAX_DECL_METHOD(l_GetClassName); + template<class T> LUAX_DECL_METHOD(l_GetClassName2); + + LUAX_DECL_METHOD(l_ToString); // __tostring + + //------------------------------------------------------------------------------------------------------------ + // - void* mUserdata; + LUAX_DECL_METHOD(l_GC); // __gc + + //------------------------------------------------------------------------------------------------------------ + // }; @@ -102,8 +128,15 @@ namespace Luax /// ڳԱﴴLuaxStateԲм顣 /// #define LUAX_SETUP(L, params) \ - LuaxState state(L);\ - if(!state.CheckParams(1, params)) return 0; + LuaxRuntime& runtime = LuaxRuntime::Get(); \ + LuaxState& state = runtime[L].state; \ + if(!state.CheckParams(1, params)) return 0 + +#define LUAX_STATE(L) \ + LuaxState& state = LuaxRuntime::Get().GetLuaxState(L) + +#define LUAX_RUNTIME() \ + LuaxRuntime& runtime = LuaxRuntime::Get() #include "luax_class.inl" |