Mercurial > hg > octave-nkf
annotate examples/code/embedded.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 |
---|---|
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 #include <iostream> |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 #include <octave/oct.h> |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 #include <octave/octave.h> |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 #include <octave/parse.h> |
17781
d029ef208e4a
fix segfault/corrupted memory when terminating an embedded interpreter.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
16867
diff
changeset
|
5 #include <octave/toplev.h> |
9053
4295d634797d
remove copyright notices from example files
John W. Eaton <jwe@octave.org>
parents:
8097
diff
changeset
|
6 |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 int |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 main (void) |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 { |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 string_vector argv (2); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 argv(0) = "embedded"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 argv(1) = "-q"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 |
16481
27a6bb1a2f74
Backport working embedded.cc example for documentation.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
14 octave_main (2, argv.c_str_vec (), 1); |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 octave_idx_type n = 2; |
16481
27a6bb1a2f74
Backport working embedded.cc example for documentation.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
17 octave_value_list in; |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 |
17791
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
17781
diff
changeset
|
19 for (octave_idx_type i = 0; i < n; i++) |
16483
fcf1b0b52083
Use a better example of gcd() in embedded.cc
Rik <rik@octave.org>
parents:
16482
diff
changeset
|
20 in(i) = octave_value (5 * (i + 2)); |
17791
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
17781
diff
changeset
|
21 |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 octave_value_list out = feval ("gcd", in, 1); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 |
20753
2f8500ca91d3
eliminate error_state from example files
John W. Eaton <jwe@octave.org>
parents:
19225
diff
changeset
|
24 if (out.length () > 0) |
17791
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
17781
diff
changeset
|
25 std::cout << "GCD of [" |
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
17781
diff
changeset
|
26 << in(0).int_value () |
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
17781
diff
changeset
|
27 << ", " |
16481
27a6bb1a2f74
Backport working embedded.cc example for documentation.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
28 << in(1).int_value () |
17791
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
17781
diff
changeset
|
29 << "] is " << out(0).int_value () |
16481
27a6bb1a2f74
Backport working embedded.cc example for documentation.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
30 << std::endl; |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 else |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 std::cout << "invalid\n"; |
17791
224e76250443
Use GNU style coding conventions for code in examples/
Rik <rik@octave.org>
parents:
17781
diff
changeset
|
33 |
17781
d029ef208e4a
fix segfault/corrupted memory when terminating an embedded interpreter.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
16867
diff
changeset
|
34 clean_up_and_exit (0); |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 } |