oldFunction: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Removed stub, added a bit more clarification.)
mNo edit summary
Line 15: Line 15:


|example=
|example=
Used within a user-defined function named {{code|eval()}}, 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.
<source lang="mtmacro">
<source lang="mtmacro">
[h, if ( arg(0) == 0 ), code:
[h, if ( arg(0) == 0 ), code:
Line 24: 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.
By having access to the original function definition, this example is able to provide custom or standard return values when called.


|also=
|also=

Revision as of 01:35, 17 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

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