Description:
Register a .dfx/.splx/.spl file as a function to be called.
Syntax:
register(f,spl)
Note:
The function registers a script file spl as function f to call it in a cellset script. Syntax of the function expression is f(xi,...), where xi,... is a parameter in the spl file. Use the comma to separate multiple parameters.
The function name is the one registered the last time.
The function cannot work in a multithreaded environment.
Parameter:
f |
Function name. |
spl |
.dfx/.splx/.spl file path, which can be an absolute path or a relative path; a relative path is relative to the main directory. |
Option:
@o |
In a function registered with @o, o in the invocation expression fn@o is the first (string) parameter value. If no option is specified in the invocation expression, the first (string) parameter value passed is regarded as null. |
@j |
Register the function for a specific task; by default, register it for the global use. |
Return value:
Result of executing the script file
Example:
Below is emp.splx, where arg1 and arg2 are cellset parameters:
|
A |
1 |
=connect("demo") |
2 |
=A1.query("select EID,NAME,DEPT,GENDER,SALARY from employee where DEPT=? and GENDER=?",arg1,arg2) |
3 |
return A2 |
Register emp.splx as a function and call it:
|
A |
|
1 |
=register("df1","D:/emp.splx") |
Register emp.splx as a function named df1. |
2 |
=df1("HR","M") |
Call the registered function and pass parameter values: |
Below is emp2.splx, where opt and arg2 are cellset parameters:
|
A |
B |
1 |
if opt=="z" |
>opt="order by SALARY desc" |
2 |
else if opt=="a" |
>opt="order by SALARY" |
3 |
="select EID,NAME,GENDER,SALARY from employee where GENDER=? "+opt |
|
4 |
=connect("demo").query(A3,arg2) |
|
Use @o option to register a function:
|
A |
|
1 |
=register@o("df2","D:/emp2.splx") |
Use @o mtethod to register emp2.splx as a function named df2; We can use @z option, which performs a sorting by SALARY in descending order, and @a option, which performs a sorting by SALARY in ascending order, with function df2; do not perform a sorting when both options are absent. |
2 |
=df2@z("F") |
Call function df2 and use @z option to perform a sorting by SALARY in descending order; Perform the computation, where in emp2.splx value of the first string parameter is z and that of parameter arg2 is F, and return result as follows: |
3 |
=df2@a("M") |
Call function df2 and use @a option to perform a sorting by SALARY in ascending order; Perform the computation, where in emp2.splx value of the first string parameter opt is a and that of parameter arg2 is M, and return result as follows: |
4 |
=df2("M") |
Call function df2 and, since both parameter @z and @a are absent, sorting will not be performed; Perform the computation, where in emp2.splx value of the first string parameter opt is null and that of parameter arg2 is M, and return result as follows: |
Below is emp.splx: