525
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
525
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
525
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_defun_h) |
|
24 #define octave_defun_h 1 |
|
25 |
|
26 #if defined (octave_defun_dld_h) |
|
27 #error defun.h and defun-dld.h both included in same file! |
|
28 #endif |
|
29 |
|
30 #include "defun-int.h" |
|
31 |
550
|
32 // Define a builtin variable. |
|
33 // |
1957
|
34 // name is the name of the variable, unquoted. |
1340
|
35 // |
|
36 // defn is the initial value for the variable. |
550
|
37 // |
|
38 // ins_as_fcn is a flag that says whether to install the variable as |
|
39 // if it were a function (allowing the name to also be used as a |
|
40 // variable by users, but recover its original definition if cleared). |
|
41 // |
1340
|
42 // protect is a flag that says whether it should be possible to give |
|
43 // the variable a new value. |
|
44 // |
550
|
45 // eternal is a flag that says whether it should be possible to |
|
46 // clear the variable. Most builtin variables are eternal, and |
|
47 // cannot be cleared. |
|
48 // |
|
49 // sv_fcn is a pointer to a function that should be called whenever |
|
50 // this variable is given a new value. It can be 0 if there is no |
|
51 // function to call. See also the code in user-prefs.cc. |
|
52 // |
|
53 // doc is the simple help text for this variable. |
|
54 |
1957
|
55 #define DEFVAR(name, defn, inst_as_fcn, sv_fcn, doc) \ |
|
56 DEFVAR_INT (#name, SBV_ ## name, defn, inst_as_fcn, 0, sv_fcn, doc) |
|
57 |
|
58 // Define a builtin-constant, and a corresponding variable that can be |
|
59 // redefined. This is just the same as DEFVAR, except that it defines |
|
60 // `name' as a variable, and `__name__' as a constant that cannot be |
|
61 // redefined. |
|
62 |
|
63 #define DEFCONST(name, defn, inst_as_fcn, sv_fcn, doc) \ |
2890
|
64 DEFVAR_INT (#name, SBV_ ## name, defn, inst_as_fcn, false, sv_fcn, doc); \ |
|
65 DEFVAR_INT ("__" ## #name ## "__", XSBV_ ## name, defn, false, true, \ |
|
66 sv_fcn, doc) |
1957
|
67 |
|
68 // This one can be used when `name' cannot be used directly (if it is |
|
69 // already defined as a macro). In that case, name is already a |
|
70 // quoted string, and the name of the structure has to be passed too. |
|
71 |
|
72 #define DEFCONSTX(name, sname, defn, inst_as_fcn, sv_fcn, doc) \ |
2890
|
73 DEFVAR_INT (name, sname, defn, inst_as_fcn, false, sv_fcn, doc); \ |
|
74 DEFVAR_INT ("__" ## name ## "__", X ## sname, defn, false, true, sv_fcn, doc) |
1957
|
75 |
|
76 // How builtin variables are actually installed. |
|
77 |
|
78 #define DEFVAR_INT(name, sname, defn, inst_as_fcn, protect, sv_fcn, doc) \ |
525
|
79 do \ |
|
80 { \ |
2374
|
81 builtin_variable sname (name, octave_value (defn), inst_as_fcn, \ |
2432
|
82 protect, (sv_fcn != 0), sv_fcn, doc); \ |
1755
|
83 install_builtin_variable (sname); \ |
525
|
84 } \ |
|
85 while (0) |
|
86 |
550
|
87 // Define a builtin function. |
|
88 // |
1957
|
89 // name is the name of the function, unqouted. |
550
|
90 // |
2086
|
91 // args_name is the name of the octave_value_list variable used to pass |
1957
|
92 // the argument list to this function. |
550
|
93 // |
1957
|
94 // nargout_name is the name of the int variable used to pass the |
|
95 // number of output arguments this function is expected to produce. |
550
|
96 // |
|
97 // doc is the simple help text for the function. |
|
98 |
1957
|
99 #define DEFUN(name, args_name, nargout_name, doc) \ |
2890
|
100 DEFUN_INTERNAL (name, args_name, nargout_name, false, doc) |
525
|
101 |
550
|
102 // Define a builtin text-style function. |
|
103 // |
|
104 // This is like DEFUN, except that it defines a function that can be |
|
105 // called from the Octave language without using parenthesis to |
|
106 // surround the arguments). |
|
107 |
1957
|
108 #define DEFUN_TEXT(name, args_name, nargout_name, doc) \ |
2890
|
109 DEFUN_INTERNAL (name, args_name, nargout_name, true, doc) |
525
|
110 |
550
|
111 // Define a mapper function. |
|
112 // |
1957
|
113 // name is the name of the function, unquoqted. |
550
|
114 // |
2089
|
115 // ch_map is a pointer to a function that should be called for |
|
116 // integer arguments that are expected to creat integer results. |
|
117 // (It's a kluge to handle character mappers like isalpha.) |
550
|
118 // |
|
119 // d_d_map is a pointer to a function that should be called for real |
|
120 // arguments that are expected to create real results. |
|
121 // |
|
122 // d_c_map is a pointer to a function that should be called for real |
|
123 // arguments that are expected to create complex results. |
|
124 // |
|
125 // c_c_map is a pointer to a function that should be called for |
|
126 // complex arguments that are expected to create complex results. |
|
127 // |
2089
|
128 // lo is the lower bound of the range for which real arguments can |
|
129 // become complex. (e.g., lo == -Inf for sqrt). |
|
130 // |
|
131 // hi is the upper bound of the range for which real arguments can |
|
132 // become complex. (e.g., hi == 0 for sqrt). |
|
133 // |
|
134 // can_ret_cmplx_for_real is a flag that says whether this function |
|
135 // can create a complex number given a real-valued argument |
|
136 // (e.g., sqrt (-1)). |
|
137 // |
550
|
138 // doc is the simple help text for the function. |
|
139 |
2089
|
140 #define DEFUN_MAPPER(name, ch_map, d_d_map, d_c_map, c_c_map, \ |
|
141 lo, hi, can_ret_cmplx_for_real, doc) \ |
2890
|
142 install_builtin_mapper \ |
|
143 (new octave_mapper (ch_map, d_d_map, d_c_map, c_c_map, lo, hi, \ |
|
144 can_ret_cmplx_for_real, #name)) |
525
|
145 |
550
|
146 // Make alias another name for the existing function name. This macro |
|
147 // must be used in the same file where name is defined, after the |
|
148 // definition for name. |
525
|
149 |
2374
|
150 #define DEFALIAS(name, alias) \ |
|
151 DEFALIAS_INTERNAL (name, alias) |
525
|
152 |
|
153 #endif |
|
154 |
|
155 /* |
|
156 ;;; Local Variables: *** |
|
157 ;;; mode: C++ *** |
|
158 ;;; End: *** |
|
159 */ |