Compare commits

...
Author SHA1 Message Date
indev 72288e2bae Count lua memory for total usage in memfree command 2026-09-21 17:14:43 +03:00
indev 0e7460009e Change lua to not use z_zone allocator 2026-09-07 18:03:50 +03:00
3 changed files with 20 additions and 12 deletions

No files matched your search

+15 -10
View File
@@ -62,14 +62,6 @@ static lua_CFunction liblist[] = {
NULL
};
// Lua asks for memory using this.
static void *LUA_Alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
(void)ud;
(void)osize;
return Z_Realloc(ptr, nsize, PU_LUA, NULL);
}
// Panic function Lua calls when there's an unprotected error.
// This function cannot return. Lua would kill the application anyway if it did.
FUNCNORETURN static int LUA_Panic(lua_State *L)
@@ -197,7 +189,7 @@ void LUA_ClearState(void)
CONS_Printf(M_GetText("Pardon me while I initialize the Lua scripting interface...\n"));
// allocate state
L = lua_newstate(LUA_Alloc, NULL);
L = luaL_newstate();
lua_atpanic(L, LUA_Panic);
// open base libraries
@@ -373,7 +365,7 @@ void LUA_DumpFile(const char *filename)
static void createMathLibState(void)
{
mL = lua_newstate(LUA_Alloc, NULL);
mL = luaL_newstate();
lua_atpanic(mL, LUA_Panic);
// open only enum lib
@@ -1465,3 +1457,16 @@ int Lua_CreateFieldTable(lua_State *L, const char *const lst[])
return luaL_ref(L, LUA_REGISTRYINDEX);
}
size_t LUA_MemoryUsage(void)
{
size_t usage = 0;
if (gL)
usage += lua_gc(gL, LUA_GCCOUNT, 0);
if (mL)
usage += lua_gc(mL, LUA_GCCOUNT, 0);
return usage;
}
+3
View File
@@ -82,6 +82,9 @@ int Lua_optoption(lua_State *L, int narg, int def, int list_ref);
int Lua_CreateFieldTable(lua_State *L, const char *const lst[]);
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save);
// Returns lua memory usage in kbytes
size_t LUA_MemoryUsage(void);
// Console wrapper
void COM_Lua_f(void);
+2 -2
View File
@@ -663,8 +663,8 @@ static void Command_Memfree_f(void)
Z_CheckHeap(-1);
CONS_Printf("\x82%s", M_GetText("Memory Info\n"));
CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage()>>10));
CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(Z_TagUsage(PU_LUA)>>10));
CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1((Z_TotalUsage()>>10) + LUA_MemoryUsage()));
CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(LUA_MemoryUsage())); // No longer uses z_zone memory but for consistency keep it here
CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10));
CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10));
CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10));