foxygit / fake-08-xbox360 Log in
commit 387edb3edd5a226502d83e38dc35791c0e9bbc49
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Mon Apr 27 14:54:51 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Mon Apr 27 14:54:51 2020 -0600

    Log errors if we can't load the lua
---
 source/console.cpp | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/source/console.cpp b/source/console.cpp
index 5716da0..67e78b3 100644
--- a/source/console.cpp
+++ b/source/console.cpp
@@ -64,7 +64,15 @@ void Console::LoadCart(std::string filename){
     luaL_openlibs(_luaState);

     //load in global lua fuctions for pico 8
-    luaL_dostring(_luaState, p8GlobalLuaFunctions);
+    int loadedGlobals = luaL_dostring(_luaState, p8GlobalLuaFunctions);
+
+    if (loadedGlobals != LUA_OK) {
+        Logger::Write("ERROR loading pico 8 lua globals\n");
+        Logger::Write("Error: %s\n", lua_tostring(_luaState, -1));
+        lua_pop(_luaState, 1);
+
+        return;
+    }

     //graphics
     lua_register(_luaState, "cls", cls);
@@ -121,7 +129,15 @@ void Console::LoadCart(std::string filename){
     lua_register(_luaState, "dget", dget);
     lua_register(_luaState, "dset", dset);

-    luaL_dostring(_luaState, _loadedCart->LuaString.c_str());
+    int loadedCart = luaL_dostring(_luaState, _loadedCart->LuaString.c_str());
+
+    if (loadedCart != LUA_OK) {
+        Logger::Write("ERROR loading cart\n");
+        Logger::Write("Error: %s\n", lua_tostring(_luaState, -1));
+        lua_pop(_luaState, 1);
+
+        return;
+    }


     // Push the _init function on the top of the lua stack (or nil if it doesn't exist)