Lots more work on eng::malloc

This commit is contained in:
2022-02-28 21:57:54 -05:00
parent ff932dba10
commit 7cd8eb0a43
25 changed files with 314 additions and 253 deletions

View File

@@ -34,11 +34,21 @@ static int panicf(lua_State *L) {
exit(1);
}
// An allocator for lua states that uses system malloc and system free.
static void *l_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
if (nsize == 0) {
free(ptr);
return NULL;
} else {
return realloc(ptr, nsize);
}
}
lua_State *LuaStack::newstate (lua_Alloc allocf) {
lua_State *L = lua_newstate(allocf, NULL);
if (L) lua_atpanic(L, &panicf);
return L;
if (allocf == nullptr) allocf = l_alloc;
lua_State *L = lua_newstate(allocf, NULL);
if (L) lua_atpanic(L, &panicf);
return L;
}
bool LuaStack::ckboolean(LuaSlot s) const {