# HG changeset patch # User John W. Eaton # Date 1295290775 18000 # Node ID 1e4dfc7a9487f41cd086c93ccbf6e496f35e2fb4 # Parent e9d72a3caa46a99b0caa4293a305cd62f8dbb183 use .argn. to store argument names for inputname function diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2011-01-17 John W. Eaton + + * miscellaneous/inputname.m: Use __varval__ to lookup ".argn." + instead of "argn". + 2011-01-16 Ben Abbott * plot/print.m: For DOS, connect the pipe to ghostscript (bug 31967), diff --git a/scripts/miscellaneous/inputname.m b/scripts/miscellaneous/inputname.m --- 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)) diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2011-01-17 John W. Eaton + + * 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 * ov-usr-fcn.cc (bind_automatic_vars): Mark variables created diff --git a/src/ov-usr-fcn.cc b/src/ov-usr-fcn.cc --- 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; diff --git a/src/variables.cc b/src/variables.cc --- 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; +}