annotate examples/hello.cc @ 8710:739141cde75a ss-3-1-52

fix typo in Array-f.cc
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 09 Feb 2009 21:51:31 +0100
parents 4270ded9ddc6
children 4295d634797d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7019
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
1 /*
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
2
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
3 Copyright (C) 1996, 1997, 1999, 2002, 2003, 2007 John W. Eaton
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
4
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
5 This file is part of Octave.
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
6
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
8 under the terms of the GNU General Public License as published by the
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
10 option) any later version.
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
11
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
15 for more details.
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
16
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
17 You should have received a copy of the GNU General Public License
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
18 along with Octave; see the file COPYING. If not, see
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
19 <http://www.gnu.org/licenses/>.
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
20
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
21 */
4270ded9ddc6 [project @ 2007-10-13 01:42:20 by jwe]
jwe
parents: 4399
diff changeset
22
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
23 // hello.cc -- example of a dynamically linked function for Octave.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
24
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
25 // To use this file, your version of Octave must support dynamic
2153
dc829883f13a [project @ 1996-05-13 08:09:05 by jwe]
jwe
parents: 2152
diff changeset
26 // linking. To find out if it does, type the command
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
27 //
4128
919b2f6573ee [project @ 2002-10-25 20:36:14 by jwe]
jwe
parents: 3242
diff changeset
28 // octave_config_info ("ENABLE_DYNAMIC_LINKING")
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
29 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
30 // at the Octave prompt. Support for dynamic linking is included if
4128
919b2f6573ee [project @ 2002-10-25 20:36:14 by jwe]
jwe
parents: 3242
diff changeset
31 // this expression returns the string "true".
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
32 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
33 // To compile this file, type the command
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
34 //
2137
f9d5d427152d [project @ 1996-05-13 03:48:11 by jwe]
jwe
parents: 2134
diff changeset
35 // mkoctfile hello.cc
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
36 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
37 // at the shell prompt. The script mkoctfile should have been
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
38 // installed along with Octave. Running it will create a file called
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
39 // hello.oct that can be loaded by Octave. To test the hello.oct
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
40 // file, start Octave and type the command
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
41 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
42 // hello ("easy as", 1, 2, 3)
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
43 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
44 // at the Octave prompt. Octave should respond by printing
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
45 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
46 // Hello, world!
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
47 // easy as
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
48 // 1
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
49 // 2
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
50 // 3
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
51 // ans = 3
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
52
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
53 // Additional examples are available in the files in the src directory
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
54 // of the Octave distribution that use the macro DEFUN_DLD_BUILTIN.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
55 // Currently, this includes the files
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
56 //
3045
d2046ca9a380 [project @ 1997-06-06 22:08:11 by jwe]
jwe
parents: 2217
diff changeset
57 // balance.cc fft.cc ifft.cc minmax.cc sort.cc
d2046ca9a380 [project @ 1997-06-06 22:08:11 by jwe]
jwe
parents: 2217
diff changeset
58 // chol.cc fft2.cc ifft2.cc pinv.cc svd.cc
d2046ca9a380 [project @ 1997-06-06 22:08:11 by jwe]
jwe
parents: 2217
diff changeset
59 // colloc.cc filter.cc inv.cc qr.cc syl.cc
d2046ca9a380 [project @ 1997-06-06 22:08:11 by jwe]
jwe
parents: 2217
diff changeset
60 // dassl.cc find.cc log.cc quad.cc
d2046ca9a380 [project @ 1997-06-06 22:08:11 by jwe]
jwe
parents: 2217
diff changeset
61 // det.cc fsolve.cc lsode.cc qzval.cc
d2046ca9a380 [project @ 1997-06-06 22:08:11 by jwe]
jwe
parents: 2217
diff changeset
62 // eig.cc givens.cc lu.cc rand.cc
d2046ca9a380 [project @ 1997-06-06 22:08:11 by jwe]
jwe
parents: 2217
diff changeset
63 // expm.cc hess.cc minmax.cc schur.cc
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
64 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
65 // The difference between DEFUN_DLD and DEFUN_DLD_BUILTIN is that
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
66 // DEFUN_DLD_BUILTIN can define a built-in function that is not
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
67 // dynamically loaded if the operating system does not support dynamic
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
68 // linking. To define your own dynamically linked functions you
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
69 // should use DEFUN_DLD.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
70
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
71 #include <octave/config.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
72
4399
286a3345aa8e [project @ 2003-05-01 03:00:28 by jwe]
jwe
parents: 4128
diff changeset
73 #include <iostream>
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
74
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
75 #include <octave/defun-dld.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
76 #include <octave/error.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
77 #include <octave/oct-obj.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
78 #include <octave/pager.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
79 #include <octave/symtab.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
80 #include <octave/variables.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
81
2152
e9ee6418f62d [project @ 1996-05-13 08:03:26 by jwe]
jwe
parents: 2142
diff changeset
82 // DEFUN_DLD and the macros that it depends on are defined in the
e9ee6418f62d [project @ 1996-05-13 08:03:26 by jwe]
jwe
parents: 2142
diff changeset
83 // files defun-dld.h, defun.h, and defun-int.h.
e9ee6418f62d [project @ 1996-05-13 08:03:26 by jwe]
jwe
parents: 2142
diff changeset
84
e9ee6418f62d [project @ 1996-05-13 08:03:26 by jwe]
jwe
parents: 2142
diff changeset
85 // Note that the third parameter (nargout) is not used, so it is
e9ee6418f62d [project @ 1996-05-13 08:03:26 by jwe]
jwe
parents: 2142
diff changeset
86 // omitted from the list of arguments to DEFUN_DLD in order to avoid
e9ee6418f62d [project @ 1996-05-13 08:03:26 by jwe]
jwe
parents: 2142
diff changeset
87 // the warning from gcc about an unused function parameter.
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
88
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
89 DEFUN_DLD (hello, args, ,
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
90 "[...] = hello (...)\n\
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
91 \n\
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
92 Print greeting followed by the values of all the arguments passed.\n\
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
93 Returns all arguments in reverse order.")
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
94 {
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
95 // The list of values to return. See the declaration in oct-obj.h
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
96
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
97 octave_value_list retval;
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
98
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
99 // This stream is normally connected to the pager.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
100
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
101 octave_stdout << "Hello, world!\n";
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
102
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
103 // The arguments to this function are available in args.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
104
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
105 int nargin = args.length ();
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
106
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
107 // The octave_value_list class is a zero-based array of octave_value
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
108 // objects. The declaration for the octave_value class is in the
3242
8c5ad0b49742 [project @ 1999-04-09 00:20:06 by jwe]
jwe
parents: 3045
diff changeset
109 // file ov.h. The print() method will send its output to
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
110 // octave_stdout, so it will also end up going through the pager.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
111
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
112 for (int i = 0; i < nargin; i++)
2142
3dc97364d58e [project @ 1996-05-13 04:34:11 by jwe]
jwe
parents: 2137
diff changeset
113 {
3dc97364d58e [project @ 1996-05-13 04:34:11 by jwe]
jwe
parents: 2137
diff changeset
114 octave_value tmp = args (i);
3242
8c5ad0b49742 [project @ 1999-04-09 00:20:06 by jwe]
jwe
parents: 3045
diff changeset
115 tmp.print (octave_stdout);
2142
3dc97364d58e [project @ 1996-05-13 04:34:11 by jwe]
jwe
parents: 2137
diff changeset
116 retval (nargin-i-1) = tmp;
3dc97364d58e [project @ 1996-05-13 04:34:11 by jwe]
jwe
parents: 2137
diff changeset
117 }
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
118
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
119 return retval;
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
120 }