Skip to content

Commit

Permalink
Implement simple importing of Python modules
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Jan 28, 2017
1 parent 5577232 commit fbee34c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Inline/Python.pm6
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions pyhelper.c
Expand Up @@ -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));
}
Expand Down

0 comments on commit fbee34c

Please sign in to comment.