Remove n function arguments from the stack
variable args = __pop_args(Integer_Type n);
This function together with the companion function __push_args
is useful for passing the arguments of a function to another function.
__pop_args returns an array of n structures with a
single structure field called value, which represents the value
of the argument.
Consider the following print function. It prints all its
arguments to stdout separated by spaces:
define print ()
{
variable i;
variable args = __pop_args (_NARGS);
for (i = 0; i < _NARGS; i++)
{
() = fputs (string (args[i].value), stdout);
() = fputs (" ", stdout);
}
() = fputs ("\n", stdout);
() = fflush (stdout);
}
Now consider the problem of defining a function called ones
that returns a multi-dimensional array with all the elements set to
1. For example, ones(10) should return a 1-d array of ones,
whereas ones(10,20) should return a 10x20 array.
define ones ()
{
!if (_NARGS) return 1;
variable a;
a = __pop_args (_NARGS);
return @Array_Type (Integer_Type, [__push_args (a)]) + 1;
}
Here, __push_args was used to push on the arguments passed to
the ones function onto the stack to be used when dereferencing
Array_Type.
- slangrtl
-
__class_id,
__class_type,
__eqs,
__get_reference,
__is_initialized,
__push_args,
_nargs,
_pop_n,
_stk_roll,
_typeof,
array_info,
dup,
is_defined,
is_struct_type,
length,
pop,
typecast,
typeof
|