From 1e0ebaf6154d6cbd20073f67d878fb0408e3606a Mon Sep 17 00:00:00 2001 From: ruitaocai Date: Mon, 31 Oct 2022 11:45:26 +0800 Subject: [PATCH] fix expose issue, first time is right, each call after the first will left G on the stack, increase the stack --- include/ponder/uses/lua.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/ponder/uses/lua.hpp b/include/ponder/uses/lua.hpp index 03678c7b..1c855f5f 100644 --- a/include/ponder/uses/lua.hpp +++ b/include/ponder/uses/lua.hpp @@ -421,7 +421,8 @@ void expose(lua_State *L, const Class& cls, const IdRef name) lua_pushglobaltable(L); // +1 lua_pushliteral(L, PONDER__LUA_METATBLS); // +1 lua_rawget(L, -2); // 0 -+ - if (lua_isnil(L, -1)) + bool isnil = lua_isnil(L, -1); + if (isnil) { // first time lua_pop(L, 1); // -1 pop nil @@ -459,7 +460,7 @@ void expose(lua_State *L, const Class& cls, const IdRef name) lua_setmetatable(L, -2); // -1 lua_rawset(L, -3); // -2 _G[CLASSNAME] = class_obj - lua_pop(L, 2); // -2 global,meta + lua_pop(L, isnil ? 2 : 3); // -2 global,meta } void expose(lua_State *L, const Enum& enm, const IdRef name)