diff options
Diffstat (limited to 'source/3rd-party/Luax/luax_class.inl')
-rw-r--r-- | source/3rd-party/Luax/luax_class.inl | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/source/3rd-party/Luax/luax_class.inl b/source/3rd-party/Luax/luax_class.inl index d1c8c4b..45e6552 100644 --- a/source/3rd-party/Luax/luax_class.inl +++ b/source/3rd-party/Luax/luax_class.inl @@ -116,7 +116,12 @@ namespace Luax u32 count = state.GetValue<u32>(-1, 0); // get the count (or 0) lua_pop(state, 1); // pop the old count - if (count == 0) return; // nothing to do + // no such reference + if (count == 0) + { + state.Pop(2); // userdata, reftable + return; // nothing to do + } if (count > 1) { lua_pushnumber(state, count - 1); // push the new count @@ -125,7 +130,12 @@ namespace Luax lua_pushnil(state); // maybe cause gc } lua_settable(state, -3); // save it in the table + + state.Pop(1); // reftable + return; } + state.Pop(2); // nil, reftable + return; } } @@ -194,9 +204,10 @@ namespace Luax /// /// userdataԴref tablemember tableclass table - /// ref table kvǿtableuserdataüͨuserdataΪkeyΪvalueԼԱ + /// ref table kvǿtableuserdataüͨuserdataΪkey + /// ΪvalueԼԱ /// member table luaʵijԱ - /// class table б͵ʵеĺ + /// class table б͵ʵеĺ /// template<typename T> void LuaxNativeClass<T>::BindToLua(LuaxState& state) @@ -205,8 +216,13 @@ namespace Luax assert(!T::IsLuaxClassSingleton()); assert(!mUserdata); - // userdataջעַҪתΪT*ֱthisܻᵼ¶ؼ̳еɥʧ̬ - state.PushPtrUserdata(static_cast<T*>(this)); + /// + /// userdataջעַҪתΪT*ֱthisܻᵼ¶ؼ̳еɥʧ̬ + /// ֱӴthisȥڶؼ̳£òһͷ麯ġҪthis + /// תΪĵ͵ַõһ麯ͨһʵֶ̬ + /// + T* p = static_cast<T*>(this); + state.PushPtrUserdata(p); lua_newtable(state); // ref tableluaʣC lua_newtable(state); // member tableluaдĶԱ @@ -222,10 +238,13 @@ namespace Luax int memberTable = top - 1; int refTable = top - 2; - // ref table ע __tostring - lua_pushcfunction(state, l___tostring); + // ref table ע __tostring __gc + lua_pushcfunction(state, _Tostring); lua_setfield(state, refTable, "__tostring"); + lua_pushcfunction(state, _GC); + lua_setfield(state, refTable, "__gc"); + // ref table __index __newindex Ϊ member table lua_pushvalue(state, memberTable); lua_setfield(state, refTable, "__index"); @@ -233,9 +252,6 @@ namespace Luax lua_pushvalue(state, memberTable); lua_setfield(state, refTable, "__newindex"); - lua_pushcfunction(state, l___gc); - lua_setfield(state, refTable, "__gc"); - // Ԫ lua_setmetatable(state, -2); // class is meta of member lua_setmetatable(state, -2); // member is meta of ref @@ -321,8 +337,12 @@ namespace Luax /// ͷŹʵ /// template<typename T> - int LuaxNativeClass<T>::l___gc(lua_State* L) + int LuaxNativeClass<T>::_GC(lua_State* L) { +#if LUAX_PROFILER + std::cout << "Luax: GC<" << T::GetLuaxClassName() << ">\n"; +#endif + LUAX_SETUP(L, "U"); T* self = state.GetUserdata<T>(1); delete self; @@ -334,7 +354,7 @@ namespace Luax /// ַ /// template<typename T> - int LuaxNativeClass<T>::l___tostring(lua_State* L) + int LuaxNativeClass<T>::_Tostring(lua_State* L) { // params: // 1: userdata |