Prev | Current Page 486 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Thus ::expression:: is the placeholder for a variable named expression . The placeholder variable
must be an existent field inside the data object passed to the execute method or a valid expression.
Numeric and Calculation Expressions
An expression can contain a constant numeric value such as ::(123):: , where 123 will be the obvious
result. More interesting expressions can be created using the basic math operators (+, - , /, * ). So in the
following example a simple mathematical expression is used:
class Main
{
public static function main()
{
var t = new haxe.Template(???Seconds in a day ::(24*(60*60))::???);
trace(t.execute(Reflect.empty()));
}
}
// result in: Main.hx:6: Seconds in a day 86400
Note that the participants in the mathematical expression must be grouped in pairs using rounded
parentheses; otherwise an exception will be thrown.
In the previous example, the passed data object is an empty object because no variables were required.
It is important to note that when an empty object has to be created, the correct way is to use the
Reflect.


Pages:
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498