mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
1d9c565b64
commit
e982a4e60b
@ -615,3 +615,10 @@ bool pkpy_eval(pkpy_vm* vm_handle, const char* code) {
|
|||||||
ERRHANDLER_CLOSE
|
ERRHANDLER_CLOSE
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* pkpy_get_id(pkpy_vm* vm_handle, int index) {
|
||||||
|
CVM* vm = (CVM*) vm_handle;
|
||||||
|
index = lua_to_cstack_index(index, vm->c_data->size());
|
||||||
|
PyObject* o = vm->c_data->begin()[index];
|
||||||
|
return (void*) o;
|
||||||
|
}
|
@ -114,6 +114,8 @@ PK_EXPORT bool pkpy_getattr(pkpy_vm*, const char* name);
|
|||||||
PK_EXPORT bool pkpy_setattr(pkpy_vm*, const char* name);
|
PK_EXPORT bool pkpy_setattr(pkpy_vm*, const char* name);
|
||||||
PK_EXPORT bool pkpy_eval(pkpy_vm*, const char* source);
|
PK_EXPORT bool pkpy_eval(pkpy_vm*, const char* source);
|
||||||
|
|
||||||
|
PK_EXPORT void* pkpy_get_id(pkpy_vm*, int index);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -75,6 +75,11 @@ struct VoidP{
|
|||||||
return _CAST(VoidP&, lhs).ptr <= CAST(VoidP&, rhs).ptr;
|
return _CAST(VoidP&, lhs).ptr <= CAST(VoidP&, rhs).ptr;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vm->bind__hash__(OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
|
||||||
|
VoidP& self = _CAST(VoidP&, obj);
|
||||||
|
return reinterpret_cast<i64>(self.ptr);
|
||||||
|
});
|
||||||
|
|
||||||
vm->bind_method<1>(type, "set_base_offset", [](VM* vm, ArgsView args){
|
vm->bind_method<1>(type, "set_base_offset", [](VM* vm, ArgsView args){
|
||||||
VoidP& self = _CAST(VoidP&, args[0]);
|
VoidP& self = _CAST(VoidP&, args[0]);
|
||||||
if(is_non_tagged_type(args[1], vm->tp_str)){
|
if(is_non_tagged_type(args[1], vm->tp_str)){
|
||||||
|
@ -100,8 +100,8 @@ inline void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind_builtin_func<1>("id", [](VM* vm, ArgsView args) {
|
_vm->bind_builtin_func<1>("id", [](VM* vm, ArgsView args) {
|
||||||
PyObject* obj = args[0];
|
PyObject* obj = args[0];
|
||||||
if(is_tagged(obj)) return VAR((i64)0);
|
if(is_tagged(obj)) return vm->None;
|
||||||
return VAR(BITS(obj));
|
return VAR_T(VoidP, obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind_builtin_func<2>("divmod", [](VM* vm, ArgsView args) {
|
_vm->bind_builtin_func<2>("divmod", [](VM* vm, ArgsView args) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user