Please enable JavaScript to view this site.

Updated November 2017 (added Example)

XFUNC (Sbxname, arg1,...,argn)

XFUNC$ (Sbxname, arg1,...,argn)

XFUNC executes an external function, returning a value. It is similar to XCALL, in that it loads and calls an external function, except that it is an expression (which returns a value) rather than a statement (which does not). Sbxname is the name of an SBX subroutine which implements the function, and arg1 through argn are the arguments passed to the SBX routine. The only special requirement for the SBX routine is that it return a value—numeric for XFUNC and string for XFUNC$—via a special form of the RETURN statement.

Note that as with other system functions, XFUNC and XFUNC$ are expressions—not labels—and thus cannot be invoked with the CALL statement.

Example

Here's an example of an SBX to concatenate two strings that can be called via XCALL (returning the result in the 3rd parameter), or via XFUNC$ (returning the result as the value of the function):

map1 var1$,s,30,"  abra   "

map1 result$,s,50

 

    xcall CONCAT2,var1$,"  cadabra  ",result$

    ? "xcall result:  "; result$

 

    ? "xfunc$ result: "; xfunc$("CONCAT2", var1$,"  cadabra  ")

    end

 

Both the XCALL and the XFUNC$ statements above invoke the same CONCAT2.SBX routine, which, if written to handle both calling methods, will result in the same output for the two print statements above, i.e.

.RUN TSTCONCAT2

xcall result:  abracadabra

xfunc$ result: abracadabra

 

This sample program illustrates the use of the XPUTARG and RETURN (expr) statements to support both calling interfaces.

program CONCAT2, 1.0(100)  ! sbx to strip spaces and concatenate 2 strings

!------------------------------------------------------------------------

!NOTES

!   xcall CONCAT, arg1$, arg2$, result$

!or

!   xfunc$("CONCAT", arg1$, arg2$)  - returns result as value of function

!------------------------------------------------------------------------

 

++pragma SBX

 

map1 params

    map2 arg1$,s,0

    map2 arg2$,s,0

    map2 result$,s,0

    

    xgetargs arg1$, arg2$

    xcall TRIM, arg1$

    xcall TRIM, arg2$

    result$ = arg1$ + arg2$

    xputarg 3,result$           ! return result in 3rd param (if XCALL)

    return (result$)            ! in case called via XFUNC$

    end                         ! returns to XCALL caller

 

See Also

Created with Help+Manual 9 and styled with Premium Pack Version 5 © by EC Software