Mercurial > pytave
changeset 116:3a35bb85ce52
py: Experiment with handle to target function
* py.cc (Fpy): Experiment with getting a handle to the function to be called
rather than calling eval on a Python expression.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Sun, 20 Sep 2015 15:17:46 +0200 |
parents | 00d19f71c9ca |
children | 386772f4e12d |
files | py.cc |
diffstat | 1 files changed, 4 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/py.cc Sun Sep 20 15:12:47 2015 +0200 +++ b/py.cc Sun Sep 20 15:17:46 2015 +0200 @@ -65,6 +65,7 @@ if (idx != std::string::npos) { module = func.substr (0, idx); + func = func.substr (idx + 1); } Py_Initialize (); @@ -74,13 +75,9 @@ object main_module = import ("__main__"); object main_namespace = main_module.attr ("__dict__"); - if (! module.empty ()) - { - std::string cmd = "import " + module; - exec (cmd.c_str (), main_namespace, main_namespace); - } - - object res = eval (func.c_str (), main_namespace, main_namespace); + object mod = (module.empty ()) ? main_module : import (module.c_str ()); + object callable = mod.attr (func.c_str ()); + object res = callable (); if (! res.is_none ()) {