Mercurial > pytave
annotate oct-py-eval.h @ 351:040aff46e4db
Refactor calling a Python function into a set of wrapper functions
* oct-py-eval.cc, oct-py-eval.h (pytave::py_call_function): New function
overloads to call a Python function in various ways.
* pycall.cc (Fpycall): Use pytave::py_call_function.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Wed, 17 Aug 2016 14:02:33 -0700 |
parents | 9b862844e6b7 |
children | c4b78e449c62 |
rev | line source |
---|---|
335
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
1 /* |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
2 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 2016 Mike Miller |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
4 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
5 This file is part of Pytave. |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
6 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
7 Pytave is free software; you can redistribute it and/or modify it |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
11 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
12 Pytave is distributed in the hope that it will be useful, but WITHOUT |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
15 for more details. |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
16 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
18 along with Pytave; see the file COPYING. If not, see |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
20 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
21 */ |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
22 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
23 #if ! defined (pytave_oct_py_eval_h) |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
24 #define pytave_oct_py_eval_h 1 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
25 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
26 #include <Python.h> |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
27 #include <string> |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
28 |
351
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
29 class octave_value_list; |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
30 |
335
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
31 namespace pytave |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
32 { |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
33 |
351
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
34 //! Call a Python function by name with the given argument list. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
35 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
36 //! The @a func string may be the name of a builtin function or of a function |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
37 //! in a loadable module in the form @c module.function. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
38 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
39 //! If @a args contains one or more values created by the @c pyargs function, |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
40 //! they are automatically interpreted as keyword arguments. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
41 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
42 //! @param func name of a Python function |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
43 //! @param args Octave argument list to be converted and passed to @a func |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
44 //! @return return value of @a func |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
45 PyObject * |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
46 py_call_function (const std::string& func, const octave_value_list& args); |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
47 |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
48 //! Call a Python function by name with arguments and keyword arguments. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
49 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
50 //! The @a func string may be the name of a builtin function or of a function |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
51 //! in a loadable module in the form @c module.function. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
52 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
53 //! @param func name of a Python function |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
54 //! @param args tuple of positional arguments |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
55 //! @param kwargs dictionary of keyword arguments |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
56 //! @return return value of @a func |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
57 PyObject * |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
58 py_call_function (const std::string& func, PyObject *args, PyObject *kwargs = 0); |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
59 |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
60 //! Call a Python function with the given argument list. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
61 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
62 //! If @a args contains one or more values created by the @c pyargs function, |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
63 //! they are automatically interpreted as keyword arguments. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
64 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
65 //! @param callable Python function or other callable object |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
66 //! @param args Octave argument list to be converted and passed to @a func |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
67 //! @return return value of @a func |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
68 PyObject * |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
69 py_call_function (PyObject *callable, const octave_value_list& args); |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
70 |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
71 //! Call a Python function with arguments and keyword arguments. |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
72 //! |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
73 //! @param callable Python function or other callable object |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
74 //! @param args tuple of positional arguments |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
75 //! @param kwargs dictionary of keyword arguments |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
76 //! @return return value of @a func |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
77 PyObject * |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
78 py_call_function (PyObject *callable, PyObject *args, PyObject *kwargs = 0); |
040aff46e4db
Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents:
335
diff
changeset
|
79 |
335
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
80 PyObject * |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
81 py_eval_string (const std::string& expr, PyObject *globals = 0, PyObject *locals = 0); |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
82 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
83 PyObject * |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
84 py_exec_string (const std::string& expr, PyObject *globals = 0, PyObject *locals = 0); |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
85 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
86 } |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
87 |
9b862844e6b7
Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
88 #endif |