diff --git a/lib/lua_runner.cpp b/lib/lua_runner.cpp index 39218a9..5fd6403 100755 --- a/lib/lua_runner.cpp +++ b/lib/lua_runner.cpp @@ -136,7 +136,7 @@ int Lua_runner::unload_lib(const char *name) { return -1; } - lua_remove(this->L,this->pkgs[sig].ref); + lua_remove(this->L,this->pkgs[sig].ref - 1); // ref = gettop+1, 故用 ref-1 定位实际栈位置 for(int j = sig+1;jpkg_cont;j++) { this->pkgs[j-1] = this->pkgs[j];//保持数据结构 @@ -162,10 +162,8 @@ int Lua_runner::clean()//进行新一轮调用前一定要先clean清除上个 luaL_dostring(this->L, clean_globals_code);//清空全局变量 luaL_dostring(this->L, "package.loaded = {}");//清空当前引用的包 - for(int i = 0 ;ipkg_cont;i++) - { - lua_remove(this->L,this->pkgs[i].ref); - } + // 注: 原先此处有逐个 lua_remove(pkgs[i].ref) 的循环,但 ref=gettop+1 恒越界且多次移除后索引偏移, + // 实为死代码;末尾 lua_settop(L,0) 已完整清栈(LuaJIT 下越界 remove 会损坏内存导致崩溃,故删除) this->pkg_cont = 0; // 清理预加载函数 for(int i = 0; i < this->func_cont; i++)