/* -*- C -*- */ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "Python.h" #include "py2pl.h" #include "util.h" #ifdef EXPOSE_PERL #include "perlmodule.h" #endif /* To save a little time, I check the calling context and don't convert * the arguments if I'm in void context, flatten lists in list context, * and return only one element in scalar context. * * If this turns out to be a bad idea, it's easy enough to turn off. */ #define CHECK_CONTEXT #ifdef CREATE_PYTHON void do_pyinit() { #ifdef EXPOSE_PERL PyObject *main_dict; PyObject *perl_obj; PyObject *dummy1 = PyString_FromString(""), *dummy2 = PyString_FromString("main"); #endif /* sometimes Python needs to know about argc and argv to be happy */ int _python_argc = 1; char *_python_argv[] = { "python", }; Py_SetProgramName("python"); Py_Initialize(); PySys_SetArgv(_python_argc, _python_argv); /* Tk needs this */ #ifdef EXPOSE_PERL /* create the perl module and add functions */ initperl(); /* now -- create the main 'perl' object and add it to the dictionary. */ perl_obj = newPerlPkg_object(dummy1,dummy2); main_dict = PyModule_GetDict(PyImport_AddModule("__main__")); PyDict_SetItemString(main_dict, "perl", perl_obj); Py_DECREF(dummy1); Py_DECREF(dummy2); #endif } #endif MODULE = Inline::Python PACKAGE = Inline::Python BOOT: #ifdef CREATE_PYTHON do_pyinit(); #endif PROTOTYPES: DISABLE void py_study_package(PYPKG="__main__") char* PYPKG PREINIT: PyObject *mod; PyObject *dict; PyObject *keys; int len; int i; AV* functions = newAV(); HV* classes = newHV(); PPCODE: mod = PyImport_AddModule(PYPKG); dict = PyModule_GetDict(mod); keys = PyMapping_Keys(dict); len = PyObject_Length(dict); Printf(("py_study_package: dict length: %i\n", len)); for (i=0; iob_type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { croak("Attempted to call method '%s' on a non-instance", mname); XSRETURN_EMPTY; } Printf(("inst is indeed a Python Instance\n")); if (!PyObject_HasAttrString(inst, mname)) { croak("Python object has no method named %s", mname); XSRETURN_EMPTY; } Printf(("inst has an attribute named '%s'\n", mname)); method = PyObject_GetAttrString(inst,mname); if (!PyCallable_Check(method)) { croak("Attempted to call non-method '%s'", mname); XSRETURN_EMPTY; } tuple = PyTuple_New(items-NUM_FIXED_ARGS); for (i=NUM_FIXED_ARGS; i