/apps/twnlua: fix for windows, parametrize newstate for alloc func

This commit is contained in:
veclavtalica
2025-02-17 10:39:10 +03:00
parent 1cd4bfa638
commit 47799deb8b
4 changed files with 12 additions and 15 deletions

View File

@ -147,12 +147,12 @@ static void exchange_lua_states(lua_State *from, lua_State *to, int level, int i
void game_tick(void) {
if (ctx.initialization_needed) {
if (!ctx.udata)
ctx.udata = calloc(1, sizeof (State));
ctx.udata = SDL_calloc(1, sizeof (State));
State *state = ctx.udata;
/* let's init lua */
lua_State *new_state = luaL_newstate();
lua_State *new_state = luaL_newstate(custom_alloc);
lua_setallocf(new_state, custom_alloc, NULL);
/* state existed already, copy its udata over */
@ -161,7 +161,6 @@ void game_tick(void) {
lua_getfield(state->L, -1, "udata");
SDL_assert(!lua_isnoneornil(state->L, -1));
SDL_assert(!lua_isnoneornil(state->L, -2));
// SDL_TriggerBreakpoint();
if (!lua_isnoneornil(state->L, -1)) {
log_info("Exchanging lua states...");
lua_newtable(new_state);
@ -228,7 +227,7 @@ void game_tick(void) {
lua_pop(state->L, 1);
}
free(game_buf);
SDL_free(game_buf);
/* from this point we have access to everything defined in lua */
}
@ -261,5 +260,5 @@ void game_end(void) {
State *state = ctx.udata;
bindgen_unload_twn(state->L);
lua_close(state->L);
free(state);
SDL_free(state);
}