GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
defun.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <string>
31
32#include "defun.h"
33#include "dynamic-ld.h"
34#include "error.h"
35#include "help.h"
36#include "ov.h"
37#include "ov-builtin.h"
38#include "ov-dld-fcn.h"
39#include "ov-fcn.h"
40#include "ov-mex-fcn.h"
41#include "ov-usr-fcn.h"
42#include "ovl.h"
43#include "oct-lvalue.h"
44#include "pager.h"
45#include "interpreter-private.h"
46#include "interpreter.h"
47#include "symtab.h"
48#include "variables.h"
49
51
52// Print the usage part of the doc string of FCN (user-defined or DEFUN).
53void
55{
57
58 const octave_function *cur = tw.current_function ();
59
60 if (cur)
61 print_usage (cur->name ());
62 else
63 error ("print_usage: invalid function");
64}
65
66void
67print_usage (const std::string& name)
68{
70
71 interp.feval ("print_usage", octave_value (name), 0);
72}
73
74void
75check_version (const std::string& version, const std::string& fcn)
76{
77 if (version != OCTAVE_API_VERSION)
78 {
79 error ("API version %s found in .oct file function '%s'\n"
80 " does not match the running Octave (API version %s)\n"
81 " this can lead to incorrect results or other failures\n"
82 " you can fix this problem by recompiling this .oct file",
83 version.c_str (), fcn.c_str (), OCTAVE_API_VERSION);
84 }
85}
86
87// Install variables and functions in the symbol tables.
88
89void
91 const dynamic_library& shl, const std::string& doc,
92 bool relative)
93{
94 octave_dld_function *fcn = new octave_dld_function (f, shl, name, doc);
95
96 if (relative)
97 fcn->mark_relative ();
98
99 octave_value fval (fcn);
100
102
103 symtab.install_built_in_function (name, fval);
104}
105
106void
108 const dynamic_library& shl, const std::string& doc,
109 bool relative)
110{
111 octave_dld_function *fcn = new octave_dld_function (m, shl, name, doc);
112
113 if (relative)
114 fcn->mark_relative ();
115
116 octave_value fval (fcn);
117
119
120 symtab.install_built_in_function (name, fval);
121}
122
123void
124install_mex_function (void *fptr, bool fmex, const std::string& name,
125 const dynamic_library& shl, bool relative)
126{
127 octave_mex_function *fcn = new octave_mex_function (fptr, fmex, shl, name);
128
129 if (relative)
130 fcn->mark_relative ();
131
132 octave_value fval (fcn);
133
135
136 symtab.install_built_in_function (name, fval);
137}
138
141{
142 dynamic_library retval;
143
145
146 octave_function *curr_fcn = tw.current_function ();
147
148 if (curr_fcn)
149 {
150 if (curr_fcn->is_dld_function ())
151 {
153 = dynamic_cast<octave_dld_function *> (curr_fcn);
154 retval = dld->get_shlib ();
155 }
156 else if (curr_fcn->is_mex_function ())
157 {
159 = dynamic_cast<octave_mex_function *> (curr_fcn);
160 retval = mex->get_shlib ();
161 }
162 }
163
164 return retval;
165}
166
167OCTAVE_END_NAMESPACE(octave)
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
Definition mxarray.h:688
virtual bool is_mex_function() const
Definition ov-base.h:555
virtual bool is_dld_function() const
Definition ov-base.h:553
octave_value_list(* fcn)(const octave_value_list &, int)
Definition ov-builtin.h:61
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition ov-builtin.h:58
octave::dynamic_library get_shlib() const
Definition ov-dld-fcn.h:91
std::string name() const
Definition ov-fcn.h:208
void mark_relative()
Definition ov-fcn.h:204
void install_built_in_function(const std::string &name, const octave_value &fcn)
Definition symtab.cc:411
octave_function * current_function(bool skip_first=false) const
Definition pt-eval.cc:2613
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void install_dld_function(octave_dld_function::fcn f, const std::string &name, const dynamic_library &shl, const std::string &doc, bool relative)
Definition defun.cc:90
void install_mex_function(void *fptr, bool fmex, const std::string &name, const dynamic_library &shl, bool relative)
Definition defun.cc:124
void check_version(const std::string &version, const std::string &fcn)
Definition defun.cc:75
void print_usage()
Definition defun.cc:54
dynamic_library get_current_shlib()
Definition defun.cc:140
void error(const char *fmt,...)
Definition error.cc:1003
tree_evaluator & __get_evaluator__()
symbol_table & __get_symbol_table__()
interpreter & __get_interpreter__()
F77_RET_T const F77_DBLE const F77_DBLE * f
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)