oldFunction: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Clarified that user-defined functions can be redefined as well, and gave a basic explanation of function chaining.)
m (Removed stub, added a bit more clarification.)
Line 1: Line 1:
{{stub}}
{{MacroFunction
{{MacroFunction
|name=oldFunction
|name=oldFunction
|version=1.3b51
|description=
|description=
If a user-defined function redefines a standard MapTool function or another user-defined function -- for instance, a user defines a function called {{code|eval()}}, redefining the standard MapTool {{func|eval}} -- {{func|oldFunction}} can be used in the user-defined function to call the original function. When a user-defined function redefines an existing function, it keeps track of the function that it redefined. Due to this tracking, it is possible to redefine a function multiple times and {{func|oldFunction}} will always reference the previous function in the chain.
If a user-defined function redefines a standard MapTool function or another user-defined function -- for instance, a user defines a function called {{code|eval()}}, redefining the standard MapTool {{func|eval}} -- {{func|oldFunction}} can be used in the user-defined function to call the original function. When a user-defined function redefines an existing function, it keeps track of the function that it redefined. Due to this tracking, it is possible to redefine a function multiple times and {{func|oldFunction}} will always reference the previous function in the chain.
'''Note:''' Do not rely on a specific order in the function chain unless you are sure that the functions will be redefined in that order. Calls to {{func|defineFunction}} within [[onCampaignLoad]] macros on different [[Library Token]]s are not executed in any standard order.


|usage=
|usage=
Line 12: Line 14:
{{param|SPECIAL|oldFunction supports the same parameters as the function that it is referencing.}}
{{param|SPECIAL|oldFunction supports the same parameters as the function that it is referencing.}}


|examples=
|example=
Used within a user defined function named {{code|eval()}}, oldFunction() is used to call the standard {{func|eval}}.
Used within a user-defined function named {{code|eval()}}, oldFunction() is used to call the standard MapTool {{func|eval}} function.
<source lang="mtmacro" line>
<source lang="mtmacro">
[h, if ( arg(0) == 0 ), code:
[h, if ( arg(0) == 0 ), code:
{
{
Line 22: Line 24:
}]
}]
</source>
</source>
By having access to the original function definition, this example is able to provide both custom and standards return values when called.


|also=
|also=

Revision as of 22:51, 16 April 2009

oldFunction() Function

Introduced in version 1.3b51
If a user-defined function redefines a standard MapTool function or another user-defined function -- for instance, a user defines a function called eval(), redefining the standard MapTool eval() -- oldFunction() can be used in the user-defined function to call the original function. When a user-defined function redefines an existing function, it keeps track of the function that it redefined. Due to this tracking, it is possible to redefine a function multiple times and oldFunction() will always reference the previous function in the chain. Note: Do not rely on a specific order in the function chain unless you are sure that the functions will be redefined in that order. Calls to defineFunction() within onCampaignLoad macros on different Library Tokens are not executed in any standard order.

Usage

oldFunction(SPECIAL)

Parameter

  • SPECIAL - oldFunction supports the same parameters as the function that it is referencing.

Example

Used within a user-defined function named eval(), oldFunction() is used to call the standard MapTool eval() function.
[h, if ( arg(0) == 0 ), code:
{
    [h: macro.return = 0]
};{
    [h: macro.return = oldFunction( arg(0) ) ]
}]
By having access to the original function definition, this example is able to provide both custom and standards return values when called.

See Also