Closed wixette closed 3 years ago
With https://github.com/wixette/isb/commit/ec9b7744e4ddf24a80204c8452930d03b776c5b3 , running program as a Unity coroutine is supported.
Canceling an execution when there are time-consuming operations, such as an infinite loop, is also supported.
See https://github.com/wixette/isb/blob/main/unity_integration_demo/Assets/Scripts/Program.cs for an example:
// Runs the program in a Unity coroutine.
Action<bool> doneCallback = (value) =>
{
if (!value)
{
ReportErrors(engine);
}
else if (engine.StackCount > 0)
{
string ret = engine.StackTop.ToDisplayString();
PrintDebugInfo(ret);
}
};
// Prevents the scripting engine to be stuck in an infinite loop.
int maxInstructionsToExecute = 1000000;
Func<int, bool> canContinueCallback =
(counter) => counter >= maxInstructionsToExecute ? false : true;
StartCoroutine(engine.RunAsCoroutine(doneCallback, canContinueCallback));
With the demo env set up by the above code, the following long (infinite yet) loop will be canceled during execution:
x = 0
for i = 1 to 100000
x = x + 1
endfor
x
@ratkingsminion added stepping to the execution method to prevent long-time running in every frame: