Get Global values in Oct file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Get Global values in Oct file

babelproofreader
How to access global values in an oct file? When I try using
get_global_value() I get the warning

warning: ‘octave_value get_global_value(const string&, bool)’ is deprecated:
[4.4]: use 'symbol_table::global_varval' instead [-Wdeprecated-declarations]

What is the new way of using 'symbol_table::global_varval'? I cannot find
any documentation for this. I'm using Octave 5.1.0 on a Linux system.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Get Global values in Oct file

Carlo de Falco-2


> Il giorno 30 ott 2019, alle ore 17:01, babelproofreader <[hidden email]> ha scritto:
>
> How to access global values in an oct file? When I try using
> get_global_value() I get the warning
>
> warning: ‘octave_value get_global_value(const string&, bool)’ is deprecated:
> [4.4]: use 'symbol_table::global_varval' instead [-Wdeprecated-declarations]
>
> What is the new way of using 'symbol_table::global_varval'? I cannot find
> any documentation for this. I'm using Octave 5.1.0 on a Linux system.

There is not much documentation, but the definition of symbol_table::global_varval
is given here :

http://octave.org/doxygen/5.1/d8/d9b/symtab_8h_source.html#l00161

and it looks pretty much self explaining ...

c.

Reply | Threaded
Open this post in threaded view
|

Re: Get Global values in Oct file

siko1056
On 10/31/19 1:52 AM, Carlo De Falco wrote:

>
>
>> Il giorno 30 ott 2019, alle ore 17:01, babelproofreader <[hidden email]> ha scritto:
>>
>> How to access global values in an oct file? When I try using
>> get_global_value() I get the warning
>>
>> warning: ‘octave_value get_global_value(const string&, bool)’ is deprecated:
>> [4.4]: use 'symbol_table::global_varval' instead [-Wdeprecated-declarations]
>>
>> What is the new way of using 'symbol_table::global_varval'? I cannot find
>> any documentation for this. I'm using Octave 5.1.0 on a Linux system.
>
> There is not much documentation, but the definition of symbol_table::global_varval
> is given here :
>
> http://octave.org/doxygen/5.1/d8/d9b/symtab_8h_source.html#l00161
>
> and it looks pretty much self explaining ...
>
> c.
>
Hmm, there is really not much documentation.  I attached an overhauled
version of Octave's globaldemo.cc example.

@jwe: can you confirm that this is the right way to go in the future
with including the interpreter and using DEFMETHOD_DLD?  See your cset:

   https://hg.savannah.gnu.org/hgweb/octave/rev/b29904962d2d

Then I can update the demo to cause less confusion.  At least it
compiles and works for me without errors and warnings:

octave:1> mkoctfile globaldemo.cc
octave:2> globaldemo ("hi")
ans = Global variable not found
octave:3> global a
octave:4> a
a =  42
octave:5> global hi
octave:6> hi = "wuff"
hi = wuff
octave:7> globaldemo ("hi")
ans = wuff

HTH,
Kai



globaldemo.cc (517 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Get Global values in Oct file

John W. Eaton
Administrator
On 10/30/19 10:28 PM, Kai Torben Ohlhus wrote:

> @jwe: can you confirm that this is the right way to go in the future
> with including the interpreter and using DEFMETHOD_DLD?  See your cset:
>
>     https://hg.savannah.gnu.org/hgweb/octave/rev/b29904962d2d
>
> Then I can update the demo to cause less confusion.  At least it
> compiles and works for me without errors and warnings:

Yes, that is the way to do it in 5.1.  In the next major version you
will be able to do this job without having to reference the symbol table
object:

   octave_value tmp = interp.global_varval (name);

and

   interp.global_assign (name, value);

but the symbol_table functions will remain for backward compatibility.

jwe


Reply | Threaded
Open this post in threaded view
|

Re: Get Global values in Oct file

siko1056
On 10/31/19 2:09 PM, John W. Eaton wrote:

> On 10/30/19 10:28 PM, Kai Torben Ohlhus wrote:
>
>> @jwe: can you confirm that this is the right way to go in the future
>> with including the interpreter and using DEFMETHOD_DLD?  See your cset:
>>
>>     https://hg.savannah.gnu.org/hgweb/octave/rev/b29904962d2d
>>
>> Then I can update the demo to cause less confusion.  At least it
>> compiles and works for me without errors and warnings:
>
> Yes, that is the way to do it in 5.1.  In the next major version you
> will be able to do this job without having to reference the symbol table
> object:
>
>   octave_value tmp = interp.global_varval (name);
>
> and
>
>   interp.global_assign (name, value);
>
> but the symbol_table functions will remain for backward compatibility.
>
> jwe

Thank for checking jwe.  Programming oct-files really becomes a charm =)
 I improved the example on the stable branch, as it is already relevant
for Octave 5 users:

  https://hg.savannah.gnu.org/hgweb/octave/rev/18fea1c5b21a

Best,
Kai