Inline-Python

 view release on metacpan or  search on metacpan

Python.xs  view on Meta::CPAN

py_study_package(PYPKG="__main__")
    char*   PYPKG
  PREINIT:
    PyObject *mod;
    PyObject *dict;
    PyObject *keys;
    int len;
    int i;
    AV* const functions = newAV();
    HV* const 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; i<len; i++) {
        PyObject * const key = PySequence_GetItem(keys,i);
        PyObject * const val = PyObject_GetItem(dict,key);
        if (PyCallable_Check(val)) {

Python.xs  view on Meta::CPAN

py_eval(str, type=1)
    char *str
    int type
  PREINIT:
    PyObject *main_module;
    PyObject *globals;
    PyObject *locals;
    PyObject *py_result;
    int             context;
    SV*             ret = NULL;
  PPCODE:
    Printf(("py_eval: code: %s\n", str));
    /* doc:  if the module wasn't already loaded, you will get an empty
     * module object. */
    main_module = PyImport_AddModule("__main__");
    if(main_module == NULL) {
        croak("Error -- Import_AddModule of __main__ failed");
    }
    Printf(("py_eval: main_module=%p\n", main_module));
    globals = PyModule_GetDict(main_module);
    Printf(("py_eval: globals=%p\n", globals));

Python.xs  view on Meta::CPAN


    PyObject * const mod       = PyImport_AddModule(PYPKG);
    PyObject * const dict      = PyModule_GetDict(mod);
    PyObject * const func      = PyMapping_GetItemString(dict,FNAME);
    PyObject *o         = NULL;
    PyObject *py_retval = NULL;
    PyObject *tuple     = NULL;

    SV* ret = NULL;

  PPCODE:

    Printf(("py_call_function\n"));
    Printf(("package: %s\n", PYPKG));
    Printf(("function: %s\n", FNAME));

    if (!PyCallable_Check(func)) {
        croak("'%s' is not a callable object", FNAME);
        XSRETURN_EMPTY;
    }

Python.xs  view on Meta::CPAN

  PREINIT:
    int i;

    PyObject * const func = (PyObject *) SvIV(FUNC);
    PyObject *o         = NULL;
    PyObject *py_retval = NULL;
    PyObject *tuple     = NULL;

    SV* ret = NULL;

  PPCODE:

    Printf(("py_call_function_ref\n"));

    if (!PyCallable_Check(func)) {
        croak("'%p' is not a callable object", func);
        XSRETURN_EMPTY;
    }

    Printf(("function '%p' is callable!\n", func));

Python.xs  view on Meta::CPAN

    PyObject *inst;

    /* Other variables */
    PyObject *method;    /* the method object */
    PyObject *tuple;     /* the parameters */
    PyObject *py_retval; /* the return value */
    int i;
    int is_string;
    SV *ret;

  PPCODE:

    Printf(("eval_python_method\n"));

    if (SvROK(_inst) && SvTYPE(SvRV(_inst))==SVt_PVMG) {
        inst = (PyObject*)SvIV(SvRV(_inst));
    }
    else {
        croak("Object did not have Inline::Python::Object magic");
        XSRETURN_EMPTY;
    }

Python.xs  view on Meta::CPAN

void
py_has_attr(_inst, key)
    SV*   _inst;
    SV*   key;
  PREINIT:

    PyObject *inst;
    char     *key_name;
    STRLEN   len;

  PPCODE:

    Printf(("get_object_data py_has_attr\n"));

    if (SvROK(_inst) && SvTYPE(SvRV(_inst))==SVt_PVMG) {
        inst = (PyObject*)SvIV(SvRV(_inst));
    }
    else {
        croak("Object did not have Inline::Python::Object magic");
        XSRETURN_EMPTY;
    }

Python.xs  view on Meta::CPAN

    SV*   _inst;
    SV*   key;
  PREINIT:

    PyObject *inst;
    char     *key_name;
    STRLEN   len;
    PyObject *py_retval; /* the return value */
    SV       *ret;

  PPCODE:

    Printf(("get_object_data py_get_attr\n"));

    if (SvROK(_inst) && SvTYPE(SvRV(_inst))==SVt_PVMG) {
        inst = (PyObject*)SvIV(SvRV(_inst));
    }
    else {
        croak("Object did not have Inline::Python::Object magic");
        XSRETURN_EMPTY;
    }

Python.xs  view on Meta::CPAN

    SV* _inst;
    SV* key;
    SV* value;

  PREINIT:

    PyObject *inst, *py_value;
    char     *key_name;
    STRLEN   len;

  PPCODE:

    Printf(("set_attr\n"));

    if (SvROK(_inst) && SvTYPE(SvRV(_inst))==SVt_PVMG) {
        inst = (PyObject*)SvIV(SvRV(_inst));
    }
    else {
        croak("Object did not have Inline::Python::Object magic");
        XSRETURN_EMPTY;
    }

Python.xs  view on Meta::CPAN

    PyObject_SetAttrString(inst, key_name, py_value);
    Py_DECREF(py_value);

    XSRETURN_EMPTY;

#undef  NUM_FIXED_ARGS
#define NUM_FIXED_ARGS 0

void
py_finalize()
  PPCODE:

    Py_Finalize();

    XSRETURN_EMPTY;

#undef  NUM_FIXED_ARGS
#define NUM_FIXED_ARGS 1

int
py_is_tuple(_inst)



( run in 0.303 second using v1.01-cache-2.11-cpan-5511b514fd6 )