Custom Function Development |
![]() ![]() ![]() |
MScript is an extensible language. New functions can be developed with Java by implementing org.moremotion.evaluator.MSciptFunction interface. Assume that we need a new function called repeat() that repeats the given string the given number of times and returns it. The example below shows how we want to use it.
The definition of the function is done in the configuration as follows.
And the source code of the mypack.RepeatMScriptFunction class s as follows.
The execute method of the class is called by MScript engine and function parameters are passed in a Expression array. The second parameter of the method is a MScriptFunctionContext object which provides access to all the other necessary objects. See how MScript configuration is acquired and the value of the "repeat-separator" parameter is accessed through the MScriptFunctionContext object.
|