/apps/twnlua: report error on loading

This commit is contained in:
veclavtalica 2025-01-26 08:48:59 +03:00
parent b0e718876a
commit 4d700936c9
2 changed files with 27 additions and 15 deletions

View File

@ -150,13 +150,22 @@ void game_tick(void) {
log_critical("%s", lua_tostring(state->L, -1)); log_critical("%s", lua_tostring(state->L, -1));
lua_pop(state->L, 1); lua_pop(state->L, 1);
} }
state->loaded_successfully = true;
} else {
/* got some sort of error, it should be pushed on top of the stack */
SDL_assert(lua_isstring(state->L, -1));
log_critical("Error loading /scripts/game.lua entry: %s", luaL_tolstring(state->L, -1, NULL));
lua_pop(state->L, 1);
} }
free(game_buf); free(game_buf);
/* from this point we have access to everything defined in lua */ /* from this point we have access to everything defined in lua */
} }
State *state = ctx.udata; State *state = ctx.udata;
if (state->loaded_successfully) {
bindgen_build_context(state->L); bindgen_build_context(state->L);
lua_getglobal(state->L, "ctx"); lua_getglobal(state->L, "ctx");
if (!lua_isnoneornil(state->L, -1)) { if (!lua_isnoneornil(state->L, -1)) {
@ -175,6 +184,7 @@ void game_tick(void) {
lua_getglobal(state->L, "ctx"); lua_getglobal(state->L, "ctx");
bindgen_upload_context(state->L); bindgen_upload_context(state->L);
} }
}
void game_end(void) { void game_end(void) {

View File

@ -3,9 +3,11 @@
#include <lua.h> #include <lua.h>
#include <stdbool.h>
typedef struct State { typedef struct State {
lua_State *L; lua_State *L;
bool loaded_successfully;
} State; } State;