Skip to content

Commit

Permalink
add a way to manually execute the script entirely if shit hits the fan
Browse files Browse the repository at this point in the history
  • Loading branch information
crowplexus authored Jan 11, 2025
1 parent fc136af commit d6113a3
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions source/psychlua/HScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HScript extends Iris
hs.scriptCode = code;
hs.varsToBring = varsToBring;
hs.parse(true);
hs.execute();
hs.tryRunning();
}
catch(e:Dynamic)
{
Expand All @@ -56,7 +56,7 @@ class HScript extends Iris
#end

public var origin:String;
override public function new(?parent:Dynamic, ?file:String, ?varsToBring:Any = null)
override public function new(?parent:Dynamic, ?file:String, ?varsToBring:Any = null, ?manualRun:Bool = false)
{
if (file == null)
file = '';
Expand Down Expand Up @@ -99,13 +99,10 @@ class HScript extends Iris
this.modFolder = parent.modFolder;
}
#end
try {
preset();
execute();
} catch(e:haxe.Exception) {
this.destroy();
throw e;
return;
if (!manualRun) {
var _active:Bool = tryRunning();
if (_active == false)
return;
}
Iris.warn = function(x, ?pos:haxe.PosInfos) {
if (PlayState.instance != null)
Expand All @@ -125,6 +122,19 @@ class HScript extends Iris
}
}

function tryRunning():Bool {
try {
preset();
execute();
return true;
} catch(e:haxe.Exception) {
this.destroy();
throw e;
return false;
}
return false;
}

var varsToBring(default, set):Any = null;
override function preset() {
super.preset();
Expand Down Expand Up @@ -545,4 +555,4 @@ class CustomInterp extends crowplexus.hscript.Interp

return null;
}
}
}

0 comments on commit d6113a3

Please sign in to comment.