blueloveTH 1 год назад
Родитель
Сommit
26c553eb9a
2 измененных файлов с 9 добавлено и 0 удалено
  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.
 /// 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 *************/
 

+ 6 - 0
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 */