octave-maintainers
[Top][All Lists]
Advanced

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

Re: Change of current context ? (whos -file ...)


From: John W. Eaton
Subject: Re: Change of current context ? (whos -file ...)
Date: Mon, 22 Sep 2008 14:28:47 -0400

On 22-Sep-2008, Jaroslav Hajek wrote:

| On Mon, Sep 22, 2008 at 4:01 PM, David Bateman
| <address@hidden> wrote:
| > I just thought of a way to easily implement "whos -file", but I'm having
| > issues with the use of the new symbol table code. What I thought to do was
| > something like
| >
| >
| >     if (argv[i] == "-file")
| >   {
| >     if (i == argc - 1)
| >       error ("whos: -file argument must be followed by a file name");
| >     else
| >       {
| >         std::string nm = argv [i + 1];
| >
| >         symbol_table::scope_id tmp_scope = symbol_table::alloc_scope ();
| >
| >         unwind_protect::begin_frame ("do_who_file");
| >
| >         symbol_table::push_scope (tmp_scope);
| >
| >         unwind_protect::add (symbol_table::pop_scope);
| >
| >         feval ("load", octave_value (nm), 0);
| >
| >         std::string newmsg = std::string ("Variables in the file ") +
| >       nm + ":\n\n";
| >
| >         if (!error_state)
| >       retval =  do_who (i - 1, argv, return_list, verbose, newmsg);
| >
| >         unwind_protect::run_frame ("do_who_file");
| >
| >         symbol_table::erase_scope (tmp_scope);
| >       }
| >
| >     return retval;
| >   }
| >
| > That if the -file flag is given treats the following argument as a file
| > name, and all following arguments are dropped, a new context is created the
| > file is loaded to this context and who is rerun within this temporary
| > context.
| >
| > However, the above doesn't seem to be the correct manner to push/pop the
| > current context. Anyone see what I'm missing?
| >
| 
| Maybe you also need push_context+pop_context and clear_variables at
| the end? At least that's what octave_user_function::do_multi_index_op
| seems to do.
| 
| Btw. isn't this approach going to show also global variables?

I understand the motivation for this approach as it would be a
relatively simple change, but maybe we should instead modify do_load
in load-save.cc to skip the call to install_loaded_variable and return
the variable names instead?  I see do_load already has a way to return
the names (the list_only option).  This change might require a little
refactoring, but maybe it would not be too difficult?

jwe


reply via email to

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