From 41d0e247804632af1aae12e9df239bd3a99fa370 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Sat, 11 Jan 2025 16:22:41 +0300 Subject: [PATCH] /apps/twnlua: ctx.udata preservation (not yet for reload case) --- apps/twnlua/game.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/twnlua/game.c b/apps/twnlua/game.c index 6df50a5..8ce97c2 100644 --- a/apps/twnlua/game.c +++ b/apps/twnlua/game.c @@ -112,6 +112,12 @@ void game_tick(void) { State *state = ctx.udata; bindgen_build_context(state->L); + lua_getglobal(state->L, "ctx"); + if (!lua_isnoneornil(state->L, -1)) { + lua_getfield(state->L, -1, "udata"); + lua_setfield(state->L, -3, "udata"); + } + lua_pop(state->L, 1); lua_setglobal(state->L, "ctx"); lua_getglobal(state->L, "game_tick");