Skip to content

Commit

Permalink
Merge pull request #19 from 32blit/patch-error-handling
Browse files Browse the repository at this point in the history
Improve error handling
  • Loading branch information
Daft-Freak authored Sep 6, 2024
2 parents 909e06f + 6ed2b0d commit 293e467
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ void init() {
if(!launchPath) {
launchPath = "main.lua";
}
luaL_loadfile(L, launchPath);
auto err = luaL_loadfile(L, launchPath);

if(err) {
blit::debugf("Error loading %s: %s\n", launchPath, lua_tostring(L, -1));
has_render = has_update = false;
return;
}

// Super important priming call that makes stuff not explode
if(lua_pcall(L, 0, 0, 0) != 0){
Expand Down Expand Up @@ -54,7 +60,12 @@ void init() {
}

void render(uint32_t time) {
if(!has_render) return;
if(!has_render) {
blit::screen.pen = {0, 0, 0};
blit::screen.clear();
return;
}

uint32_t ms_start = now();
lua_getglobal(L, "render");
lua_pushnumber(L, time);
Expand Down

0 comments on commit 293e467

Please sign in to comment.