You will need a new function prototype. The code
becomes
function [blah] = fn(blah, varargin)
The values in
function [blah] = fn(blah, ...)
varargin = list(all_va_args);
varargin{i}
can then be referenced as
nth(varargin, i)
. If you want to use more than one
of these values in a function, e.g., t(varargin{:})
,
then you must use the apply function defined as follows:
function [...] = apply(_name, ...)
if nargin == 0
usage("[r1, r2, ...] = apply(fn, v1, v2, ...)");
endif
## build return value list
if nargout == 0
_exp = "";
elseif nargout == 1
_exp = "_r.r1 =";
else
_exp = "[_r.r1";
for _i = 2:nargout
_exp = [ _exp, ", _r.r", num2str(_i) ];
endfor
_exp = [ _exp, "]=" ];
endif
## add function name
_exp = [ _exp, _name ];
## build input parameter list
_in = append(list(), va_all_args);
if (length(_in) == 1)
_exp = [ _exp, "(nth(_in, 1));" ];
elseif length(_in) > 1
_exp = [ _exp, "(nth(_in, 1)" ];
for _i = 2: length(_in)
_exp = [ _exp, ", nth(_in, ", num2str(_i), ")" ];
endfor
_exp = [ _exp, ");" ];
endif
## evaluate
eval(_exp);
## extract returned values
for i = 1: nargout
eval(["vr_val(_r.r", num2str(i), ");"]);
endfor
endfunction
length(_in)
with rows(struct_elements(_in))
.
varargout = fn (blah)
with
[...] = fn (blah)
varargout = list();
Then, before any return you must punch in the return values to octave
using:
for i = 1:length(varargout)
vr_val(nth(varargout, i));
endfor
And that's it.
varargout{i} = expr;
with eval(["varargout.r", num2str(i), "=expr;"]);
in addition to what you do for 2.1.x.