Mercurial > hg > octave-nkf
changeset 11558:1e4dfc7a9487
use .argn. to store argument names for inputname function
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 17 Jan 2011 13:59:35 -0500 |
parents | e9d72a3caa46 |
children | 26a6435857bc |
files | scripts/ChangeLog scripts/miscellaneous/inputname.m src/ChangeLog src/ov-usr-fcn.cc src/variables.cc |
diffstat | 5 files changed, 45 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2011-01-17 John W. Eaton <jwe@octave.org> + + * miscellaneous/inputname.m: Use __varval__ to lookup ".argn." + instead of "argn". + 2011-01-16 Ben Abbott <bpabbott@mac.com> * plot/print.m: For DOS, connect the pipe to ghostscript (bug 31967),
--- a/scripts/miscellaneous/inputname.m +++ b/scripts/miscellaneous/inputname.m @@ -28,7 +28,7 @@ function s = inputname (n) if (nargin == 1) - s = evalin ("caller", sprintf ("deblank (argn(%d,:));", n)); + s = evalin ("caller", sprintf ("__varval__ (\".argn.\"){%d};", n)); ## For compatibility with Matlab, return empty string if argument ## name is not a valid identifier. if (! isvarname (s))
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2011-01-17 John W. Eaton <jwe@octave.org> + + * ov-usr-fcn.cc (octave_user_function::bind_automatic_vars): + Save argument names in hidden variable .argn.. + + * variables.cc (F__varval__): New function. + 2011-01-17 John W. Eaton <jwe@octave.org> * ov-usr-fcn.cc (bind_automatic_vars): Mark variables created
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -544,9 +544,18 @@ { if (! arg_names.empty ()) { + // It is better to save this in the hidden variable .argn. and + // then use that in the inputname function instead of using argn, + // which might be redefined in a function. Keep the old argn name + // for backward compatibility of functions that use it directly. + symbol_table::varref ("argn") = arg_names; + symbol_table::varref (".argn.") = Cell (arg_names); + + symbol_table::mark_hidden (".argn."); symbol_table::mark_automatic ("argn"); + symbol_table::mark_automatic (".argn."); } symbol_table::varref (".nargin.") = nargin;
--- a/src/variables.cc +++ b/src/variables.cc @@ -2545,3 +2545,26 @@ feval (func_name, octave_value (name)); } } + +DEFUN (__varval__, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __varval__ (@var{name})\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + { + std::string name = args(0).string_value (); + + if (! error_state) + retval = symbol_table::varval (args(0).string_value ()); + else + error ("__varval__: expecting argument to be variable name"); + } + else + print_usage (); + + return retval; +}