Castle Game Engine: CastleScript: Class TCasScriptFunction

# Class TCasScriptFunction
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleScript ## Declaration `type TCasScriptFunction = class(TCasScriptExpression)` ## Description no description available, TCasScriptExpression description follows ## Hierarchy TObject TCasScriptExpression TCasScriptFunction ## Overview ### Methods
| `procedure CheckArguments; virtual;`
| `function CoreExecute: TCasScriptValue; override;`
| `constructor Create(AArgs: TCasScriptExpressionList); overload;`
| `constructor Create(const AArgs: array of TCasScriptExpression); overload;`
| `destructor Destroy; override;`
| `class function Name: string; virtual;`
| `class function ShortName: string; virtual; abstract;`
| `class function InfixOperatorName: string; virtual;`
| `class function GreedyArgumentsCalculation: Integer; virtual;`
| `class function ArgumentMustBeAssignable(const Index: Integer): boolean; virtual;`
### Properties
| `property Args: TCasScriptExpressionList read FArgs;`
## Description ### Methods
| `procedure CheckArguments; virtual;`
Used by constructor to check are args valid. Also, right now this gets FunctionHandlersByArgument (this way we don't have to search it at each TCasScriptFunction.Execute call, so TCasScriptFunction.Execute may work much faster). ###### Exceptions raised ECasScriptFunctionArgumentsError on invalid Args passed to function.
| `function CoreExecute: TCasScriptValue; override;`
| `constructor Create(AArgs: TCasScriptExpressionList); overload;`
Constructor initializing Args from given TCasScriptExpressionList. AArgs list contents is copied, i.e. AArgs refence is not stored or freed by TCasScriptFunction. But items on AArags are not copied recursively, we copy references from AArags items, and so we become their owners. ###### Exceptions raised ECasScriptFunctionArgumentsError if you specified invalid number of arguments for this function.
| `constructor Create(const AArgs: array of TCasScriptExpression); overload;`
| `destructor Destroy; override;`
| `class function Name: string; virtual;`
Long function name for user. This is possibly with spaces, parenthesis and other funny characters. It will be used in error messages and such to describe this function. Default implementation in this class simply returns ShortName. This should be suitable for most "norma" functions.
| `class function ShortName: string; virtual; abstract;`
Short function name, for the parser. This is the name of the function for use in expressions like "function_name(arg_1, arg_2 ... , arg_n)". This can be empty string ('') if no such name for this function exists, then the logic to parse this function expressions must be somehow built in the parser (for example, operators use this: they are just normal functions, TCasScriptFunction, with `ShortName` = '' and special support in the parser).
| `class function InfixOperatorName: string; virtual;`
Function name when used as an infix operator. Empty string ('') if no such name for this function. This is returned by default implementation of this in this class. This does require cooperation from the parser to actually work, that is you cannot simply define new operators by registering new TCasScriptFunction with `InfixOperatorName` <> ''. For now. Note that at least one of ShortName and `InfixOperatorName` must not be empty. The only exception is the TCasScriptNegate function, that is neither infix operator nor a usual function that must be specified as "function_name(arguments)". So this is an exception, and if there will be a need, I shall fix this (probably by introducing some third field, like PrefixOperatorName ?) Note 2 things: Function that can be used as infix operator (i.e. has `InfixOperatorName` <> '') is not necessary binary operator, i.e. `InfixOperatorName` <> '' does not determine the value of ArgsCount. This way I was able to define infix operators +, -, * etc. that take any number of arguments and operators like ˆ and > that always take 2 arguments. Function may have both ShortName <> '' and `InfixOperatorName` <> ''. E.g. TCasScriptPower can be used as "Power(3, 1.5)" or "3 ˆ 1.5".
| `class function GreedyArgumentsCalculation: Integer; virtual;`
Specify which arguments are calculated before function handler is called. If = -1 (default value returned by implementation in this class) then all arguments are greedily calculated, which simply means that all arguments are calculated before executing function handler. This is the usual and expected behavior of normal functions. It's also a prerequisite for most of overloaded things to work, since we need to know types of calculated arguments (TCasScriptValue classes) before we choose overloaded handler for function. If this is >= 0, then arguments with index >= of this will not be calculated before handler execution. Since their type is unknown, they will match any type in handler's ArgumentClasses. Your handler will receive `Nil` in their places, and is responsible for calling their Execute on it's own if needed. This is particularly suited for implementing control-flow instructions, like "if" and "while", as normal functions inside CastleScript. For example, "if" will have `GreedyArgumentsCalculation` = 1, so the first argument (condition) will be calculated, but the execution of 2nd or 3rd argument ("then" code or "else" code) will be left to the handler.
| `class function ArgumentMustBeAssignable(const Index: Integer): boolean; virtual;`
Which arguments should be assignable by this function. Default implementation in TCasScriptFunction just returns `False` always. If you're making a function that changes it's argument (like assignment operator, or vector_set, array_set and such) you want to override this. This is actually checked by CheckArguments, called from constructors.
### Properties
| `property Args: TCasScriptExpressionList read FArgs;`
Function arguments. Don't modify this list after function is created (although you can modify values inside arguments).
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:11