help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best replacement for curr_sym_tab in octave 3.2


From: John W. Eaton
Subject: Re: Best replacement for curr_sym_tab in octave 3.2
Date: Thu, 7 Jan 2010 15:08:13 -0500

On  6-Jan-2010, Joshua Redstone wrote:

| Looking at the code more, I think the entire purpose is to assign a variable
| at the top level a value.
| I think in 3.2, I can just use symbol_table::varref(name,
| symbol_table::top_level()).
| Is there a backwards compatible way of doing this?

I guess you could write functions that are similar to the
get_global_value and set_global_value functions, but use
top_level_symtab instead fo global_sym_tab.

Maybe we should have these functions, so I checked in this change:

  http://hg.savannah.gnu.org/hgweb/octave/rev/e42b1bbd1052

The functions in this changeset should also work in 3.2.x.

For 3.0 and earlier, it guess it would be (untested):

octave_value
get_top_level_value (const std::string& nm, bool silent)
{
  octave_value retval;

  symbol_record *sr = top_level_sym_tab->lookup (nm);

  if (sr)
    {
      octave_value sr_def = sr->def ();

      if (sr_def.is_defined ())
        retval = sr_def;
      else if (! silent)
        error ("get_top_level_value: undefined symbol `%s'", nm.c_str ());
    }
  else if (! silent)
    error ("get_top_level_value: unknown symbol `%s'", nm.c_str ());

  return retval;
}

void
set_top_level_value (const std::string& nm, const octave_value& val)
{
  symbol_record *sr = top_level_sym_tab->lookup (nm, true);

  if (sr)
    sr->define (val);
  else
    panic_impossible ();
}

| I was thinking of using mkmf to try to detect whether symbol_table was
| present in symtab.h, but, at least the ruby mkmf package
| testing for presence of symtab.h by trying to compile a program consisting
| of a single statement "#include <symtab.h>",
| and it produces gobs of errors - looks like maybe symtab.h does not include
| everything it depends on?

Does

  #include <octave/config.h>
  #include <octave/symtab.h>

work?

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]