summaryrefslogtreecommitdiff
path: root/Source/3rdParty/Luax/luax_class.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/3rdParty/Luax/luax_class.h')
-rw-r--r--Source/3rdParty/Luax/luax_class.h124
1 files changed, 92 insertions, 32 deletions
diff --git a/Source/3rdParty/Luax/luax_class.h b/Source/3rdParty/Luax/luax_class.h
index 1721ec4..d241030 100644
--- a/Source/3rdParty/Luax/luax_class.h
+++ b/Source/3rdParty/Luax/luax_class.h
@@ -3,50 +3,110 @@
#include <vector>
+#include "lua.hpp"
+#include "luax_config.h"
+#include "luax_state.h"
+
namespace Luax
{
-#define LUAX_DECL_METHOD(MTD) static int MTD(lua_State*)
-#define LUAX_DECL_FACTORY(CLS) static int RegisterLuaClass(lua_State*);
-#define LUAX_DECL_SINGLETON(CLS)
+#define LUAX_DECL_METHOD(mtd) static int mtd(lua_State*)
+
+ ///
+ /// RegisterLuaxClass עķͳԱö١ȵclass table
+ /// LuaxRegisterInterface עӿڷinterface table
+ /// LuaxGetFactoryName ùͬʱעʱעΪsingletonͨʱ
+ ///
+#define LUAX_DECL_FACTORY(type) \
+ static void RegisterLuaxClass(LuaxState&);\
+ static void RegisterLuaxInterface(LuaxState&);\
+ static const char* GetLuaxFactoryName() { return #type; };\
+ static const char* GetLuaxClassName() { return #type; };\
+ static bool IsLuaxClassSingleton() { return false; };
+
+
+ ///
+ /// RegisterLuaxClass עķͳԱö١ȵclass table
+ /// LuaxGetSingletonName õ
+ ///
+#define LUAX_DECL_SINGLETON(type) \
+ static void RegisterLuaxClass(LuaxState&); \
+ static const char* GetLuaxSingletonName() { return #type; }; \
+ static const char* GetLuaxClassName() { return #type; }; \
+ static bool IsLuaxClassSingleton() { return true; };
+
+
+ ///
+ /// Ҫ¶luaclassҪ̳дࡣͨluaʵҪȷüȷԣڶ߳Ҫȷͷš
+ ///
+ class LuaxClass
+ {
+ public:
+
+ void Retain();
+ void Release();
+
+ //------------------------------------------------------------------------------------------------------------
+ //
+
+ template<class T>
+ static void RegisterLuaxClass(LuaxState& state);
+
+ template<class T>
+ LUAX_DECL_METHOD(l_GetClassName);
+
+ //------------------------------------------------------------------------------------------------------------
+ //
+
+ template<class T>
+ static void RegisterLuaxFactoryClass(LuaxState& state);
+
+ template<class T>
+ static void RegisterLuaxInterface(LuaxState& state);
+
+ LUAX_DECL_METHOD(l_GC);
+
+ //------------------------------------------------------------------------------------------------------------
+ //
+
+ template<class T>
+ static void RegisterLuaxSingletonClass(LuaxState& state);
+
+ protected:
+
+ LuaxClass();
+ ~LuaxClass();
-#define LUAX_REGISTER_CLASS(CLS) CLS::RegisterLuaType()
- /*
- ///
- /// Ҫ¶luaclassҪ̳дࡣ
- ///
- class LuaxClass
- {
- public:
+ ///
+ /// userdata pushջûгʼmUserdataʼúԪѳʼõuserdataջ
+ ///
+ bool PushLuaUserdata(LuaxState& state);
- static void RegisterLuaType();
+ private:
- static void RegisterLuaFuncs();
+ ///
+ /// ȡַҪַֻͨڶϴʵõջϺ;̬ıȡַ֤ü׼ȷ
+ /// ҪãʹôݶǴݵַ
+ ///
+ void* operator &();
- private:
-
- };
+ void BindToLua(LuaxState& state);
- ///
- /// ҪΪuserdata̳дࡣΪ࣬ͨLUAX_DECL_FACTORY(CLS)ָ
- ///
- class LuaxFactory : public LuaxClass
- {
-
+ int mRefCount;
- };
+ void* mUserdata;
+
+ };
- ///
- /// עluaĵ̳дࡣ
- ///
- class LuaxSingleton : public LuaxClass
- {
- public:
+ ///
+ /// ڳԱﴴLuaxStateԲм顣
+ ///
+#define LUAX_SETUP(L, params) \
+ LuaxState state(L);\
+ if(!state.CheckParams(1, params)) return 0;
- private:
+#include "luax_class.inl"
- };
- */
}
#endif \ No newline at end of file