oldFunction: Difference between revisions
Jump to navigation
Jump to search
m (Conversion script moved page OldFunction to oldFunction: Converting page titles to lowercase) |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 8: | Line 8: | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
oldFunction(SPECIAL) | oldFunction(SPECIAL) | ||
</ | </syntaxhighlight> | ||
'''Parameter''' | '''Parameter''' | ||
{{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.}} | ||
Line 16: | Line 16: | ||
|example= | |example= | ||
Within a user-defined function named {{code|eval()}}, {{func|oldFunction}} is used to call the standard MapTool {{func|eval}} function. | Within a user-defined function named {{code|eval()}}, {{func|oldFunction}} is used to call the standard MapTool {{func|eval}} function. | ||
< | <syntaxhighlight lang="mtmacro"> | ||
[h, if ( arg(0) == 0 ), code: | [h, if ( arg(0) == 0 ), code: | ||
{ | { | ||
Line 23: | Line 23: | ||
[h: macro.return = oldFunction( arg(0) ) ] | [h: macro.return = oldFunction( arg(0) ) ] | ||
}] | }] | ||
</ | </syntaxhighlight> | ||
By having access to the original function definition, this example is able to provide custom or standard return values when called. | By having access to the original function definition, this example is able to provide custom or standard return values when called. | ||
Latest revision as of 23:59, 14 March 2023
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
Within a user-defined function named
By having access to the original function definition, this example is able to provide custom or standard return values when called.
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) ) ]
}]