mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
ec201dbc45
commit
c0dc98042e
@ -5,11 +5,11 @@ using namespace pkpy;
|
|||||||
|
|
||||||
typedef int (*LuaStyleFuncC)(VM*);
|
typedef int (*LuaStyleFuncC)(VM*);
|
||||||
|
|
||||||
#define C_API_ASSERT(x) if(!(x)) { pkpy_error(vm_handle, "AssertionError", #x); return false; }
|
|
||||||
|
|
||||||
#define PK_ASSERT_N_EXTRA_ELEMENTS(n) \
|
#define PK_ASSERT_N_EXTRA_ELEMENTS(n) \
|
||||||
if(!has_n_extra_elements(vm, n)){ \
|
int __ex_count = count_extra_elements(vm, n); \
|
||||||
pkpy_error(vm_handle, "StackError", "not enough elements on stack"); \
|
if(__ex_count < n){ \
|
||||||
|
std::string msg = fmt("expected at least ", n, " elements, got ", __ex_count); \
|
||||||
|
pkpy_error(vm_handle, "StackError", msg.c_str()); \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,12 +17,12 @@ typedef int (*LuaStyleFuncC)(VM*);
|
|||||||
if(vm->_c.error != nullptr) \
|
if(vm->_c.error != nullptr) \
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
static int has_n_extra_elements(VM* vm, int n){
|
static int count_extra_elements(VM* vm, int n){
|
||||||
if(vm->callstack.empty()){
|
if(vm->callstack.empty()){
|
||||||
return vm->s_data.size() >= n;
|
return vm->s_data.size();
|
||||||
}
|
}
|
||||||
PyObject** base = vm->top_frame()->_locals.end();
|
PyObject** base = vm->top_frame()->_locals.end();
|
||||||
return vm->s_data._sp - base >= n;
|
return vm->s_data._sp - base;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* stack_item(VM* vm, int index){
|
static PyObject* stack_item(VM* vm, int index){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user