Castle Game Engine: CastleScript: Class TCasScriptExpression

# Class TCasScriptExpression
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleScript ## Declaration `type TCasScriptExpression = class(TObject)` ## Description ## Hierarchy TObject TCasScriptExpression ## Overview ### Methods
| `function CoreExecute: TCasScriptValue; virtual; abstract;`
| `function Execute: TCasScriptValue;`
| `function TryExecuteMath: TCasScriptValue;`
| `function AsFloat(const ADefaultValue: Float = 0): Float;`
| `procedure FreeByParentExpression;`
### Properties
| `property Environment: TCasScriptEnvironment read FEnvironment write FEnvironment;`
## Description ### Methods
| `function CoreExecute: TCasScriptValue; virtual; abstract;`
More internal version of Execute. This doesn't necessarily check floating-point exceptions. Execute actually calls `CoreExecute` and then ClearExceptions. Also this doesn't try to convert EIntError and EMathError to ECasScriptAnyMathError. This is done by Execute. When one CastleScript `CoreExecute` calls another function, it can use `CoreExecute` instead of Execute. This way only one ClearExceptions will be needed for whole expression execution, instead of doing ClearExceptions after each function handler.
| `function Execute: TCasScriptValue;`
Execute and calculate this expression. Returned value is owned by this object. Which should be comfortable for you usually, as you do not have to worry about freeing it. Also, it allows us to make various optimizations to avoid creating/destroying lots of temporary TCasScriptExpression instances during calculation of complex expression. The disadvantage of this is that returned object value is valid only until you executed this same expression again, or until you freed this expression. If you need to remember the execute result for longer, you have to copy it somewhere. For example you can do
      { This will always work, thanks to virtual TCasScriptValue.Create
        and AssignValue methods. }
      Copy := TCasScriptValue(ReturnedValue.ClassType).Create;
      Copy.AssignValue(ReturnedValue);
###### Exceptions raised ECasScriptError Execute is guaranteed to raise an ECasScriptError exception if some calculation fails because of invalid arguments. This means that when you run CastleScript expression provided by the user, you only have to catch ECasScriptError to be safe from errors produced by user. No need to catch something more general like Exception class. Also it's guaranteed that no hanging floating-point errors are left. Normally, there is no guarantee that floating-point errors are raised immediately, they may be raised at the next fp operation (this is needed for fp operations to proceed in parallel, and be much faster). For executing CastleScript, Execute calls Math.ClearExceptions(true) to make sure that all floating point errors are caught. This ensures that we can safely execute even invalid expressions (like 'ln(-3)') and get reliable exceptions. Floating-point errors of course also result in ECasScriptError descendants. More specifically, EIntError and EMathError result in ECasScriptAnyMathError.
| `function TryExecuteMath: TCasScriptValue;`
Try to execute expression, or return `Nil` if a mathematical error occurred within expression. "Math error within expression" means that a ECasScriptAnyMathError exception occurred while calculating expression. This is useful to secure you against math arguments errors ('ln(-3)', 'sqrt(-3)') but still raises normal exception on other ECasScriptError errors (like invalid argument type for function).
| `function AsFloat(const ADefaultValue: Float = 0): Float;`
Execute expression, return the result as a simple float value. It assumes that the expression is written to always return float. To easily create such expression, use ParseFloatExpression.
| `procedure FreeByParentExpression;`
Call Free, but only if this is not TCasScriptValue with OwnedByParentExpression = false. (This cannot be implemented cleanly, as virtual procedure, since it must work when Self is `Nil`, and then virtual method table is not available of course.)
### Properties
| `property Environment: TCasScriptEnvironment read FEnvironment write FEnvironment;`
Environment (outside information) for this expression. May be `Nil`. This object is not owned by TCasScriptExpression, will not be freed by TCasScriptExpression and such.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:11