From 7270cd95294d53180641b05784258df1e29f90d2 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 15 Nov 2020 11:56:49 +0800 Subject: *lua BindToLua --- Runtime/Scripting/LuaBindState.h | 102 +++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'Runtime/Scripting/LuaBindState.h') diff --git a/Runtime/Scripting/LuaBindState.h b/Runtime/Scripting/LuaBindState.h index 76357cf..ea8cf5b 100644 --- a/Runtime/Scripting/LuaBindState.h +++ b/Runtime/Scripting/LuaBindState.h @@ -7,13 +7,13 @@ #include "LuaBindRefTable.h" #include "LuaBindGlobalState.h" -namespace LuaBind +namespace LuaBind { - class LuaBindVM; - class LuaBindEnum; - class LuaBindStrongRef; - class LuaBindWeakRef; + class VM; + class Enum; + class StrongRef; + class WeakRef; /// /// 对lua_State的代理,除了保存一个lua_State的引用不保存其他内容。一个实例的metatable如下: @@ -24,13 +24,13 @@ namespace LuaBind /// 从userdata通过getmetatable获取上级metatable。除此之外还有一个class table注册在对应 /// 的名称空间里。 /// - LUA_BIND_API class LuaBindState + LUA_BIND_API class State { public: - LuaBindState(lua_State* state); - LuaBindState(const LuaBindState& state); - virtual ~LuaBindState(); + State(lua_State* state); + State(const State& state); + virtual ~State(); inline lua_State* operator ->() { return mState; }; inline lua_State& operator *() { return *mState; }; @@ -44,7 +44,7 @@ namespace LuaBind global_State* GetGlobalState(); - LuaBindVM* GetVM(); + VM* GetVM(); //------------------------------------------------------------------------------// @@ -163,7 +163,7 @@ namespace LuaBind /// /// 注册枚举 /// - void RegisterEnum(cc8* name, LuaBindEnum* enums); + void RegisterEnum(cc8* name, Enum* enums); /// /// 注册C函数,注意后面加一行{0, 0} @@ -203,10 +203,10 @@ namespace LuaBind protected: - friend class LuaBindVM; + friend class VM; /// - /// 屏蔽对LuaBindState的地址相关操作 + /// 屏蔽对State的地址相关操作 /// void* operator &(); void* operator new(size_t size); @@ -217,69 +217,69 @@ namespace LuaBind //--------------------------------------------------------------------------------// // GetValue()模板特化 - template <> bool LuaBindState::GetValue < bool >(int idx, const bool value); - template <> cc8* LuaBindState::GetValue < cc8* >(int idx, const cc8* value); - template <> double LuaBindState::GetValue < double >(int idx, const double value); - template <> float LuaBindState::GetValue < float >(int idx, const float value); - template <> s8 LuaBindState::GetValue < s8 >(int idx, const s8 value); - template <> s16 LuaBindState::GetValue < s16 >(int idx, const s16 value); - template <> s32 LuaBindState::GetValue < s32 >(int idx, const s32 value); - template <> s64 LuaBindState::GetValue < s64 >(int idx, const s64 value); - template <> u8 LuaBindState::GetValue < u8 >(int idx, const u8 value); - template <> u16 LuaBindState::GetValue < u16 >(int idx, const u16 value); - template <> u32 LuaBindState::GetValue < u32 >(int idx, const u32 value); - template <> u64 LuaBindState::GetValue < u64 >(int idx, const u64 value); - template <> std::string LuaBindState::GetValue < std::string >(int idx, const std::string value); - template <> const void* LuaBindState::GetValue < const void* >(int idx, const void* value); + template <> bool State::GetValue < bool >(int idx, const bool value); + template <> cc8* State::GetValue < cc8* >(int idx, const cc8* value); + template <> double State::GetValue < double >(int idx, const double value); + template <> float State::GetValue < float >(int idx, const float value); + template <> s8 State::GetValue < s8 >(int idx, const s8 value); + template <> s16 State::GetValue < s16 >(int idx, const s16 value); + template <> s32 State::GetValue < s32 >(int idx, const s32 value); + template <> s64 State::GetValue < s64 >(int idx, const s64 value); + template <> u8 State::GetValue < u8 >(int idx, const u8 value); + template <> u16 State::GetValue < u16 >(int idx, const u16 value); + template <> u32 State::GetValue < u32 >(int idx, const u32 value); + template <> u64 State::GetValue < u64 >(int idx, const u64 value); + template <> std::string State::GetValue < std::string >(int idx, const std::string value); + template <> const void* State::GetValue < const void* >(int idx, const void* value); //--------------------------------------------------------------------------------// // CheckValue模板特化 - template <> bool LuaBindState::CheckValue < bool >(int idx); - template <> cc8* LuaBindState::CheckValue < cc8* >(int idx); - template <> double LuaBindState::CheckValue < double >(int idx); - template <> float LuaBindState::CheckValue < float >(int idx); - template <> s8 LuaBindState::CheckValue < s8 >(int idx); - template <> s16 LuaBindState::CheckValue < s16 >(int idx); - template <> s32 LuaBindState::CheckValue < s32 >(int idx); - template <> s64 LuaBindState::CheckValue < s64 >(int idx); - template <> u8 LuaBindState::CheckValue < u8 >(int idx); - template <> u16 LuaBindState::CheckValue < u16 >(int idx); - template <> u32 LuaBindState::CheckValue < u32 >(int idx); - template <> u64 LuaBindState::CheckValue < u64 >(int idx); - template <> std::string LuaBindState::CheckValue < std::string >(int idx); - template <> const void* LuaBindState::CheckValue < const void* >(int idx); + template <> bool State::CheckValue < bool >(int idx); + template <> cc8* State::CheckValue < cc8* >(int idx); + template <> double State::CheckValue < double >(int idx); + template <> float State::CheckValue < float >(int idx); + template <> s8 State::CheckValue < s8 >(int idx); + template <> s16 State::CheckValue < s16 >(int idx); + template <> s32 State::CheckValue < s32 >(int idx); + template <> s64 State::CheckValue < s64 >(int idx); + template <> u8 State::CheckValue < u8 >(int idx); + template <> u16 State::CheckValue < u16 >(int idx); + template <> u32 State::CheckValue < u32 >(int idx); + template <> u64 State::CheckValue < u64 >(int idx); + template <> std::string State::CheckValue < std::string >(int idx); + template <> const void* State::CheckValue < const void* >(int idx); /// - /// 在成员方法里创建LuaBindState并对参数进行检查。 + /// 在成员方法里创建State并对参数进行检查。 /// #define LUA_BIND_SETUP(L, params) \ - LuaBind::LuaBindState state(L); \ + LuaBind::State state(L); \ if(!state.CheckParams(1, params)) return 0 #define LUA_BIND_STATE(L) \ - LuaBind::LuaBindState state(L) + LuaBind::State state(L) //--------------------------------------------------------------------------------// /// /// 确保不安全的lua调用能够在调用之后返回到最初stack状态。 /// - class LuaBindScopedState - : public LuaBindState + class ScopedState + : public State { public: - LuaBindScopedState(lua_State* state) - : LuaBindState(state) + ScopedState(lua_State* state) + : State(state) { mRestoreTop = lua_gettop(mState); } - LuaBindScopedState(const LuaBindState& state) - : LuaBindState(state) + ScopedState(const State& state) + : State(state) { mRestoreTop = lua_gettop(mState); } - ~LuaBindScopedState() + ~ScopedState() { if (mState) { if (lua_gettop(mState) != mRestoreTop) { -- cgit v1.1-26-g67d0