Comparing versions 10 and 11.
Kickstart
The method you might use most often is ru.hwl.svetka.Evaluator#evaluate(expression : String). Evaluator instances must be initialized in a special way, so you must not call Evaluator’s constructor explicitly. To retrieve an instance invoke ru.hwl.svetka.EvaluatorPool#newEvaluator(evaluatorName : String) factory method. EvaluatorPool is singleton.
import ru.hwl.svetka.Evaluator;
import ru.hwl.svetka.EvaluatorPool;
...
var pool : !EvaluatorPool = !EvaluatorPool.instance();
var evl : Evaluator = pool.newEvaluator("evl");
var result = evl.evaluate("2+2"); // result is 4
Note that “2+2” is evaluated by browser’s JS-engine. To access variables and objects existing on the AS-side you have to expose them to the JS-engine using ru.hwl.svetka.Evaluator#expose(objectToExpose : Object, objectAliasOnJsSide : String) method:
var obj : !SomeTestObject = new !SomeTestObject();
evl.expose(obj, "obj");
result = evl.evaluate("obj.doSomething(1, 2, 3)"); // !SomeTestObject#doSomething(int, int, int) is
// invoked on the AS-side and the result is stored in "result" var
You can assign a number of aliases to one variable:
evl.expose(obj, "anotherAliasForObj");
evl.expose(obj, "yetAnotherAlias");
result = evl.evaluate("anotherAliasForObj == yetAnotherAlias") &&
evl.evaluate("yetAnotherAlias") == obj; // result is true
Now when you’ve learnt several basic use cases, it’s time to learn how to get Svetka and how to make it working.
Important Restriction
You can not access AS-object’s properties (fields) – only methods. This limitation is discussed on Svetka Architecture page.