Skip to content

Commit f435175

Browse files
committed
Set function
1 parent 8dacd3a commit f435175

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

rulescript/RuleScriptInterp.hx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,37 @@ class RuleScriptInterp extends hscript.Interp
474474
return null;
475475
}
476476

477+
override function set(o:Dynamic, f:String, v:Dynamic):Dynamic
478+
{
479+
if (o == null)
480+
error(EInvalidAccess(f));
481+
482+
if (o == this)
483+
{
484+
if (variables.exists(f))
485+
{
486+
var variable:Dynamic = variables.get(f);
487+
variable is RuleScriptProperty ? cast(variable, RuleScriptProperty).value = v : variables.set(f, v);
488+
return v;
489+
}
490+
else
491+
o = superInstance;
492+
}
493+
494+
if (o is RuleScriptedClass)
495+
{
496+
var cl:RuleScriptedClass = cast(o, RuleScriptedClass);
497+
if (cl.variableExists(f))
498+
{
499+
var o = cl.getVariable(f);
500+
return o is RuleScriptProperty ? cast(o, RuleScriptProperty).value = v : cl.setVariable(f, v);
501+
}
502+
}
503+
504+
Reflect.setProperty(o, f, v);
505+
return v;
506+
}
507+
477508
override function call(o:Dynamic, f:Dynamic, args:Array<Dynamic>):Dynamic
478509
{
479510
if (o == superInstance)

test/scripts/haxe/importTest/ScriptImportTest.rhx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ package importTest;
33
import importTest.Script;
44

55
class ScriptImportTest{
6+
public var a = 'hello';
7+
68
function main(){
79
trace(Script.helloWorld());
810

911
var scriptedClass = new ScriptedClass(1,'ScriptImportTest');
12+
13+
trace(scriptedClass.variable1);
14+
15+
scriptedClass.variable1 += ' 2';
16+
1017
trace(scriptedClass.variable1);
18+
19+
trace(this.a);
20+
21+
this.a = 'world';
22+
23+
trace(this.a);
1124
}
1225
}

0 commit comments

Comments
 (0)