[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: global variables
From: |
John W. Eaton |
Subject: |
Re: global variables |
Date: |
Tue, 15 Dec 2009 13:46:54 -0500 |
On 15-Dec-2009, Naveen Garg wrote:
| On Mon, Dec 14, 2009 at 10:46 PM, John W. Eaton <address@hidden> wrote:
|
| > On 14-Dec-2009, Naveen Garg wrote:
| > | int parse_status;
| > | eval_string("global gvar", false, parse_status);
| > |
| > | I get:
| > | error: eval: invalid use of statement list
| > |
| >
|
|
| > Why don't you avoid the eval and just use the set_global_variable
| > function? That's what it is there for.
| >
| > I could not find a "set_global_variable".
| I am already using set_global_value, but in order for me to have access to
| that value, i need to declare it global...
|
http://www.gnu.org/software/octave/doc/interpreter/Global-Variables.html#Global-Variables
The following works for me:
#include <oct.h>
DEFUN_DLD (foo, args, , "")
{
set_global_value (args(0).string_value (), args(1));
return octave_value ();
}
Then using this function from the Octave prompt:
octave:1> gvar
error: `gvar' undefined near line 1 column 1
octave:1> foo ("gvar", pi)
octave:2> gvar
error: `gvar' undefined near line 2 column 1
octave:2> global gvar
octave:3> gvar
gvar = 3.1416
so yes, it needs to be declared global in the scripting language, but
the set_global_value function can only manipulate the global symbol
table, and it inserts the variable name if it is not already present
in the global table.
So if this doesn't work for you, then I guess you should show a
complete example of what you are doing that is failing for you.
jwe