Mercurial > hg > octave-nkf
annotate examples/code/globaldemo.cc @ 20753:2f8500ca91d3
eliminate error_state from example files
* addtwomatrices.cc, celldemo.cc, embedded.cc, fortrandemo.cc,
funcdemo.cc, globaldemo.cc, helloworld.cc, make_int.cc, paramdemo.cc,
stringdemo.cc, structdemo.cc, unwinddemo.cc:
Eliminate use of global error_state variable.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 03 Oct 2015 16:05:27 -0400 |
parents | c8240a60dd01 |
children |
rev | line source |
---|---|
6572 | 1 #include <octave/oct.h> |
2 | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9053
diff
changeset
|
3 DEFUN_DLD (globaldemo, args, , "Global Demo") |
6572 | 4 { |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9053
diff
changeset
|
5 octave_value retval; |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
6 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
7 if (args.length () != 1) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
8 print_usage (); |
6572 | 9 |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
10 std::string s = args(0).string_value (); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
11 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
12 octave_value tmp = get_global_value (s, true); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
13 |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
14 if (tmp.is_defined ()) |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
15 retval = tmp; |
6572 | 16 else |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
17 retval = "Global variable not found"; |
6572 | 18 |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
19 set_global_value ("a", 42.0); |
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
20 |
6572 | 21 return retval; |
22 } |