mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-29 12:40:01 +01:00
Return a reason for failure from sim.loadStamp
This commit is contained in:
parent
cb52495472
commit
dcf0764fd8
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -216,5 +216,6 @@ public:
|
||||
virtual ~LuaScriptInterface();
|
||||
};
|
||||
|
||||
extern LuaScriptInterface *luacon_ci;
|
||||
|
||||
#endif /* LUASCRIPTINTERFACE_H_ */
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user