From 0b4675b4ad82d63c6b4d7fed5c0cb72657937bc0 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Thu, 14 Aug 2025 03:07:44 -0700 Subject: [PATCH] static property accessor call --- hscript/Interp.hx | 1 + hscript/Property.hx | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/hscript/Interp.hx b/hscript/Interp.hx index 988a090..b8d74d7 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -908,6 +908,7 @@ class Interp { getter: getter, setter: setter, isVar: isVar, + isStatic: isStatic, interp: this, } } diff --git a/hscript/Property.hx b/hscript/Property.hx index 94de62f..85dd576 100644 --- a/hscript/Property.hx +++ b/hscript/Property.hx @@ -28,31 +28,41 @@ import hscript.Expr.FieldPropertyAccess; @:access(hscript.Interp) @:structInit class Property { + private static inline var GET = 'get_'; + private static inline var SET = 'set_'; + public var r:Dynamic; public var getter:FieldPropertyAccess; public var setter:FieldPropertyAccess; + public var isStatic(get, never):Bool; + function get_isStatic() { + return __isStatic && interp.allowStaticVariables; + } + var isVar:Bool; var interp:Interp; - public function new(r:Dynamic, getter:FieldPropertyAccess, setter:FieldPropertyAccess, isVar:Bool, interp:Interp) { + public function new(r:Dynamic, getter:FieldPropertyAccess, setter:FieldPropertyAccess, isVar:Bool, isStatic:Bool, interp:Interp) { this.r = r; this.getter = getter; this.setter = setter; this.isVar = isVar; + this.__isStatic = isStatic; this.interp = interp; } var __allowReadAccess:Bool = false; var __allowWriteAccess:Bool = false; var __allowSetGet:Null = null; + final __isStatic:Bool = false; public function callGetter(name:String) { switch (getter) { case AGet | ADynamic: - var fName:String = 'get_$name'; + var fName:String = '$GET$name'; if (!__allowReadAccess && (__allowSetGet != null && __allowSetGet || !interp.isBypassAccessor)) { - if (interp.varExists(fName)) { + if (varExists(fName)) { return callAccessor(fName); } else interp.error(ECustom('Method $fName required by property $name is missing')); @@ -73,9 +83,9 @@ class Property { public function callSetter(name:String, val:Dynamic) { switch (setter) { case ASet | ADynamic: - var fName:String = 'set_$name'; + var fName:String = '$SET$name'; if (!__allowWriteAccess && (__allowSetGet != null && __allowSetGet || !interp.isBypassAccessor)) { - if (interp.varExists(fName)) + if (varExists(fName)) return callAccessor(fName, [val], true); else interp.error(ECustom('Method $fName required by property $name is missing')); @@ -94,7 +104,7 @@ class Property { } private function callAccessor(f:String, ?args:Array, isWrite:Bool = false):Dynamic { - var fn = interp.variables.get(f); + var fn = isStatic ? interp.staticVariables.get(f) : interp.variables.get(f); var rt:Dynamic = null; if (fn != null && Reflect.isFunction(fn)) { if (isWrite) __allowWriteAccess = true; @@ -111,4 +121,8 @@ class Property { return rt; } + + private function varExists(n:String) { + return isStatic ? interp.staticVariables.exists(n) : interp.variables.exists(n); + } }