add py_getvmctx

This commit is contained in:
blueloveTH 2024-08-30 16:01:22 +08:00
parent 108d2fe969
commit 5ad606859f
4 changed files with 14 additions and 0 deletions

View File

@ -32,6 +32,7 @@ typedef struct VM {
bool is_curr_exc_handled; // handled by try-except block but not cleared yet
py_TValue reg[8]; // users' registers
void* ctx; // user-defined context
py_StackRef __curr_class;
py_StackRef __curr_function;

View File

@ -92,6 +92,10 @@ PK_EXPORT int py_currentvm();
PK_EXPORT void py_switchvm(int index);
/// Reset the current VM.
PK_EXPORT void py_resetvm();
/// Get the current VM context. This is used for user-defined data.
PK_EXPORT void* py_getvmctx();
/// Set the current VM context. This is used for user-defined data.
PK_EXPORT void py_setvmctx(void* ctx);
/// Set `sys.argv`. Used for storing command-line arguments.
PK_EXPORT void py_sys_setargv(int argc, char** argv);
/// Setup the callbacks for the current VM.

View File

@ -71,6 +71,7 @@ void VM__ctor(VM* self) {
self->curr_exception = *py_NIL;
self->is_curr_exc_handled = false;
self->ctx = NULL;
self->__curr_class = NULL;
self->__curr_function = NULL;

View File

@ -75,6 +75,14 @@ int py_currentvm() {
return -1;
}
void* py_getvmctx(){
return pk_current_vm->ctx;
}
void py_setvmctx(void* ctx){
pk_current_vm->ctx = ctx;
}
void py_sys_setargv(int argc, char** argv) {
py_GlobalRef sys = py_getmodule("sys");
py_Ref argv_list = py_getdict(sys, py_name("argv"));