blueloveTH 1 year ago
parent
commit
26c553eb9a
2 changed files with 9 additions and 0 deletions
  1. 3 0
      include/pocketpy/pocketpy.h
  2. 6 0
      src/public/stack_ops.c

+ 3 - 0
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.
 /// Get the current `function` object from the stack.
 /// Return `NULL` if not available.
 /// Return `NULL` if not available.
 py_StackRef py_inspect_currentfunction();
 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 *************/
 /************* Bindings *************/
 
 

+ 6 - 0
src/public/stack_ops.c

@@ -64,6 +64,12 @@ py_StackRef py_inspect_currentfunction(){
     return frame->p0;
     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; }
 void py_assign(py_Ref dst, py_Ref src) { *dst = *src; }
 
 
 /* Stack References */
 /* Stack References */