Debugger: Lua - Added "ScriptEnded" event

This commit is contained in:
Sour 2018-04-04 23:35:41 -04:00
parent 79dd71dc3b
commit cbb0f0e68d
6 changed files with 32 additions and 3 deletions

View file

@ -546,6 +546,8 @@ void Console::Run()
_hdPackBuilder.reset();
_hdData.reset();
_debugger.reset();
_stopLock.Release();
_runLock.Release();

View file

@ -114,6 +114,17 @@ Debugger::~Debugger()
_stopFlag = true;
Console::Pause();
{
auto lock = _scriptLock.AcquireSafe();
for(shared_ptr<ScriptHost> script : _scripts) {
//Send a ScriptEnded event to all active scripts
script->ProcessEvent(EventType::ScriptEnded);
}
_scripts.clear();
_hasScript = false;
}
if(Debugger::Instance == this) {
Debugger::Instance = nullptr;
}
@ -1245,6 +1256,9 @@ int Debugger::LoadScript(string name, string content, int32_t scriptId)
return script->GetScriptId() == scriptId;
});
if(result != _scripts.end()) {
//Send a ScriptEnded event before reloading the code
(*result)->ProcessEvent(EventType::ScriptEnded);
(*result)->LoadScript(name, content, this);
return scriptId;
}
@ -1257,7 +1271,14 @@ void Debugger::RemoveScript(int32_t scriptId)
{
DebugBreakHelper helper(this);
auto lock = _scriptLock.AcquireSafe();
_scripts.erase(std::remove_if(_scripts.begin(), _scripts.end(), [=](const shared_ptr<ScriptHost>& script) { return script->GetScriptId() == scriptId; }), _scripts.end());
_scripts.erase(std::remove_if(_scripts.begin(), _scripts.end(), [=](const shared_ptr<ScriptHost>& script) {
if(script->GetScriptId() == scriptId) {
//Send a ScriptEnded event before unloading the script
script->ProcessEvent(EventType::ScriptEnded);
return true;
}
return false;
}), _scripts.end());
_hasScript = _scripts.size() > 0;
}

View file

@ -147,6 +147,7 @@ enum class EventType
StateSaved = 7,
InputPolled = 8,
SpriteZeroHit = 9,
ScriptEnded = 10,
EventTypeSize
};

View file

@ -161,6 +161,7 @@ int LuaApi::GetLibrary(lua_State *lua)
lua_pushintvalue(stateLoaded, EventType::StateLoaded);
lua_pushintvalue(stateSaved, EventType::StateSaved);
lua_pushintvalue(inputPolled, EventType::InputPolled);
lua_pushintvalue(scriptEnded, EventType::ScriptEnded);
lua_settable(lua, -3);
lua_pushliteral(lua, "executeCountType");

View file

@ -22,7 +22,9 @@ endFrame = 4, Triggered at the end of a frame (cycle 0, scanline 241)
codeBreak = 5, Triggered when code execution breaks (e.g due to a breakpoint, etc.)
stateLoaded = 6, Triggered when a user manually loads a savestate
stateSaved = 7, Triggered when a user manually saves a savestate
inputPolled = 8 Triggered when the emulation core polls the state of the input devices for the next frame
inputPolled = 8, Triggered when the emulation core polls the state of the input devices for the next frame
spriteZeroHit = 9, Triggered when the PPU sets the sprite zero hit flag
scriptEnded = 10 Triggered when the current Lua script ends (script window closed, execution stopped, etc.)
```
**Description**

View file

@ -504,7 +504,7 @@ namespace Mesen.GUI.Debugger
new List<string> {"func","emu.getRomInfo","emu.getRomInfo()","","*Table* Information about the current ROM","Returns information about the ROM file that is currently running."},
new List<string> {"func","emu.getScriptDataFolder","emu.getScriptDataFolder()","","*String* The scripts data folder.","This function returns the path to a unique folder (based on the scripts filename) where the script should store its data (if any data needs to be saved).\nThe data will be saved in subfolders inside the LuaScriptData folder in Mesens home folder."},
new List<string> {"func","emu.takeScreenshot","emu.takeScreenshot()","","*String* A binary string containing a PNG image.","Takes a screenshot and returns a PNG file as a string.\nThe screenshot is not saved to the disk."},
new List<string> {"enum","emu.eventType","emu.eventType.[value]","","","Values:\nreset = 0,\nnmi = 1,\nirq = 2,\nstartFrame = 3,\nendFrame = 4,\ncodeBreak = 5\nstateLoaded = 6,\nstateSaved = 7,\ninputPolled = 8\n\nUsed by addEventCallback / removeEventCallback calls."},
new List<string> {"enum","emu.eventType","emu.eventType.[value]","","","Values:\nreset = 0,\nnmi = 1,\nirq = 2,\nstartFrame = 3,\nendFrame = 4,\ncodeBreak = 5\nstateLoaded = 6,\nstateSaved = 7,\ninputPolled = 8,\nspriteZeroHit = 9,\nscriptEnded = 10\n\nUsed by addEventCallback / removeEventCallback calls."},
new List<string> {"enum","emu.eventType.reset","Triggered when a soft reset occurs","","",""},
new List<string> {"enum","emu.eventType.nmi","Triggered when an nmi occurs","","",""},
new List<string> {"enum","emu.eventType.irq","Triggered when an irq occurs","","",""},
@ -514,6 +514,8 @@ namespace Mesen.GUI.Debugger
new List<string> {"enum","emu.eventType.stateLoaded","Triggered when a user manually loads a savestate","","",""},
new List<string> {"enum","emu.eventType.stateSaved","Triggered when a user manually saves a savestate","","",""},
new List<string> {"enum","emu.eventType.inputPolled","Triggered when the emulation core polls the state of the input devices for the next frame","","",""},
new List<string> {"enum","emu.eventType.spriteZeroHit","Triggered when the PPU sets the sprite zero hit flag","","",""},
new List<string> {"enum","emu.eventType.scriptEnded","Triggered when the current Lua script ends (script window closed, execution stopped, etc.)","","",""},
new List<string> {"enum","emu.executeCountType","emu.executeCountType.[value]","","","Values:\ncpuCycles = 0,\nppuCycles = 1,\ncpuInstructions = 2\n\nUsed by execute calls." },
new List<string> {"enum","emu.executeCountType.cpuCycles","Count the number of CPU cycles","","",""},
new List<string> {"enum","emu.executeCountType.ppuCycles","Count the number of PPU cycles","","",""},