Mercurial > hg > octave-nkf
annotate examples/embedded.cc @ 15104:093961d9ebed gui
Fixed self-assignment bug found by Torsten.
* find-dialog.cc: Fixed self-assignment in constructor.
author | Jacob Dawid <jacob.dawid@gmail.com> |
---|---|
date | Sat, 04 Aug 2012 10:53:58 +0200 |
parents | 460a3c6d8bf1 |
children | 84873dc19757 |
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> |
9053
4295d634797d
remove copyright notices from example files
John W. Eaton <jwe@octave.org>
parents:
8097
diff
changeset
|
5 |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 int |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 main (void) |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 { |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 string_vector argv (2); |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 argv(0) = "embedded"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 argv(1) = "-q"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14801
diff
changeset
|
13 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
|
14 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 octave_idx_type n = 2; |
14801
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
16 octave_value_list in; |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 |
14801
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
18 for (octave_idx_type i = 0; i < n; i++) |
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
19 in(i) = octave_value (5 * (i + 1)); |
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
20 |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 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
|
22 |
14801
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
23 |
8097
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 if (!error_state && out.length () > 0) |
14801
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
25 std::cout << "GCD of [" |
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
26 << in(0).int_value () |
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
27 << ", " |
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
28 << in(1).int_value () |
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
12174
diff
changeset
|
29 << "] is " << out(0).int_value () |
3c5e6971064c
fix embedding example.
Carlo de Falco <cdf@users.sourceforge.net>
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"; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 return 0; |
804c60f92fb1
Add explanationation of initializing the interpreter in a standalone program
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 } |