E
Defining New SKILL Functions
You can define a function and add it to the SKILL User Defined Functions category in the calculator by following these steps:
- Define the form that prompts for user-defined arguments to the function.
- Define the syntax of the function in the callback procedure.
- Register the function.
Defining a Form
The following example shows how to define an input form for a function that takes three arguments. The first argument is the buffer expression. The other two arguments are the boundaries of the range of the expression on which you want to operate.
procedure( CreateMyForm()
let( ( fieldList a b )
a = ahiCreateStringField(
?name 'from
?prompt "From"
?value ""
)
b = ahiCreateStringField(
?name 'to
?prompt "To"
?value ""
)
fieldList = list(
list( a 5:0 120:25 40 )
list( b 160:0 110:25 30 )
)
calCreateSpecialFunctionsForm( 'MyForm
fieldList )))
In this example, the From and To fields are string fields created in a two-dimensional form specification for fieldList. The form is created by the call to calCreateSpecialFunctionsForm. This function creates and registers the form with the specified form symbol, MyForm.
Defining a Callback Procedure
You define a callback procedure that is called from the entry on the Calculator User Defined Functions category. Since this example uses a form to prompt for additional information required by the special function, the callback procedure is
procedure( MySpecialFunctionCB()
calCreateSpecialFunction(
?formSym 'MyForm
?formInitProc 'CreateMyForm
?formTitle "Test"
?formCallback "calSpecialFunctionInput( 'test
'(from to) )"
)
)
In this procedure, a call is made to calCreateSpecialFunction, which creates and displays the form and then builds the expression in the buffer with the specified form fields.
Using Stack Registers in the Procedure
You can use the special symbol ’STACK in the list of form fields to get expressions from the stack.
For example, if you want to insert a stack element between the From and To arguments in the special function expression, you can specify the callback line as follows:
?formCallback "calSpecialFunctionInput(’test ’(from STACK to))"
If your special function does not require a form to prompt for , you can define your callback as follows:
procedure( MySpecialFunctionCB()
calSpecialFunctionInput( ’test nil )
)
Registering the Function
You register the function and callback with the calRegisterSpecialFunction:
calRegisterSpecialFunction(
list( "test" ’MySpecialFunctionCB )
)
The next time you open the calculator, the functions you defined appear in the User Defined Functions category.
Defining a Custom Function
Custom functions need to be supported for both single and multi-dimensional waveform (parametric) data.
A custom function example is shown below:
procedure(myFunction(wf)
cond(
(drIsWaveform(wf)
;; your custom function code
)
(famIsFamily(wf)
famMap('myFunction wf)
)
(t
error("myFunction cannot handle argument %L\n" wf)
)
)
Return to top