/apps/twnlua: report error on loading
This commit is contained in:
		@@ -150,30 +150,40 @@ void game_tick(void) {
 | 
			
		||||
                log_critical("%s", lua_tostring(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);
 | 
			
		||||
 | 
			
		||||
        /* from this point we have access to everything defined in lua */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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");
 | 
			
		||||
    if (lua_pcall(state->L, 0, 0, 0) != LUA_OK) {
 | 
			
		||||
        log_critical("%s", lua_tostring(state->L, -1));
 | 
			
		||||
    if (state->loaded_successfully) {
 | 
			
		||||
        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, "ctx");
 | 
			
		||||
    bindgen_upload_context(state->L);
 | 
			
		||||
        lua_getglobal(state->L, "game_tick");
 | 
			
		||||
        if (lua_pcall(state->L, 0, 0, 0) != LUA_OK) {
 | 
			
		||||
            log_critical("%s", lua_tostring(state->L, -1));
 | 
			
		||||
            lua_pop(state->L, 1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        lua_getglobal(state->L, "ctx");
 | 
			
		||||
        bindgen_upload_context(state->L);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,11 @@
 | 
			
		||||
 | 
			
		||||
#include <lua.h>
 | 
			
		||||
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
 | 
			
		||||
typedef struct State {
 | 
			
		||||
    lua_State *L;
 | 
			
		||||
    bool loaded_successfully;
 | 
			
		||||
} State;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user