# HG changeset patch # User John W. Eaton # Date 1262894839 18000 # Node ID e42b1bbd1052b45b1e8d3b4008657cbcf0495b01 # Parent 897e62651c0adc8bc682c30a406b5ef69806e4e1 variables.cc (get_top_level_value, set_top_level_value): new functions diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2010-01-07 John W. Eaton + + * variables.cc (get_global_value): Fix function name in error message. + (get_top_level_value, set_top_level_value): New functions. + * variables.h (get_top_level_value, set_top_level_value): + Provide decls. + + * symtab.h (symbol_table::top_level_varref, + symbol_table::top_level_varval): New static functions. + 2010-01-07 Jaroslav Hajek * utils.cc (octave_sleep (double)): Add OCTAVE_QUIT. diff --git a/src/symtab.h b/src/symtab.h --- a/src/symtab.h +++ b/src/symtab.h @@ -1084,6 +1084,18 @@ return (p != global_table.end ()) ? p->second : octave_value (); } + static octave_value& + top_level_varref (const std::string& name) + { + return varref (name, top_scope (), 0); + } + + static octave_value + top_level_varval (const std::string& name) + { + return varval (name, top_scope (), 0); + } + static octave_value& persistent_varref (const std::string& name) { static octave_value foobar; diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -607,7 +607,7 @@ octave_value val = symbol_table::global_varval (nm); if (val.is_undefined () && ! silent) - error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); + error ("get_global_value: undefined symbol `%s'", nm.c_str ()); return val; } @@ -618,6 +618,23 @@ symbol_table::global_varref (nm) = val; } +octave_value +get_top_level_value (const std::string& nm, bool silent) +{ + octave_value val = symbol_table::top_level_varval (nm); + + if (val.is_undefined () && ! silent) + error ("get_top_level_value: undefined symbol `%s'", nm.c_str ()); + + return val; +} + +void +set_top_level_value (const std::string& nm, const octave_value& val) +{ + symbol_table::top_level_varref (nm) = val; +} + // Variable values. octave_value diff --git a/src/variables.h b/src/variables.h --- a/src/variables.h +++ b/src/variables.h @@ -78,7 +78,14 @@ extern OCTINTERP_API octave_value get_global_value (const std::string& nm, bool silent = false); -extern OCTINTERP_API void set_global_value (const std::string& nm, const octave_value& val); +extern OCTINTERP_API void +set_global_value (const std::string& nm, const octave_value& val); + +extern OCTINTERP_API octave_value +get_top_level_value (const std::string& nm, bool silent = false); + +extern OCTINTERP_API void +set_top_level_value (const std::string& nm, const octave_value& val); extern OCTINTERP_API octave_value set_internal_variable (bool& var, const octave_value_list& args,