From 8644e03586ac9c39741f62cbcbce87b18805538c Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 14 Mar 2019 23:12:54 +0800 Subject: =?UTF-8?q?*=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/3rdParty/Luax/luax_state.h | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'Source/3rdParty/Luax/luax_state.h') diff --git a/Source/3rdParty/Luax/luax_state.h b/Source/3rdParty/Luax/luax_state.h index 2b143f8..166ac26 100644 --- a/Source/3rdParty/Luax/luax_state.h +++ b/Source/3rdParty/Luax/luax_state.h @@ -10,6 +10,9 @@ namespace Luax { class Context; + class LuaxEnum; + class LuaxStrongRef; + class LuaxWeakRef; /// /// 对lua_State的代理,除了保存一个lua_State的引用不保存其他内容。一个实例的metatable如下: @@ -23,15 +26,15 @@ namespace Luax { public: - operator lua_State*(); - operator bool(); - lua_State* operator ->(); - lua_State& operator *(); + inline lua_State* operator ->() { return mState; }; + inline lua_State& operator *() { return *mState; }; + inline operator lua_State*() { return mState; } + inline operator bool() { return mState != nullptr; }; /// /// 获取绑定的lua_State /// - lua_State* GetHandle(); + inline lua_State* GetHandle() { return mState; }; //------------------------------------------------------------------------------------------------------------ @@ -55,7 +58,7 @@ namespace Luax /// /// 注册C函数,注意后面加一行{0, 0} /// - void Register(const luaL_Reg *l); + void RegisterMethods(const luaL_Reg *l); void GetField(int idx, cc8* name); void GetField(int idx, int key); @@ -109,11 +112,6 @@ namespace Luax template T* GetLuaUserdata(int idx); - //------------------------------------------------------------------------------------------------------------ - // 对引用的管理,包含register[LUAX_STRONG_REFTABLE]和register[LUAX_WEAK_REFTABLE] - - void Ref(); - //------------------------------------------------------------------------------------------------------------ template T GetValue(int idx, T default_value); @@ -139,6 +137,11 @@ namespace Luax /// template void RegisterSingleton(); + /// + /// 注册枚举 + /// + void RegisterEnum(cc8* name, LuaxEnum* enums); + private: friend class Context; @@ -175,6 +178,17 @@ namespace Luax template <> std::string LuaxState::GetValue < std::string >(int idx, const std::string value); template <> const void* LuaxState::GetValue < const void* >(int idx, const void* value); + /// + /// 在成员方法里创建LuaxState并对参数进行检查。 + /// +#define LUAX_SETUP(L, params) \ + 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) + } #endif \ No newline at end of file -- cgit v1.1-26-g67d0