oldFunction: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Initial write-up.)
 
No edit summary
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{stub}}
{{MacroFunction
{{MacroFunction
|name=oldFunction
|name=oldFunction
|version=1.3b51
|description=
|description=
Used within a user defined function to call the function that the aforementioned user defined function redefind.
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=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
oldFunction(SPECIAL)
oldFunction(SPECIAL)
</source>
</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.}}


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


|also=
|also=

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 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 custom or standard return values when called.

See Also