PLearn 0.1
|
#include <plearn/python/PythonCodeSnippet.h>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <iostream>
Go to the source code of this file.
Classes | |
struct | X |
Typedefs | |
typedef boost::function< void()> | XFunction |
Functions | |
PyObject * | python_trampoline (PyObject *self, PyObject *args) |
int | main () |
Variables | |
string | python_code = " print >>sys.stderr, 'The C function returned the charming value',y\n" |
typedef boost::function<void ()> XFunction |
Definition at line 32 of file test_trampoline.cc.
int main | ( | ) |
Definition at line 45 of file test_trampoline.cc.
References PLearn::X::f(), python_code, python_trampoline(), and x.
{ PP<PythonCodeSnippet> python = new PythonCodeSnippet(python_code); python->build(); // Build my interesting instance of X X x(42); // Bind it to a function object XFunction xfunc = boost::bind(&X::f, x); // Create a Python Function Object PyMethodDef py_method; py_method.ml_name = NULL; py_method.ml_meth = python_trampoline; py_method.ml_flags = METH_VARARGS; py_method.ml_doc = NULL; PyObject* py_funcobj = PyCFunction_NewEx(&py_method, reinterpret_cast<PyObject*>(&xfunc), NULL /* module */); // Inject into the running python snippet python->setGlobalObject("injected_c_function", py_funcobj); // And now call our darling python->invoke("trampoline_call", 64); Py_XDECREF(py_funcobj); return 0; }
PyObject* python_trampoline | ( | PyObject * | self, |
PyObject * | args | ||
) |
Definition at line 34 of file test_trampoline.cc.
Referenced by main().
{ XFunction *xfunc = reinterpret_cast<XFunction*>(self); // Should parse args here (*xfunc)(); return PyInt_FromLong(64); }
string python_code = " print >>sys.stderr, 'The C function returned the charming value',y\n" |
Definition at line 11 of file test_trampoline.cc.
Referenced by main(), PLearn::InterfunctionXchgTest::perform(), PLearn::BasicIdentityCallsTest::perform(), and PLearn::InjectionTest::perform().