annotate examples/hello.cc @ 2137:f9d5d427152d

[project @ 1996-05-13 03:48:11 by jwe]
author jwe
date Mon, 13 May 1996 03:48:11 +0000
parents f44d96f6ca9f
children 3dc97364d58e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
1 // hello.cc -- example of a dynamically linked function for Octave.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
2
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
3 // To use this file, your version of Octave must support dynamic
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
4 // linking. To find out if your version of Octave supports dynamic
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
5 // linking, type the command
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
6 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
7 // octave_config_info
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
8 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
9 // at the Octave prompt. Support for dynamic linking is included if
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
10 // the output contains either of the lines
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
11 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
12 // Dynamic Linking (dlopen/dlsym): yes
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
13 // Dynamic Linking (shl_load/shl_findsym): yes
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
14
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
15 // To compile this file, type the command
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
16 //
2137
f9d5d427152d [project @ 1996-05-13 03:48:11 by jwe]
jwe
parents: 2134
diff changeset
17 // mkoctfile hello.cc
2134
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
18 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
19 // at the shell prompt. The script mkoctfile should have been
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
20 // 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
21 // 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
22 // file, start Octave and type the command
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
23 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
24 // hello ("easy as", 1, 2, 3)
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
25 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
26 // at the Octave prompt. Octave should respond by printing
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
27 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
28 // Hello, world!
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
29 // easy as
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
30 // 1
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
31 // 2
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
32 // 3
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
33 // ans = 3
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
34
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
35 // 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
36 // 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
37 // Currently, this includes the files
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
38 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
39 // balance.cc fft.cc hess.cc lu.cc schur.cc
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
40 // chol.cc fft2.cc ifft.cc minmax.cc sort.cc
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
41 // colloc.cc filter.cc ifft2.cc pinv.cc svd.cc
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
42 // dassl.cc find.cc inv.cc qr.cc syl.cc
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
43 // det.cc fsolve.cc log.cc quad.cc
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
44 // eig.cc fsqp.cc lsode.cc qzval.cc
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
45 // expm.cc givens.cc lu.cc rand.cc
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
46 //
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
47 // 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
48 // 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
49 // dynamically loaded if the operating system does not support dynamic
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
50 // linking. To define your own dynamically linked functions you
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
51 // should use DEFUN_DLD.
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 #include <octave/config.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
54
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
55 #include <iostream.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
56
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
57 #include <octave/defun-dld.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
58 #include <octave/error.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
59 #include <octave/oct-obj.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
60 #include <octave/pager.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
61 #include <octave/symtab.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
62 #include <octave/variables.h>
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
63
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
64 // Note, nargout is not used, so it is omitted from the argument list
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
65 // to avoid the warning from gcc about an unused function parameter.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
66
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
67 DEFUN_DLD (hello, args, ,
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
68 "[...] = hello (...)\n\
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
69 \n\
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
70 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
71 Returns all arguments in reverse order.")
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
72 {
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
73 // 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
74
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
75 octave_value_list retval;
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
76
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
77 // This stream is normally connected to the pager.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
78
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
79 octave_stdout << "Hello, world!\n";
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
80
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
81 // The arguments to this function are available in args.
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
82
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
83 int nargin = args.length ();
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
84
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
85 // 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
86 // objects. The declaration for the octave_value class is in the
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
87 // file pt-const.h. The print() method will send its output to
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
88 // 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
89
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
90 for (int i = 0; i < nargin; i++)
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
91 retval (nargin-i-1) = args(i).print ();
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
92
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
93 return retval;
f44d96f6ca9f [project @ 1996-05-13 03:23:50 by jwe]
jwe
parents:
diff changeset
94 }