Mercurial > hg > octave-nkf
annotate examples/hello.cc @ 12385:c468c5b902b3 release-3-4-x ss-3-3-92
version is now 3.3.92
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 06 Feb 2011 06:27:19 -0500 |
parents | 23385f2c90b7 |
children | 5bc9b9cb4362 |
rev | line source |
---|---|
2134 | 1 // hello.cc -- example of a dynamically linked function for Octave. |
2 | |
3 // To use this file, your version of Octave must support dynamic | |
2153 | 4 // linking. To find out if it does, type the command |
2134 | 5 // |
4128 | 6 // octave_config_info ("ENABLE_DYNAMIC_LINKING") |
2134 | 7 // |
8 // at the Octave prompt. Support for dynamic linking is included if | |
4128 | 9 // this expression returns the string "true". |
2134 | 10 // |
11 // To compile this file, type the command | |
12 // | |
2137 | 13 // mkoctfile hello.cc |
2134 | 14 // |
15 // at the shell prompt. The script mkoctfile should have been | |
16 // installed along with Octave. Running it will create a file called | |
17 // hello.oct that can be loaded by Octave. To test the hello.oct | |
18 // file, start Octave and type the command | |
19 // | |
20 // hello ("easy as", 1, 2, 3) | |
21 // | |
22 // at the Octave prompt. Octave should respond by printing | |
23 // | |
24 // Hello, world! | |
25 // easy as | |
26 // 1 | |
27 // 2 | |
28 // 3 | |
29 // ans = 3 | |
30 | |
31 // Additional examples are available in the files in the src directory | |
32 // of the Octave distribution that use the macro DEFUN_DLD_BUILTIN. | |
33 // Currently, this includes the files | |
34 // | |
3045 | 35 // balance.cc fft.cc ifft.cc minmax.cc sort.cc |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
36 // chol.cc fft2.cc ifft2.cc pinv.cc svd.cc |
3045 | 37 // colloc.cc filter.cc inv.cc qr.cc syl.cc |
38 // dassl.cc find.cc log.cc quad.cc | |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
39 // det.cc fsolve.cc lsode.cc qzval.cc |
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
40 // eig.cc givens.cc lu.cc rand.cc |
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
41 // expm.cc hess.cc minmax.cc schur.cc |
2134 | 42 // |
43 // The difference between DEFUN_DLD and DEFUN_DLD_BUILTIN is that | |
44 // DEFUN_DLD_BUILTIN can define a built-in function that is not | |
45 // dynamically loaded if the operating system does not support dynamic | |
46 // linking. To define your own dynamically linked functions you | |
47 // should use DEFUN_DLD. | |
48 | |
49 #include <octave/config.h> | |
50 | |
4399 | 51 #include <iostream> |
2134 | 52 |
53 #include <octave/defun-dld.h> | |
54 #include <octave/error.h> | |
55 #include <octave/oct-obj.h> | |
56 #include <octave/pager.h> | |
57 #include <octave/symtab.h> | |
58 #include <octave/variables.h> | |
59 | |
2152 | 60 // DEFUN_DLD and the macros that it depends on are defined in the |
61 // files defun-dld.h, defun.h, and defun-int.h. | |
62 | |
63 // Note that the third parameter (nargout) is not used, so it is | |
64 // omitted from the list of arguments to DEFUN_DLD in order to avoid | |
12254 | 65 // the warning from gcc about an unused function parameter. |
2134 | 66 |
67 DEFUN_DLD (hello, args, , | |
68 "[...] = hello (...)\n\ | |
69 \n\ | |
70 Print greeting followed by the values of all the arguments passed.\n\ | |
71 Returns all arguments in reverse order.") | |
72 { | |
73 // The list of values to return. See the declaration in oct-obj.h | |
74 | |
75 octave_value_list retval; | |
76 | |
77 // This stream is normally connected to the pager. | |
78 | |
79 octave_stdout << "Hello, world!\n"; | |
80 | |
81 // The arguments to this function are available in args. | |
82 | |
83 int nargin = args.length (); | |
84 | |
85 // The octave_value_list class is a zero-based array of octave_value | |
86 // objects. The declaration for the octave_value class is in the | |
3242 | 87 // file ov.h. The print() method will send its output to |
2134 | 88 // octave_stdout, so it will also end up going through the pager. |
89 | |
90 for (int i = 0; i < nargin; i++) | |
2142 | 91 { |
92 octave_value tmp = args (i); | |
3242 | 93 tmp.print (octave_stdout); |
2142 | 94 retval (nargin-i-1) = tmp; |
95 } | |
2134 | 96 |
97 return retval; | |
98 } |