evesely
3rd January 2003, 17:42
Is there a nice way of forwarding on a variable length list of function arguments? What I am looking for is something similar to on.main.table, where the function call can have a variable number of arguments and that function will pass on all or a portion of the argument list to another function (ideally without know or caring about the argument types).
For example:
my.func(arg1, arg2, arg3, arg4)
...
function my.func(...)
{
<processing>
new.func(<list of arguments>)
}
In calling new.func in this example, I might to send it args 1-4 or maybe just 2-4, etc.
I have tried using new.func(...), but that doesn't seem to work. I also tried making a giant, multi-level ?: using get.<type>.arg() for a simple case where I knew the number of arguments ahead of time (this failed because of double:string compatibility errors).
Thoughts?:confused:
sdvries
6th January 2003, 10:17
A solution can be by using defines instead of functions.
#define my.func( ... )
^{
^ <processing>
^ new.func( ... )
^}
See also the programmers manual (topic preprocessor) for more info.
Regards,
Sicco
evesely
6th January 2003, 15:34
That works OK if the call and the actual function are in the same object. In this case, however, the first call is in one object and the function is in another. I guess I didn't really spell this out in my example, but consider the definition of my.func to be in some common library. It gets called from different scripts, does some processing (e.g., logging/tracing), and then calls the desired function (which may reside in a third object). The macro/preprocessor definition won't work here. :(
Any other thoughts?:confused:
sdvries
6th January 2003, 16:54
A more difficult construction, but more interesting :).
It can be done by using get.arg.type in combination with get.<type>arg and
parse_and_exec_function.
For example:
string array_args(1,1) based
long nr_of_args
nr_of_args = get.argc()
for i = 1 to nr_of_args
on case get.arg.type(i)
case DB.LONG:
get.long.arg(i)
|* Convert the argument to a string.
|* store in array_args.
break
case DB.DOUBLE:
get.double.arg(i)
|* Convert the argument to a
|* string.
|* store in array_args
...
break
case DB.STRING:
case DB.MULTIBYTE:
get.string.arg(i)
|* No conversion needed
|* store in array_args.
....
break
endcase
endfor
string funccall(2048) |* or dynamic
string funccall = "new.func(
for i = 1 to nr.of.args
funccall = funccall & array_args(1,i)
if i < nr.of.args then
funccall = funccall & ","
endif
endfor
funccall = funccall & ")"
ret = parse_and_exec_function( "o<dllobject>", funccall, ret2, ret_call )
Note: I have not tested this code :).
And it only works if the arguments are no arrays.
Regards,
Sicco
evesely
6th January 2003, 20:06
I think this line of thinking will get me where I want to go. Thanks.:D