Lua: add basic callback functions; emu.registerbefore, emu.registerafter, emu.registerstart, emu.registerexit

This commit is contained in:
gocha 2012-08-05 15:45:56 +09:00
parent 128c544998
commit 2afcfc4589
4 changed files with 26 additions and 7 deletions

View File

@ -186,6 +186,7 @@
#include "snapshot.h"
#include "cheats.h"
#include "logger.h"
#include "lua-engine.h"
#ifdef DEBUGGER
#include "debug.h"
#endif
@ -302,6 +303,10 @@ void S9xReset (void)
S9xResetSRTC();
S9xInitCheatData();
#ifdef HAVE_LUA
CallRegisteredLuaFunctions(LUACALL_ONSTART);
#endif
}
void S9xSoftReset (void)

View File

@ -183,6 +183,7 @@
#include "apu/apu.h"
#include "fxemu.h"
#include "snapshot.h"
#include "lua-engine.h"
#ifdef DEBUGGER
#include "debug.h"
#include "missing.h"
@ -322,6 +323,10 @@ static inline void StartS9xMainLoop (void)
pad_read_last = pad_read;
pad_read = FALSE;
#ifdef HAVE_LUA
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
#endif
IPPU.InMainLoop = TRUE;
}
@ -331,6 +336,10 @@ static inline void EndS9xMainLoop (void)
if(!pad_read)
IPPU.PadIgnoredFrames++;
#ifdef HAVE_LUA
CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION);
#endif
IPPU.InMainLoop = FALSE;
}

View File

@ -2,6 +2,7 @@
#ifdef HAVE_LUA
#include "port.h"
#include "snes9x.h"
#include "lua-engine.h"
#include <assert.h>
#include <vector>
@ -319,7 +320,7 @@ DEFINE_LUA_FUNCTION(emu_registerexit, "func")
lua_setfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_BEFOREEXIT]);
StopScriptIfFinished(luaStateToUIDMap[L]);
return 1;
}/*
}
DEFINE_LUA_FUNCTION(emu_registerstart, "func")
{
if (!lua_isnil(L,1))
@ -329,11 +330,11 @@ DEFINE_LUA_FUNCTION(emu_registerstart, "func")
lua_insert(L,1);
lua_pushvalue(L,-1); // copy the function so we can also call it
lua_setfield(L, LUA_REGISTRYINDEX, luaCallIDStrings[LUACALL_ONSTART]);
if (!lua_isnil(L,-1) && ((Genesis_Started)||(SegaCD_Started)||(_32X_Started)))
if (!lua_isnil(L,-1) && !Settings.StopEmulation)
lua_call(L,0,0); // call the function now since the game has already started and this start function hasn't been called yet
StopScriptIfFinished(luaStateToUIDMap[L]);
return 1;
}*/
}
DEFINE_LUA_FUNCTION(gui_register, "func")
{
if (!lua_isnil(L,1))
@ -3688,10 +3689,10 @@ static const struct luaL_reg emulib [] =
// {"lagged", emu_lagged},
// {"emulating", emu_emulating},
// {"atframeboundary", emu_atframeboundary},
// {"registerbefore", emu_registerbefore},
// {"registerafter", emu_registerafter},
// {"registerstart", emu_registerstart},
// {"registerexit", emu_registerexit},
{"registerbefore", emu_registerbefore},
{"registerafter", emu_registerafter},
{"registerstart", emu_registerstart},
{"registerexit", emu_registerexit},
{"persistglobalvariables", emu_persistglobalvariables},
// {"message", emu_message},
{"print", print}, // sure, why not

View File

@ -213,6 +213,7 @@
#include "../controls.h"
#include "../conffile.h"
#include "../statemanager.h"
#include "../lua-engine.h"
#include "AVIOutput.h"
#include "InputCustom.h"
#include "CWindow.h"
@ -3686,6 +3687,9 @@ int WINAPI WinMain(
loop_exit:
#ifdef HAVE_LUA
StopAllLuaScripts();
#endif
CloseAllToolWindows();
Settings.StopEmulation = TRUE;