SMEXEC-Compatible Function In SIMPOL
In the previous section we discussed in-depth a program in SBL that calls a SIMPOL function in
a library called jpeglib.sml
. The actual function in the
SIMPOL source code needs to be written to the interface provided by SMEXEC. In this section we
will look at that function.
The original function prototype in SIMPOL is as follows:
function
getjpegsize
(
string
,
integer sFilename
,
integer iWidth
) export
iHeight
Unfortunately this function cannot be called via SMEXEC directly, since functions that are called
from SMEXEC, as we learned in the previous section, can only take a single string
argument and can only return a string result. That means that we will have to create
an interface function that can be called via SMEXEC and that can then call the desired function and
return the results in the correct format. For ease of understanding later, we can call this function
smexec_getjpegsize()
. The source code for the interface function is shown below:
function smexec_getjpegsize(string sFilename) export string sResult integer iWidth, iHeight, iResult iWidth = 0 iHeight = 0 iResult = getjpegsize(sFilename, iWidth, iHeight) if iResult == 0 sResult = "w:" + .tostr(iWidth, 10) + " h:" + \ .tostr(iHeight, 10) else sResult = "e:" + .tostr(iResult, 10) end if end function sResult
In the interface function the only parameter passed in is the
sFilename
parameter and the values of the two integers are
converted to strings and passed in the return value if the function succeeds and if it fails the
error value is passed in the return value. The programmer is free here to implement any method
desired to transmit the information via the string result back to the caller.