Call a function in a shared library: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added whitespace, used a template for the output section.)
(→‎{{header|REXX}}: added more error checking, added comments and whitespace.)
Line 1,622: Line 1,622:


The example is using the standard library that is supplied with Regina REXX that contains a wide range of functions.
The example is using the standard library that is supplied with Regina REXX that contains a wide range of functions.
<lang rexx>/*REXX pgm calls a function (systextscreensize) in a shared library (regutil).*/
z= rxfuncadd('sysloadfuncs', "regutil", 'sysloadfuncs') /*add a function lib.*/
if z\==0 then do /*test the return cod*/
say 'return code' z "from rxfuncadd" /*tell about bad RC. */
exit z /*exit this program. */
end


A little extra boilerplate code was added to make sure the return codes were OK.
call sysloadfuncs /*load the functions.*/
<lang rexx>/*REXX program calls a function (sysTextScreenSize) in a shared library (regutil). */


rca= rxFuncAdd('sysloadfuncs', "regutil", 'sysloadfuncs') /*add a function library. */
/* [↓] call a particular function. */
y= systextscreensize() /*Y now contains 2 numbers: rows cols */
if rca\==0 then do /*examine the return code.*/
parse var y rows cols . /*obtain the two numeric words in Y. */
say 'return code' rca "from rxFuncAdd" /*tell about bad " " */
say 'rows=' rows /*display the number of (terminal) rows*/
exit rca /*exit this program with RC. */
say 'cols=' cols /* " " " " " cols*/
end

call SysDropFuncs /*clean up: make functions inaccessible*/
/*stick a fork in it, we're all done. */</lang>
rcl= sysLoadFuncs() /*we can load the functions. */
if rcl\==0 then do /*examine the return code.*/
say 'return code' rcl "from sysLoadFuncs" /*tell about bad " " */
exit rcl /*exit this program with RC. */
end

/* [↓] call a particular function. */
y= sysTextScreenSize() /*Y now contains two words: rows cols */
parse var y rows cols . /*obtain the two numeric words in Y. */
say 'rows=' rows /*display the number of (terminal) rows*/
say 'cols=' cols /* " " " " " cols*/

rcd= SysDropFuncs() /*clean up: make functions inaccessible*/
if rcd\==0 then do /*examine the return code.*/
say 'return code' rcd "from sysDropFuncs" /*tell about bad " " */
exit rcd /*exit this program with RC. */
end
exit 0 /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; (which happens to reflect the program's author's particular screen size for the "DOS" window):}}
{{out|output|text=&nbsp; (which happens to reflect the program's author's particular screen size for the "DOS" window):}}
<pre>
<pre>