Using structures here you can also build CastleScript expressions by Pascal code (that is, you don't have to parse them). For example this is an expression that calculates sin(3) + 10 + 1:
You can then call Expr.Execute to calculate such expression.
To make a variable in the expression, just create and remember a TCasScriptFloat instance first, and then change it's value freely between Expr.Execute calls. For example
Note that generally each TCasScriptExpression owns it's children expressions, so they will be automatically freed when parent is freed. Also, the values returned by Execute are owned by expression. So you can simply free whole thing by Expr.Free.
If you're want to parse CastleScript expression from a text file, see CastleScriptParser.
This specifies for each type combination (array of TCasScriptValue classes) and for each function (TCasScriptFunction class) how they should be handled.
Calculate result on given function arguments Arguments. Place result in AResult.
The current function is also passed here, although usually you don't need it (you already get a list of calculated Arguments, and you should register different procedures for different TCasScriptFunction classes, so you know what operation on arguments should be done). For functions when GreedyArgumentsCalculation >= 0, it may be useful to directly access AFunction.Args.
If needed, previous value of AResult should be freed and new created. If current AResult is <> nil and it's of appropriate class, you may also reuse it and only change it's fields (this is helpful, to avoid many creations/destroying of class instances while calculating an expression many times). CreateValueIfNeeded may be helpful for implementing this.