Class TCasScriptFunction
Unit
Declaration
type TCasScriptFunction = class(TCasScriptExpression)
Description
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
|
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
|
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 an empty string ('') if no explicit name for this function exists. This is useful for operators, which are implemented just like normal functions (a descendant of TCasScriptFunction), but with a special support from parser (e.g. to turn "x + b" into a call to the TCasScriptAdd function). |
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 Note that at least one of ShortName and 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:
|
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 This is particularly suited for implementing control-flow instructions, like "if" and "while", as normal functions inside CastleScript. For example, "if" will have |
class function ArgumentMustBeAssignable(const Index: Integer): boolean; virtual; |
|
Which arguments should be assignable by this function. Default implementation in TCasScriptFunction just returns 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.16.0.