From cacb0cdbd6651809cccdd8ee826b0be8774d5be2 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Sat, 26 Jul 2025 15:34:35 -0700 Subject: [PATCH] Cleanup + loopRun - added loopRun to define custom loops (https://github.com/HaxeFoundation/hscript/commit/20c8bc3f3c72a4dedabf9a647940b9c4f43eedf8) --- hscript/CustomClassHandler.hx | 45 ---------------------------- hscript/Interp.hx | 55 ++++++++++++++--------------------- hscript/Property.hx | 8 +++++ 3 files changed, 30 insertions(+), 78 deletions(-) diff --git a/hscript/CustomClassHandler.hx b/hscript/CustomClassHandler.hx index 9566181..f416a5e 100644 --- a/hscript/CustomClassHandler.hx +++ b/hscript/CustomClassHandler.hx @@ -146,52 +146,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip return name; } } -/* -class CustomTemplateClass implements IHScriptCustomClassBehaviour { - public var __interp:Interp; - public var __allowSetGet:Bool = true; - public var __custom__variables:Map; - public var __real_fields:Array; - public var __class__fields:Array; - public function hset(name:String, val:Dynamic):Dynamic { - if(__allowSetGet && __custom__variables.exists("set_" + name)) - return __callSetter(name, val); - if (__custom__variables.exists(name)) { - __custom__variables.set(name, val); - return val; - } - if(__real_fields.contains(name)) { - UnsafeReflect.setProperty(this, name, val); - return UnsafeReflect.field(this, name); - } - __custom__variables.set(name, val); - return val; - } - public function hget(name:String):Dynamic { - if(__allowSetGet && __custom__variables.exists("get_" + name)) - return __callGetter(name); - if (__custom__variables.exists(name)) - return __custom__variables.get(name); - - return UnsafeReflect.getProperty(this, name); - } - - public function __callGetter(name:String):Dynamic { - __allowSetGet = false; - var v = __custom__variables.get("get_" + name)(); - __allowSetGet = true; - return v; - } - - public function __callSetter(name:String, val:Dynamic):Dynamic { - __allowSetGet = false; - var v = __custom__variables.get("set_" + name)(val); - __allowSetGet = true; - return v; - } -} -*/ /** * This is for backwards compatibility with old hscript-improved, since some scripts use it diff --git a/hscript/Interp.hx b/hscript/Interp.hx index de420d9..b95d741 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -1289,17 +1289,8 @@ class Interp { function doWhileLoop(econd:Expr, e:Expr):Void { var old = declared.length; do { - try { - expr(e); - } catch (err:Stop) { - switch (err) { - case SContinue: - case SBreak: - break; - case SReturn: - throw err; - } - } + if (!loopRun(() -> expr(e))) + break; } while (expr(econd) == true); restore(old); } @@ -1307,17 +1298,8 @@ class Interp { function whileLoop(econd:Expr, e:Expr):Void { var old = declared.length; while (expr(econd) == true) { - try { - expr(e); - } catch (err:Stop) { - switch (err) { - case SContinue: - case SBreak: - break; - case SReturn: - throw err; - } - } + if (!loopRun(() -> expr(e))) + break; } restore(old); } @@ -1378,21 +1360,28 @@ class Interp { if(isKeyValue) locals.set(ithv, {r: next.key, depth: depth}); locals.set(n, {r: isKeyValue ? next.value : next, depth: depth}); - try { - expr(e); - } catch (err:Stop) { - switch (err) { - case SContinue: - case SBreak: - break; - case SReturn: - throw err; - } - } + if (!loopRun(() -> expr(e))) + break; } restore(old); } + inline function loopRun(f:Void -> Void) { + var cont = true; + try { + f(); + } catch (err:Stop) { + switch (err) { + case SContinue: + case SBreak: + cont = false; + case SReturn: + throw err; + } + } + return cont; + } + inline function isMap(o:Dynamic):Bool { return (o is IMap); } diff --git a/hscript/Property.hx b/hscript/Property.hx index c167a89..94de62f 100644 --- a/hscript/Property.hx +++ b/hscript/Property.hx @@ -35,6 +35,14 @@ class Property { var isVar:Bool; var interp:Interp; + public function new(r:Dynamic, getter:FieldPropertyAccess, setter:FieldPropertyAccess, isVar:Bool, interp:Interp) { + this.r = r; + this.getter = getter; + this.setter = setter; + this.isVar = isVar; + this.interp = interp; + } + var __allowReadAccess:Bool = false; var __allowWriteAccess:Bool = false; var __allowSetGet:Null = null;