@@ -11,8 +11,8 @@ import rulescript.types.ScriptedEnum;
1111import rulescript .types .ScriptedType ;
1212import rulescript .types .ScriptedTypeUtil ;
1313import rulescript .types .ScriptedTypedef ;
14- import rulescript .types .context .EVariableModifiers ;
1514import rulescript .types .context .EVariableDeclarations ;
15+ import rulescript .types .context .TContextVariable ;
1616
1717using rulescript .Tools ;
1818
@@ -98,8 +98,12 @@ class RuleScriptInterp extends hscript.Interp implements IInterp
9898 v = get (superInstance , id );
9999
100100 // SHARED VARIABLES
101- if (v == null && context != null && context .variables .exists (id ))
102- v = context .variables .get (id ).value ;
101+ if (v == null && context != null ) {
102+ if (context .publicVariables .exists (id ))
103+ v = context .publicVariables .get (id ).value ;
104+ else if (context .staticVariables .exists (id ))
105+ v = context .staticVariables .get (id ).value ;
106+ }
103107
104108 if (v == null )
105109 error (EUnknownVariable (id )); // fixes - orbl
@@ -143,19 +147,18 @@ class RuleScriptInterp extends hscript.Interp implements IInterp
143147 }
144148 return v ;
145149 }
146-
147- override function setVar (name : String , v : Dynamic )
148- {
150+ override function setVar (name : String , v : Dynamic ) {
149151 if (superInstance != null && (superFields .contains (name ) || superFields .contains (' set_' + name )))
150152 Reflect .setProperty (superInstance , name , v );
151- else if (context != null && context .variables .exists (name )) {
152- final cv : rulescript. Context . ContextVariable = context .variables .get (name );
153- if (cv .declaration == FINAL && cv .parent != scriptName )
153+ else if (context != null && (context .staticVariables .exists (name ) || context .publicVariables .exists (name ))) {
154+ final vg : Map <String , TContextVariable > = context .staticVariables .exists (name ) ? context .staticVariables : context .publicVariables ;
155+ final cv : TContextVariable = vg .get (name );
156+ if (cv .declaration == FINAL && cv .parent != scriptName ) {
154157 error (ECustom (' $name : Unable to override final variable defined by another script.' ));
155- else context . variables . set ( name , { modifier : cv . modifier , declaration : cv . declaration , value : v , parent : scriptName });
156- }
157- else
158- {
158+ } else {
159+ vg . set ( name , { declaration : cv . declaration , value : v , parent : scriptName });
160+ }
161+ } else {
159162 var lastValue = variables .get (name );
160163
161164 if (lastValue is Property )
@@ -241,7 +244,7 @@ class RuleScriptInterp extends hscript.Interp implements IInterp
241244
242245 if ((! locals .exists (id ) && ! variables .exists (id ))
243246 && (! superFields .contains (id ) && ! superFields .contains (' get_ $id ' ))
244- && (context == null || ! context .variables .exists (id )))
247+ && (context == null || ! context .publicVariables . exists ( id ) || context . staticVariables .exists (id )))
245248 {
246249 final typePath : String = path .join (' .' );
247250
@@ -292,20 +295,20 @@ class RuleScriptInterp extends hscript.Interp implements IInterp
292295
293296 if (isFunction && depth == 0 )
294297 {
295- return context .variables [n ] = {
298+ ( isStatic ? context .staticVariables : context . publicVariables ) [n ] = {
296299 value : this .expr (e ),
297300 declaration : isFinal ? EVariableDeclarations .FINAL : EVariableDeclarations .VAR ,
298- modifier : isStatic ? EVariableModifiers .STATIC : EVariableModifiers .PUBLIC ,
299301 parent : scriptName
300302 };
303+
304+ return (isStatic ? context .staticVariables : context .publicVariables )[n ];
301305 }
302306 else if (depth == 0 )
303307 {
304308 this .expr (e );
305- context .variables .set (n , {
309+ ( isStatic ? context .staticVariables : context . publicVariables ) .set (n , {
306310 value : resolve (n ),
307311 declaration : isFinal ? EVariableDeclarations .FINAL : EVariableDeclarations .VAR ,
308- modifier : isStatic ? EVariableModifiers .STATIC : EVariableModifiers .PUBLIC ,
309312 parent : scriptName
310313 });
311314 }
@@ -322,7 +325,7 @@ class RuleScriptInterp extends hscript.Interp implements IInterp
322325 case EVar (n , _ , e , global , _ ):
323326 if (global )
324327 {
325- if (context == null || ! context .variables .exists (n ))
328+ if (context == null || ( ! context .staticVariables .exists (n ) || ! context . publicVariables . exists ( n ) ))
326329 variables .set (n , (e == null ) ? null : this .expr (e ));
327330 }
328331 else
0 commit comments