diff options
author | chai <chaifix@163.com> | 2020-11-15 11:56:49 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-11-15 11:56:49 +0800 |
commit | 7270cd95294d53180641b05784258df1e29f90d2 (patch) | |
tree | 171554d5caed0adea988c785d3714d08595ba1f3 /Runtime/Scripting/LuaBindState.cpp | |
parent | d2e4b2839bc7ce874370ff4c52dcfdadf666ff52 (diff) |
*lua BindToLua
Diffstat (limited to 'Runtime/Scripting/LuaBindState.cpp')
-rw-r--r-- | Runtime/Scripting/LuaBindState.cpp | 192 |
1 files changed, 96 insertions, 96 deletions
diff --git a/Runtime/Scripting/LuaBindState.cpp b/Runtime/Scripting/LuaBindState.cpp index 845cf29..2b699f5 100644 --- a/Runtime/Scripting/LuaBindState.cpp +++ b/Runtime/Scripting/LuaBindState.cpp @@ -7,38 +7,38 @@ namespace LuaBind { - LuaBindState::LuaBindState(lua_State* state) + State::State(lua_State* state) : mState(state) { assert(state); } - LuaBindState::LuaBindState(const LuaBindState& state) + State::State(const State& state) : mState(state.mState) { assert(state.mState); } - LuaBindState::~LuaBindState() + State::~State() { } - void LuaBindState::OpenLibs() + void State::OpenLibs() { luaL_openlibs(mState); } - global_State* LuaBindState::GetGlobalState() + global_State* State::GetGlobalState() { return G(mState); } - LuaBindVM* LuaBindState::GetVM() + VM* State::GetVM() { - return LuaBindVM::TryGetVM(G(mState)); + return VM::TryGetVM(G(mState)); } - void LuaBindState::PushGlobalNamespace() + void State::PushGlobalNamespace() { int top = GetTop(); @@ -61,7 +61,7 @@ namespace LuaBind // -1 pseudo global namespace } - void LuaBindState::PushNamespace(cc8* name) + void State::PushNamespace(cc8* name) { assert(IsNamespace(-1)); @@ -81,23 +81,23 @@ namespace LuaBind // -1 namespace } - void LuaBindState::PopNamespace() + void State::PopNamespace() { assert(lua_istable(mState, -1)); lua_pop(mState, 1); } - bool LuaBindState::IsNamespace(int idx) + bool State::IsNamespace(int idx) { return lua_istable(mState, idx); } - void LuaBindState::DoString(const std::string& code) + void State::DoString(const std::string& code) { luaL_dostring(mState, code.c_str()); } - int LuaBindState::AbsIndex(int idx) + int State::AbsIndex(int idx) { /* #define abs_index(mState, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ @@ -111,116 +111,116 @@ namespace LuaBind return idx; } - void LuaBindState::Call(int nArgs, int nResults) + void State::Call(int nArgs, int nResults) { lua_pcall(mState, nArgs, nResults, 0); } - void LuaBindState::PushNil() + void State::PushNil() { lua_pushnil(mState); } - void LuaBindState::Push(bool value) + void State::Push(bool value) { lua_pushboolean(mState, value ? 1 : 0); } - void LuaBindState::Push(cc8* value) + void State::Push(cc8* value) { lua_pushstring(mState, value); } - void LuaBindState::Push(double value) + void State::Push(double value) { lua_pushnumber(mState, value); } - void LuaBindState::Push(float value) + void State::Push(float value) { lua_pushnumber(mState, value); } - void LuaBindState::Push(int value) + void State::Push(int value) { lua_pushnumber(mState, value); } - void LuaBindState::Push(u16 value) + void State::Push(u16 value) { lua_pushnumber(mState, value); } - void LuaBindState::Push(u32 value) + void State::Push(u32 value) { lua_pushnumber(mState, value); } - void LuaBindState::Push(u64 value) + void State::Push(u64 value) { lua_pushnumber(mState, (double)value); } - void LuaBindState::Push(s64 value) + void State::Push(s64 value) { lua_pushinteger(mState, value); } - void LuaBindState::Push(uintptr value) + void State::Push(uintptr value) { lua_pushlightuserdata(mState, (void*)value); } - void LuaBindState::Push(lua_CFunction value) + void State::Push(lua_CFunction value) { lua_pushcfunction(mState, value); } - void LuaBindState::Push(void* data, size_t size) + void State::Push(void* data, size_t size) { lua_pushlstring(mState, (cc8*)data, size); } - void LuaBindState::Push(const void* value) + void State::Push(const void* value) { lua_pushlightuserdata(mState, (void*)value); } - void LuaBindState::Push(std::string value) + void State::Push(std::string value) { Push(value.c_str()); } - void LuaBindState::PushValues(int idx, int n) + void State::PushValues(int idx, int n) { idx = AbsIndex(idx); for (int i = idx; i < idx + n; ++i) lua_pushvalue(mState, i); } - void LuaBindState::Pop(int n /* = 1 */) + void State::Pop(int n /* = 1 */) { lua_pop(mState, n); } - bool LuaBindState::IsNil(int idx) + bool State::IsNil(int idx) { return lua_isnil(mState, idx); } - bool LuaBindState::IsNilOrNone(int idx) + bool State::IsNilOrNone(int idx) { int t = lua_type(mState, idx); return ((t == LUA_TNONE) || (t == LUA_TNIL)); } - bool LuaBindState::IsTableOrUserdata(int idx) + bool State::IsTableOrUserdata(int idx) { int check = lua_type(mState, idx); return ((check == LUA_TTABLE) || (check == LUA_TUSERDATA)); } - bool LuaBindState::IsTrueOrNotNil(int idx) + bool State::IsTrueOrNotNil(int idx) { if (lua_isboolean(mState, idx)) { return lua_toboolean(mState, idx) ? true : false; @@ -228,32 +228,32 @@ namespace LuaBind return !lua_isnil(mState, idx); } - bool LuaBindState::IsType(int idx, int type) + bool State::IsType(int idx, int type) { return (lua_type(mState, idx) == type); } - bool LuaBindState::IsType(int idx, cc8* name, int type) + bool State::IsType(int idx, cc8* name, int type) { return this->HasField(idx, name, type); } - bool LuaBindState::IsValid() + bool State::IsValid() { return (mState != 0); } - void LuaBindState::Settop(int idx) + void State::Settop(int idx) { lua_settop(mState, idx); } - int LuaBindState::GetTop() + int State::GetTop() { return lua_gettop(mState); } - bool LuaBindState::HasField(int idx, cc8* name) { + bool State::HasField(int idx, cc8* name) { lua_getfield(mState, idx, name); bool hasField = (lua_isnil(mState, -1) == false); @@ -262,7 +262,7 @@ namespace LuaBind return hasField; } - bool LuaBindState::HasField(int idx, int key) { + bool State::HasField(int idx, int key) { this->GetField(idx, key); bool hasField = (lua_isnil(mState, -1) == false); @@ -271,7 +271,7 @@ namespace LuaBind return hasField; } - bool LuaBindState::HasField(int idx, cc8* name, int type) { + bool State::HasField(int idx, cc8* name, int type) { lua_getfield(mState, idx, name); bool hasField = (lua_type(mState, -1) == type); @@ -280,7 +280,7 @@ namespace LuaBind return hasField; } - bool LuaBindState::HasField(int idx, int key, int type) { + bool State::HasField(int idx, int key, int type) { this->GetField(idx, key); bool hasField = (lua_type(mState, -1) == type); @@ -289,7 +289,7 @@ namespace LuaBind return hasField; } - bool LuaBindState::HasKeys(int idx) { + bool State::HasKeys(int idx) { idx = this->AbsIndex(idx); @@ -301,12 +301,12 @@ namespace LuaBind return false; } - void LuaBindState::GetField(int idx, cc8* name) + void State::GetField(int idx, cc8* name) { lua_getfield(mState, idx, name); } - void LuaBindState::GetField(int idx, int key) + void State::GetField(int idx, int key) { idx = this->AbsIndex(idx); @@ -314,7 +314,7 @@ namespace LuaBind lua_gettable(mState, idx); } - std::string LuaBindState::GetField(int idx, cc8* key, cc8* default_value) + std::string State::GetField(int idx, cc8* key, cc8* default_value) { std::string str; if (this->GetFieldWithType(idx, key, LUA_TSTRING)) { @@ -327,7 +327,7 @@ namespace LuaBind return str; } - std::string LuaBindState::GetField(int idx, int key, cc8* default_value) + std::string State::GetField(int idx, int key, cc8* default_value) { std::string str; if (this->GetFieldWithType(idx, key, LUA_TSTRING)) { @@ -340,7 +340,7 @@ namespace LuaBind return str; } - std::string LuaBindState::GetField(int idx, cc8* key, const std::string& value) + std::string State::GetField(int idx, cc8* key, const std::string& value) { std::string str; if (this->GetFieldWithType(idx, key, LUA_TSTRING)) { @@ -353,7 +353,7 @@ namespace LuaBind return str; } - std::string LuaBindState::GetField(int idx, int key, const std::string& value) + std::string State::GetField(int idx, int key, const std::string& value) { std::string str; if (this->GetFieldWithType(idx, key, LUA_TSTRING)) { @@ -366,7 +366,7 @@ namespace LuaBind return str; } - bool LuaBindState::GetFieldWithType(int idx, cc8* name, int type) + bool State::GetFieldWithType(int idx, cc8* name, int type) { lua_getfield(mState, idx, name); if (lua_type(mState, -1) != type) { @@ -376,7 +376,7 @@ namespace LuaBind return true; } - bool LuaBindState::GetFieldWithType(int idx, int key, int type) + bool State::GetFieldWithType(int idx, int key, int type) { this->GetField(idx, key); if (lua_type(mState, -1) != type) { @@ -386,7 +386,7 @@ namespace LuaBind return true; } - void LuaBindState::SetField(int idx, cc8* key) + void State::SetField(int idx, cc8* key) { if (IsTableOrUserdata(idx)) { @@ -395,7 +395,7 @@ namespace LuaBind } } - cc8* LuaBindState::GetLuaTypeName(int type) + cc8* State::GetLuaTypeName(int type) { switch (type) { case LUA_TNONE: return "none"; @@ -413,7 +413,7 @@ namespace LuaBind } - bool LuaBindState::GetSubfieldWithType(int idx, cc8* format, int type, ...) + bool State::GetSubfieldWithType(int idx, cc8* format, int type, ...) { va_list args; va_start(args, type); @@ -449,7 +449,7 @@ namespace LuaBind return true; } - bool LuaBindState::CheckParams(int idx, cc8* format) + bool State::CheckParams(int idx, cc8* format) { idx = AbsIndex(idx); @@ -520,7 +520,7 @@ namespace LuaBind } template <> - bool LuaBindState::GetValue < bool >(int idx, const bool value) { + bool State::GetValue < bool >(int idx, const bool value) { if (this->IsType(idx, LUA_TBOOLEAN)) { return (lua_toboolean(this->mState, idx) != 0); @@ -530,7 +530,7 @@ namespace LuaBind template <> - cc8* LuaBindState::GetValue < cc8* >(int idx, const cc8* value) { + cc8* State::GetValue < cc8* >(int idx, const cc8* value) { if (this->IsType(idx, LUA_TSTRING)) { return lua_tostring(this->mState, idx); @@ -539,7 +539,7 @@ namespace LuaBind } template <> - std::string LuaBindState::GetValue<std::string>(int idx, const std::string value) + std::string State::GetValue<std::string>(int idx, const std::string value) { std::string str; if (lua_type(this->mState, idx) == LUA_TSTRING) { @@ -552,7 +552,7 @@ namespace LuaBind } template <> - double LuaBindState::GetValue < double >(int idx, const double value) + double State::GetValue < double >(int idx, const double value) { if (this->IsType(idx, LUA_TNUMBER)) { return lua_tonumber(this->mState, idx); @@ -561,7 +561,7 @@ namespace LuaBind } template <> - float LuaBindState::GetValue < float >(int idx, const float value) + float State::GetValue < float >(int idx, const float value) { if (this->IsType(idx, LUA_TNUMBER)) { return (float)lua_tonumber(this->mState, idx); @@ -570,7 +570,7 @@ namespace LuaBind } template <> - s8 LuaBindState::GetValue < s8 >(int idx, const s8 value) + s8 State::GetValue < s8 >(int idx, const s8 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (s8)lua_tonumber(this->mState, idx); @@ -580,7 +580,7 @@ namespace LuaBind template <> - s16 LuaBindState::GetValue < s16 >(int idx, const s16 value) + s16 State::GetValue < s16 >(int idx, const s16 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (s16)lua_tonumber(this->mState, idx); @@ -590,7 +590,7 @@ namespace LuaBind template <> - s32 LuaBindState::GetValue < s32 >(int idx, const s32 value) + s32 State::GetValue < s32 >(int idx, const s32 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (s32)lua_tonumber(this->mState, idx); @@ -599,7 +599,7 @@ namespace LuaBind } template <> - s64 LuaBindState::GetValue < s64 >(int idx, const s64 value) + s64 State::GetValue < s64 >(int idx, const s64 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (s64)lua_tonumber(this->mState, idx); @@ -608,7 +608,7 @@ namespace LuaBind } template <> - u8 LuaBindState::GetValue < u8 >(int idx, const u8 value) + u8 State::GetValue < u8 >(int idx, const u8 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (u8)lua_tonumber(this->mState, idx); @@ -617,7 +617,7 @@ namespace LuaBind } template <> - u16 LuaBindState::GetValue < u16 >(int idx, const u16 value) + u16 State::GetValue < u16 >(int idx, const u16 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (u16)lua_tonumber(this->mState, idx); @@ -626,7 +626,7 @@ namespace LuaBind } template <> - u32 LuaBindState::GetValue < u32 >(int idx, const u32 value) + u32 State::GetValue < u32 >(int idx, const u32 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (u32)lua_tonumber(this->mState, idx); @@ -635,7 +635,7 @@ namespace LuaBind } template <> - u64 LuaBindState::GetValue < u64 >(int idx, const u64 value) + u64 State::GetValue < u64 >(int idx, const u64 value) { if (this->IsType(idx, LUA_TNUMBER)) { return (u64)lua_tonumber(this->mState, idx); @@ -644,7 +644,7 @@ namespace LuaBind } template <> - const void* LuaBindState::GetValue < const void* >(int idx, const void* value) + const void* State::GetValue < const void* >(int idx, const void* value) { if (this->IsType(idx, LUA_TLIGHTUSERDATA)) { return (void*)lua_touserdata(this->mState, idx); @@ -652,14 +652,14 @@ namespace LuaBind return value; } - void LuaBindState::PushPtrUserdata(void* ptr) + void State::PushPtrUserdata(void* ptr) { void** handle = (void**)lua_newuserdata(this->mState, sizeof(void*)); assert(handle); (*handle) = ptr; } - void LuaBindState::RegisterEnum(cc8* name, LuaBindEnum* en) + void State::RegisterEnum(cc8* name, Enum* en) { assert(name); assert(en); @@ -699,21 +699,21 @@ namespace LuaBind } - void LuaBindState::RegisterMethods(const luaL_Reg *l) + void State::RegisterMethods(const luaL_Reg *l) { assert(lua_istable(mState, -1)); // luaL_register第二个参数为空,则向-1位置注册luaL_Reg中这些函数 luaL_register(mState, 0, l); } - void LuaBindState::RegisterMethod(cc8* fname, lua_CFunction func) + void State::RegisterMethod(cc8* fname, lua_CFunction func) { assert(lua_istable(mState, -1)); lua_pushcfunction(mState, func); lua_setfield(mState, -1, fname); } - void LuaBindState::RegisterPreloader(cc8* libname, lua_CFunction preloader) + void State::RegisterPreloader(cc8* libname, lua_CFunction preloader) { lua_getglobal(mState, "package"); lua_getfield(mState, -1, "preload"); @@ -722,36 +722,36 @@ namespace LuaBind lua_pop(mState, 2); } - void LuaBindState::RegisterLib(cc8* libname, const luaL_Reg* l) + void State::RegisterLib(cc8* libname, const luaL_Reg* l) { luaL_register(mState, libname, l); } #if LUA_BIND_ENABLE_PLAIN_CLASS - void LuaBindState::RegisterPlainClassRegistry(cc8* name) + void State::RegisterPlainClassRegistry(cc8* name) { assert(lua_istable(mState, -1)); - lua_pushcfunction(mState, LuaBindPlainClass::registry); + lua_pushcfunction(mState, PlainClass::registry); lua_setfield(mState, -2, name); } #endif #if LUA_BIND_ENABLE_PLAIN_ENUM - void LuaBindState::RegisterPlainEnumRegistry(cc8* name) + void State::RegisterPlainEnumRegistry(cc8* name) { assert(lua_istable(mState, -1)); - lua_pushcfunction(mState, LuaBindPlainEnum::registry); + lua_pushcfunction(mState, PlainEnum::registry); lua_setfield(mState, -2, name); } #endif - int LuaBindState::ErrorType(int idx, cc8* hint) + int State::ErrorType(int idx, cc8* hint) { return luaL_typerror(mState, idx, hint); } template <> - bool LuaBindState::CheckValue < bool >(int idx) + bool State::CheckValue < bool >(int idx) { bool b = false; if (lua_type(mState, idx) == LUA_TBOOLEAN) @@ -766,73 +766,73 @@ namespace LuaBind } template <> - cc8* LuaBindState::CheckValue < cc8* >(int idx) + cc8* State::CheckValue < cc8* >(int idx) { return luaL_checkstring(mState, idx); } template <> - double LuaBindState::CheckValue < double >(int idx) + double State::CheckValue < double >(int idx) { return luaL_checknumber(mState, idx); } template <> - float LuaBindState::CheckValue < float >(int idx) + float State::CheckValue < float >(int idx) { return luaL_checknumber(mState, idx); } template <> - s8 LuaBindState::CheckValue < s8 >(int idx) + s8 State::CheckValue < s8 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - s16 LuaBindState::CheckValue < s16 >(int idx) + s16 State::CheckValue < s16 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - s32 LuaBindState::CheckValue < s32 >(int idx) + s32 State::CheckValue < s32 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - s64 LuaBindState::CheckValue < s64 >(int idx) + s64 State::CheckValue < s64 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - u8 LuaBindState::CheckValue < u8 >(int idx) + u8 State::CheckValue < u8 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - u16 LuaBindState::CheckValue < u16 >(int idx) + u16 State::CheckValue < u16 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - u32 LuaBindState::CheckValue < u32 >(int idx) + u32 State::CheckValue < u32 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - u64 LuaBindState::CheckValue < u64 >(int idx) + u64 State::CheckValue < u64 >(int idx) { return luaL_checkinteger(mState, idx); } template <> - std::string LuaBindState::CheckValue < std::string >(int idx) + std::string State::CheckValue < std::string >(int idx) { return luaL_checkstring(mState, idx); } @@ -841,7 +841,7 @@ namespace LuaBind /// check light userdata /// template <> - const void* LuaBindState::CheckValue < const void* >(int idx) + const void* State::CheckValue < const void* >(int idx) { if (IsType(idx, LUA_TLIGHTUSERDATA)) { |