mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
add py_getvmctx
This commit is contained in:
parent
108d2fe969
commit
5ad606859f
@ -32,6 +32,7 @@ typedef struct VM {
|
|||||||
bool is_curr_exc_handled; // handled by try-except block but not cleared yet
|
bool is_curr_exc_handled; // handled by try-except block but not cleared yet
|
||||||
|
|
||||||
py_TValue reg[8]; // users' registers
|
py_TValue reg[8]; // users' registers
|
||||||
|
void* ctx; // user-defined context
|
||||||
|
|
||||||
py_StackRef __curr_class;
|
py_StackRef __curr_class;
|
||||||
py_StackRef __curr_function;
|
py_StackRef __curr_function;
|
||||||
|
@ -92,6 +92,10 @@ PK_EXPORT int py_currentvm();
|
|||||||
PK_EXPORT void py_switchvm(int index);
|
PK_EXPORT void py_switchvm(int index);
|
||||||
/// Reset the current VM.
|
/// Reset the current VM.
|
||||||
PK_EXPORT void py_resetvm();
|
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.
|
/// Set `sys.argv`. Used for storing command-line arguments.
|
||||||
PK_EXPORT void py_sys_setargv(int argc, char** argv);
|
PK_EXPORT void py_sys_setargv(int argc, char** argv);
|
||||||
/// Setup the callbacks for the current VM.
|
/// Setup the callbacks for the current VM.
|
||||||
|
@ -71,6 +71,7 @@ void VM__ctor(VM* self) {
|
|||||||
self->curr_exception = *py_NIL;
|
self->curr_exception = *py_NIL;
|
||||||
self->is_curr_exc_handled = false;
|
self->is_curr_exc_handled = false;
|
||||||
|
|
||||||
|
self->ctx = NULL;
|
||||||
self->__curr_class = NULL;
|
self->__curr_class = NULL;
|
||||||
self->__curr_function = NULL;
|
self->__curr_function = NULL;
|
||||||
|
|
||||||
|
@ -75,6 +75,14 @@ int py_currentvm() {
|
|||||||
return -1;
|
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) {
|
void py_sys_setargv(int argc, char** argv) {
|
||||||
py_GlobalRef sys = py_getmodule("sys");
|
py_GlobalRef sys = py_getmodule("sys");
|
||||||
py_Ref argv_list = py_getdict(sys, py_name("argv"));
|
py_Ref argv_list = py_getdict(sys, py_name("argv"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user