annotate oct-py-eval.cc @ 363:445df7f96fbc

Use the __main__ namespace as the default global namespace for evaluating code * oct-py-eval.cc (pytave::py_run_string_safe): Use the dictionary of __main__ as the default global namespace.
author Mike Miller <mtmiller@octave.org>
date Thu, 25 Aug 2016 11:39:45 -0700
parents 4c2b748eaea0
children c4b78e449c62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 (HAVE_CONFIG_H)
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
24 # include <config.h>
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
25 #endif
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
26
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 #include <boost/python.hpp>
351
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
29 #include <octave/ov.h>
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
30 #include <octave/ovl.h>
335
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
31
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
32 #include "oct-py-eval.h"
351
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
33 #include "oct-py-util.h"
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
34 #include "octave_to_python.h"
335
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
35
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
36 namespace pytave
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
37 {
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
38
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
39 PyObject *
351
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
40 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
41 {
359
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
42 PyObject *func_obj = py_find_function (func);
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
43 PyObject *retval = py_call_function (func_obj, args);
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
44 Py_DECREF (func_obj);
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
45 return retval;
351
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
46 }
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 PyObject *
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
49 py_call_function (const std::string& func, PyObject *args, PyObject *kwargs)
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
50 {
359
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
51 PyObject *func_obj = py_find_function (func);
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
52 PyObject *retval = py_call_function (func_obj, args, kwargs);
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
53 Py_DECREF (func_obj);
4c2b748eaea0 Use py_find_function where specifically searching for a function by name
Mike Miller <mtmiller@octave.org>
parents: 351
diff changeset
54 return retval;
351
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
55 }
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
56
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 (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
59 {
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
60 PyObject *kwargs = 0;
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
61 PyObject *args_list = PyList_New (0);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
62 if (! args_list)
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
63 octave_throw_bad_alloc ();
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 for (int i = 0; i < args.length (); ++i)
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
66 {
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
67 boost::python::object arg;
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
68 pytave::octvalue_to_pyobj (arg, args(i));
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
69 PyObject *obj = arg.ptr ();
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 if (pytave::is_py_kwargs_argument (obj))
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
72 kwargs = pytave::update_py_dict (kwargs, obj);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
73 else
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
74 {
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
75 Py_INCREF (obj);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
76 PyList_Append (args_list, obj);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
77 }
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
78 }
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
79
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
80 PyObject *args_tuple = PyList_AsTuple (args_list);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
81 Py_DECREF (args_list);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
82
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
83 PyObject *retval = py_call_function (callable, args_tuple, kwargs);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
84 Py_DECREF (args_tuple);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
85 Py_XDECREF (kwargs);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
86
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
87 return retval;
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
88 }
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
89
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
90 PyObject *
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
91 py_call_function (PyObject *callable, PyObject *args, PyObject *kwargs)
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
92 {
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
93 PyObject *retval = PyEval_CallObjectWithKeywords (callable, args, kwargs);
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
94 if (! retval)
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
95 throw boost::python::error_already_set ();
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
96
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
97 return retval;
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
98 }
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
99
040aff46e4db Refactor calling a Python function into a set of wrapper functions
Mike Miller <mtmiller@octave.org>
parents: 335
diff changeset
100 PyObject *
335
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
101 py_run_string_safe (const std::string& expr, int start, PyObject *globals,
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
102 PyObject *locals)
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
103 {
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
104 bool alloc = false;
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
105
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
106 if (! globals || (globals == Py_None))
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
107 {
363
445df7f96fbc Use the __main__ namespace as the default global namespace for evaluating code
Mike Miller <mtmiller@octave.org>
parents: 359
diff changeset
108 PyObject *main = py_import_module ("__main__");
445df7f96fbc Use the __main__ namespace as the default global namespace for evaluating code
Mike Miller <mtmiller@octave.org>
parents: 359
diff changeset
109 globals = PyModule_GetDict (main);
445df7f96fbc Use the __main__ namespace as the default global namespace for evaluating code
Mike Miller <mtmiller@octave.org>
parents: 359
diff changeset
110 Py_DECREF (main);
335
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
111 if (! globals)
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
112 {
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
113 globals = PyDict_New ();
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
114 alloc = true;
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
115 }
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
116 }
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
117
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
118 if (! locals || (locals == Py_None))
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
119 locals = globals;
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
120
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
121 // Evaluate all expressions under "from __future__ import print_function"
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
122 PyCompilerFlags flags { CO_FUTURE_PRINT_FUNCTION };
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
123
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
124 PyObject *retval = PyRun_StringFlags (expr.c_str (), start, globals, locals,
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
125 &flags);
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
126
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
127 if (alloc)
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
128 Py_DECREF (globals);
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
129
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
130 if (! retval)
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
131 throw boost::python::error_already_set ();
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
132
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
133 return retval;
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
134 }
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
135
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
136 PyObject *
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
137 py_eval_string (const std::string& expr, PyObject *globals, PyObject *locals)
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
138 {
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
139 return py_run_string_safe (expr, Py_eval_input, globals, locals);
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
140 }
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
141
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
142 PyObject *
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
143 py_exec_string (const std::string& expr, PyObject *globals, PyObject *locals)
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
144 {
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
145 return py_run_string_safe (expr, Py_file_input, globals, locals);
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
146 }
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
147
9b862844e6b7 Enable Python print function in evaluated expressions (fixes issue #48)
Mike Miller <mtmiller@octave.org>
parents:
diff changeset
148 }