From fbee34c81ab54a43945aebb83aba788baa54333c Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Sat, 28 Jan 2017 22:13:20 +0100 Subject: [PATCH] Implement simple importing of Python modules --- lib/Inline/Python.pm6 | 7 +++++++ pyhelper.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/lib/Inline/Python.pm6 b/lib/Inline/Python.pm6 index 83e0d68..f93fb6f 100644 --- a/lib/Inline/Python.pm6 +++ b/lib/Inline/Python.pm6 @@ -54,6 +54,9 @@ sub py_init_perl6object() sub py_eval(Str, int32) returns Pointer { ... } native(&py_eval); +sub py_import(Str) + { ... } + native(&py_import); sub py_instance_check(Pointer) returns int32 { ... } native(&py_instance_check); @@ -394,6 +397,10 @@ multi method invoke(PythonParent $p6obj, Pointer $obj, Str $method, *@args) { return retval; } +method import(Str $module) { + py_import($module); +} + method py_getattr(Pointer $obj, Str $name) { return py_getattr($obj, $name); } diff --git a/pyhelper.c b/pyhelper.c index 29b043a..59bffd6 100644 --- a/pyhelper.c +++ b/pyhelper.c @@ -54,6 +54,10 @@ PyObject *py_eval(const char* p, int type) { return py_result; } +void py_import(char *module) { + PyImport_ImportModule(module); +} + int py_instance_check(PyObject *obj) { return ((obj->ob_type->tp_flags & Py_TPFLAGS_HEAPTYPE) || PyInstance_Check(obj)); }