Do garbage collection on luacore
Another lua state that is not freed until end of game, so clean up the stack and do GC regularly.
This commit is contained in:
@@ -512,6 +512,7 @@ moveloop_core(void)
|
||||
lua_getglobal(gl.luacore, "nh_callback_run");
|
||||
lua_pushstring(gl.luacore, nhcb_name[NHCB_END_TURN]);
|
||||
nhl_pcall_handle(gl.luacore, 1, 0, "moveloop_core", NHLpa_panic);
|
||||
lua_settop(gl.luacore, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -487,8 +487,11 @@ can_do_extcmd(const struct ext_func_tab *extcmd)
|
||||
lua_pushstring(gl.luacore, nhcb_name[NHCB_CMD_BEFORE]);
|
||||
lua_pushstring(gl.luacore, extcmd->ef_txt);
|
||||
nhl_pcall_handle(gl.luacore, 2, 1, "can_do_extcmd", NHLpa_panic);
|
||||
if (!lua_toboolean(gl.luacore, -1))
|
||||
if (!lua_toboolean(gl.luacore, -1)) {
|
||||
lua_settop(gl.luacore, 0);
|
||||
return FALSE;
|
||||
}
|
||||
lua_settop(gl.luacore, 0);
|
||||
}
|
||||
|
||||
if (!wizard && (ecflags & WIZMODECMD)) {
|
||||
|
||||
1
src/do.c
1
src/do.c
@@ -1558,6 +1558,7 @@ goto_level(
|
||||
lua_getglobal(gl.luacore, "nh_callback_run");
|
||||
lua_pushstring(gl.luacore, nhcb_name[NHCB_LVL_LEAVE]);
|
||||
nhl_pcall_handle(gl.luacore, 1, 0, "goto_level", NHLpa_panic);
|
||||
lua_settop(gl.luacore, 0);
|
||||
}
|
||||
|
||||
/* tethered movement makes level change while trapped feasible */
|
||||
|
||||
@@ -1243,6 +1243,7 @@ makelevel(void)
|
||||
lua_getglobal(gl.luacore, "nh_callback_run");
|
||||
lua_pushstring(gl.luacore, nhcb_name[NHCB_LVL_ENTER]);
|
||||
nhl_pcall_handle(gl.luacore, 1, 0, "makelevel", NHLpa_panic);
|
||||
lua_settop(gl.luacore, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
src/nhlua.c
11
src/nhlua.c
@@ -174,6 +174,7 @@ l_nhcore_call(int callidx)
|
||||
nhcore_call_names[callidx]);*/
|
||||
nhcore_call_available[callidx] = FALSE;
|
||||
}
|
||||
lua_settop(gl.luacore, 0);
|
||||
}
|
||||
|
||||
DISABLE_WARNING_UNREACHABLE_CODE
|
||||
@@ -1115,6 +1116,7 @@ nhl_variable(lua_State *L)
|
||||
lua_getglobal(gl.luacore, "nh_lua_variables");
|
||||
if (!lua_istable(gl.luacore, -1)) {
|
||||
impossible("nh_lua_variables is not a lua table");
|
||||
lua_settop(gl.luacore, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1139,6 +1141,7 @@ nhl_variable(lua_State *L)
|
||||
nhl_pcall_handle(L, 0, 1, "nhl_variable-1", NHLpa_panic);
|
||||
} else
|
||||
nhl_error(L, "Cannot get variable of that type");
|
||||
lua_settop(gl.luacore, 0);
|
||||
return 1;
|
||||
} else if (argc == 2) {
|
||||
/* set nh_lua_variables[key] = value;
|
||||
@@ -1168,6 +1171,7 @@ nhl_variable(lua_State *L)
|
||||
nhl_pcall_handle(gl.luacore, 0, 0, "nhl_variable-3", NHLpa_panic);
|
||||
} else
|
||||
nhl_error(L, "Cannot set variable of that type");
|
||||
lua_settop(gl.luacore, 0);
|
||||
return 0;
|
||||
} else
|
||||
nhl_error(L, "Wrong number of arguments");
|
||||
@@ -1189,6 +1193,7 @@ get_nh_lua_variables(void)
|
||||
lua_getglobal(gl.luacore, "nh_lua_variables");
|
||||
if (!lua_istable(gl.luacore, -1)) {
|
||||
impossible("nh_lua_variables is not a lua table");
|
||||
lua_settop(gl.luacore, 0);
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -1196,10 +1201,12 @@ get_nh_lua_variables(void)
|
||||
if (lua_type(gl.luacore, -1) == LUA_TFUNCTION) {
|
||||
if (nhl_pcall_handle(gl.luacore, 0, 1, "get_nh_lua_variables",
|
||||
NHLpa_impossible)) {
|
||||
lua_settop(gl.luacore, 0);
|
||||
return key;
|
||||
}
|
||||
key = dupstr(lua_tostring(gl.luacore, -1));
|
||||
}
|
||||
lua_settop(gl.luacore, 0);
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -1237,6 +1244,7 @@ restore_luadata(NHFILE *nhfp)
|
||||
luaL_loadstring(gl.luacore, lua_data);
|
||||
free(lua_data);
|
||||
nhl_pcall_handle(gl.luacore, 0, 0, "restore_luadata", NHLpa_panic);
|
||||
lua_settop(gl.luacore, 0);
|
||||
}
|
||||
|
||||
/* local stairs = stairways(); */
|
||||
@@ -1552,6 +1560,7 @@ nhl_callback(lua_State *L)
|
||||
lua_pushstring(gl.luacore, cb);
|
||||
lua_pushstring(gl.luacore, fn);
|
||||
nhl_pcall_handle(gl.luacore, 2, 0, "nhl_callback", NHLpa_panic);
|
||||
lua_settop(gl.luacore, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1951,6 +1960,8 @@ nhl_pcall_handle(lua_State *L, int nargs, int nresults, const char *name,
|
||||
lua_tostring(L, -1));
|
||||
}
|
||||
}
|
||||
if (L == gl.luacore)
|
||||
lua_gc(L, LUA_GCCOLLECT);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user