help-octave
[Top][All Lists]
Advanced

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

Re: Exporting a variable to the global workspace from a C++ function


From: Justin Bare
Subject: Re: Exporting a variable to the global workspace from a C++ function
Date: Wed, 12 Aug 2009 11:18:27 -0400 (EDT)
User-agent: SquirrelMail/1.4.8-4.fc5

Thank you! I am new to Octave and, yes, I was not aware of how to access
the global variable from the prompt.

> On 12-Aug-2009, Justin Bare wrote:
>
> | I tried this as you suggested:
> |
> |     symbol_table::global_varref("x") = 9;
> |     symbol_table::set_scope(symbol_table::top_scope);
> |     symbol_table::insert("x").mark_global();
> |
> | but I get compiler errors that say:
> |
> |     readbuf.cpp:29: error: ‘global_varref’ is not a member of
> ‘symbol_table’
> |     readbuf.cpp:30: error: ‘set_scope’ is not a member of ‘symbol_table’
> |     readbuf.cpp:30: error: ‘top_scope’ is not a member of ‘symbol_table’
> |     readbuf.cpp:31: error: ‘insert’ is not a member of ‘symbol_table’
> |
> | even though I have included the Octave/C++ library
> |
> | How do I make this compile?
>
> Your earlier method of using set_global_value was the right way to
> install a global variable.  But I think you are confused about how to
> access globals from the interpreter prompt.
> |
> | > On Wed, Aug 12, 2009 at 2:59 PM, Justin
> | > Bare<address@hidden> wrote:
> | >> I tried the function you gave me in this way inside a C++ function:
> | >> ,A (B ,A (Bstring c = "x";
> | >> ,A (B ,A (Bconst string& cref = c;
> | >> ,A (B ,A (Boctave_value x = 9;
> | >> ,A (B ,A (Bconst octave_value& xref = x;
> | >>
> | >> ,A (B ,A (Bcout << cref << endl;
> | >> ,A (B ,A (Bcout << xref.int_value() << endl;
> | >>
> | >> ,A (B ,A (Bset_global_value(cref, xref);
> | >> ,A (B ,A (Bcout << get_global_value("x").int_value() << endl;
> | >>
> | >> Which prints out this in Octave:
> | >> x
> | >> 9
> | >> 9
> | >>
> | >> But what I want to do is create the variable x in this C++ function
> and
> | >> send it to the global workspace so that when I type "x" in the octave
> | >> command line it will give me "x = 9" instead of "error: `x' undefined
> | >> near
> | >> line 39 column 1"
> | >>
> | >> Is there a way to do this?
>
> At the command line, type
>
>   global x
>   x
>
> then you should see "9".
>
> If you want to install a variable in the base workspace (so you don't
> have to declare the variable global to access it at the interpreter
> prompt) then I don't think there is a C++ function in Octave to do
> this.  It's not a normal thing to want to do, so I'd ask why do you
> think you want to do this?  Why not simply have your function compute
> a value and return it?
>
> jwe
>


-- 

Justin Bare
Robotic Research, LLC.
814 West Diamond Ave, Suite 301
Gaithersburg, MD 20878
240-631-0008 Ext 246


reply via email to

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