[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Change of current context ? (whos -file ...)
From: |
Jaroslav Hajek |
Subject: |
Re: Change of current context ? (whos -file ...) |
Date: |
Mon, 22 Sep 2008 16:47:24 +0200 |
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?
> D.
>
>
> --
> David Bateman address@hidden
> Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les
> Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193
> Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
> The information contained in this communication has been classified as:
> [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola
> Confidential Proprietary
>
>
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz