diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 8f3aecf80..180daa585 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -46,6 +46,10 @@ #include "client/http/Request.h" #include "client/http/RequestManager.h" +#ifdef LUACONSOLE +# include "lua/LuaScriptInterface.h" +#endif + extern "C" { @@ -1477,8 +1481,11 @@ SaveFile * Client::LoadSaveFile(ByteString filename) GameSave * tempSave = new GameSave(ReadFile(filename)); file->SetGameSave(tempSave); } - catch (ParseException & e) + catch (const ParseException &e) { +#ifdef LUACONSOLE + luacon_ci->SetLastError(ByteString(e.what()).FromUtf8()); +#endif std::cerr << "Client: Invalid save file '" << filename << "': " << e.what() << std::endl; file->SetLoadingError(ByteString(e.what()).FromUtf8()); } diff --git a/src/lua/CommandInterface.h b/src/lua/CommandInterface.h index 8ae32841a..bfe1145fc 100644 --- a/src/lua/CommandInterface.h +++ b/src/lua/CommandInterface.h @@ -30,6 +30,10 @@ public: virtual int Command(String command); virtual String FormatCommand(String command); + void SetLastError(String err) + { + lastError = err; + } String GetLastError(); virtual ~CommandInterface(); }; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index ed135e7ad..6b9955a04 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1741,6 +1741,7 @@ int LuaScriptInterface::simulation_saveStamp(lua_State * l) int LuaScriptInterface::simulation_loadStamp(lua_State * l) { int i = -1; + int pushed = 1; SaveFile * tempfile = NULL; int x = luaL_optint(l,2,0); int y = luaL_optint(l,3,0); @@ -1772,12 +1773,20 @@ int LuaScriptInterface::simulation_loadStamp(lua_State * l) } } else + { + pushed = 2; lua_pushnil(l); + lua_pushstring(l, luacon_ci->GetLastError().ToUtf8().c_str()); + } delete tempfile; } else + { + pushed = 2; lua_pushnil(l); - return 1; + lua_pushliteral(l, "Failed to read file"); + } + return pushed; } int LuaScriptInterface::simulation_deleteStamp(lua_State * l) diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index a1cf6d412..2eecd30b9 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -216,5 +216,6 @@ public: virtual ~LuaScriptInterface(); }; +extern LuaScriptInterface *luacon_ci; #endif /* LUASCRIPTINTERFACE_H_ */ diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 444d06be9..b983b95da 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -55,8 +55,11 @@ int Simulation::Load(GameSave * save, bool includePressure, int fullX, int fullY { save->Expand(); } - catch (ParseException &) + catch (const ParseException &e) { +#ifdef LUACONSOLE + luacon_ci->SetLastError(ByteString(e.what()).FromUtf8()); +#endif return 1; }