diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index d2479a8e..32265415 100644 --- a/include/pocketpy/pocketpy.h +++ b/include/pocketpy/pocketpy.h @@ -281,6 +281,9 @@ void py_setslot(py_Ref self, int i, py_Ref val); /// Get the current `function` object from the stack. /// Return `NULL` if not available. py_StackRef py_inspect_currentfunction(); +/// Get the current `module` object where the code is executed. +/// Return `NULL` if not available. +py_GlobalRef py_inspect_currentmodule(); /************* Bindings *************/ diff --git a/src/public/stack_ops.c b/src/public/stack_ops.c index 4434a20a..ea257647 100644 --- a/src/public/stack_ops.c +++ b/src/public/stack_ops.c @@ -64,6 +64,12 @@ py_StackRef py_inspect_currentfunction(){ return frame->p0; } +py_GlobalRef py_inspect_currentmodule(){ + Frame* frame = pk_current_vm->top_frame; + if(!frame) return NULL; + return frame->module; +} + void py_assign(py_Ref dst, py_Ref src) { *dst = *src; } /* Stack References */