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:
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