Lua - account for callbacks with no parent script creating more callbacks by generating a mock lua file with a new thread, and register the thread with the sandbox. Fixes #1983. Not super proud of this.
This commit is contained in:
parent
021b1639c2
commit
40ad7ed67e
|
@ -48,7 +48,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void CallSaveStateEvent(string name)
|
||||
{
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnSavestateSave");
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnSavestateSave").ToList();
|
||||
try
|
||||
{
|
||||
foreach (var lf in lfs)
|
||||
|
@ -64,7 +64,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void CallLoadStateEvent(string name)
|
||||
{
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnSavestateLoad");
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnSavestateLoad").ToList();
|
||||
try
|
||||
{
|
||||
foreach (var lf in lfs)
|
||||
|
@ -80,7 +80,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void CallFrameBeforeEvent()
|
||||
{
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnFrameStart");
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnFrameStart").ToList();
|
||||
try
|
||||
{
|
||||
foreach (var lf in lfs)
|
||||
|
@ -96,7 +96,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void CallFrameAfterEvent()
|
||||
{
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnFrameEnd");
|
||||
var lfs = RegisteredFunctions.Where(l => l.Event == "OnFrameEnd").ToList();
|
||||
try
|
||||
{
|
||||
foreach (var lf in lfs)
|
||||
|
|
|
@ -14,7 +14,28 @@ namespace BizHawk.Client.Common
|
|||
_function = function;
|
||||
Name = name ?? "Anonymous";
|
||||
Event = theEvent;
|
||||
LuaFile = luaFile;
|
||||
|
||||
// When would a file be null?
|
||||
// When a script is loaded with a callback, but no infinite loop so it closes
|
||||
// Then that callback proceeds to register more callbacks
|
||||
// In these situations, we will generate a thread for this new callback on the fly here
|
||||
// Scenarios like this suggest that a thread being managed by a LuaFile is a bad idea,
|
||||
// and we should refactor
|
||||
if (luaFile == null)
|
||||
{
|
||||
var thread = new Lua();
|
||||
|
||||
// Current dir will have to do for now, but this will inevitably not be desired
|
||||
// Users will expect it to be the same directly as the thread that spawned this callback
|
||||
// But how do we know what that directory was?
|
||||
LuaSandbox.CreateSandbox(thread, ".");
|
||||
LuaFile = new LuaFile(".") { Thread = thread };
|
||||
}
|
||||
else
|
||||
{
|
||||
LuaFile = luaFile;
|
||||
}
|
||||
|
||||
Guid = Guid.NewGuid();
|
||||
|
||||
Callback = () =>
|
||||
|
|
Loading…
Reference in New Issue