Make Lua `savestate.*` functions return `false` when C# call throws
This commit is contained in:
parent
6b4d0faba9
commit
f409cc445d
|
@ -17,9 +17,18 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
_luaLibsImpl.IsUpdateSupressed = true;
|
||||
var success = APIs.SaveState.Load(path, suppressOSD);
|
||||
_luaLibsImpl.IsUpdateSupressed = false;
|
||||
return success;
|
||||
try
|
||||
{
|
||||
return APIs.SaveState.Load(path, suppressOSD);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_luaLibsImpl.IsUpdateSupressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("savestate.loadslot( 7 );")]
|
||||
|
@ -32,33 +41,56 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
_luaLibsImpl.IsUpdateSupressed = true;
|
||||
var success = APIs.SaveState.LoadSlot(slotNum, suppressOSD: suppressOSD);
|
||||
_luaLibsImpl.IsUpdateSupressed = false;
|
||||
return success;
|
||||
try
|
||||
{
|
||||
return APIs.SaveState.LoadSlot(slotNum, suppressOSD: suppressOSD);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_luaLibsImpl.IsUpdateSupressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("savestate.save( \"C:\\state.bin\" );")]
|
||||
[LuaMethod("save", "Saves a state at the given path. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
|
||||
public void Save(string path, bool suppressOSD = false)
|
||||
public bool Save(string path, bool suppressOSD = false)
|
||||
{
|
||||
if (_luaLibsImpl.IsInInputOrMemoryCallback)
|
||||
{
|
||||
throw new InvalidOperationException("savestate.save() is not allowed during input/memory callbacks");
|
||||
}
|
||||
|
||||
APIs.SaveState.Save(path, suppressOSD);
|
||||
try
|
||||
{
|
||||
APIs.SaveState.Save(path, suppressOSD);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodExample("savestate.saveslot( 7 );")]
|
||||
[LuaMethod("saveslot", "Saves a state at the given save slot (must be an integer between 1 and 10). If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes with the slot number.")]
|
||||
public void SaveSlot(int slotNum, bool suppressOSD = false)
|
||||
public bool SaveSlot(int slotNum, bool suppressOSD = false)
|
||||
{
|
||||
if (_luaLibsImpl.IsInInputOrMemoryCallback)
|
||||
{
|
||||
throw new InvalidOperationException("savestate.saveslot() is not allowed during input/memory callbacks");
|
||||
}
|
||||
|
||||
APIs.SaveState.SaveSlot(slotNum, suppressOSD);
|
||||
try
|
||||
{
|
||||
APIs.SaveState.SaveSlot(slotNum, suppressOSD);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue