diff --git a/c_bindings/pocketpy_c.cpp b/c_bindings/pocketpy_c.cpp index ff9ff5e2..c766ad65 100644 --- a/c_bindings/pocketpy_c.cpp +++ b/c_bindings/pocketpy_c.cpp @@ -562,4 +562,4 @@ void* pkpy_get_id(pkpy_vm* vm_handle, int index) { PyObject* o = vm->c_data->at(index); if(is_tagged(o)) return nullptr; return (void*) o; -} \ No newline at end of file +} diff --git a/c_bindings/test.c b/c_bindings/test.c index 488c361e..9f9ae8fa 100644 --- a/c_bindings/test.c +++ b/c_bindings/test.c @@ -71,7 +71,7 @@ int test_return_none(pkpy_vm* vm) { } int test_error_propagate(pkpy_vm* vm) { - pkpy_get_global(vm, "does not exist"); + pkpy_error(vm, "NameError", "catch me"); return 1; } @@ -307,10 +307,8 @@ int main(int argc, char** argv) { // testing code going to standard error, can ignore next error pkpy_clear_error(vm, NULL); - //with the current way execptions are handled, this will fail and pass the - //error clean through, ignoring the python handling - // - //maybe worth fixing someday, but for now it is functionating as implemented + //errors + //this should be catchable check(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass")); error(pkpy_error(vm, "_", "test direct error mechanism")); @@ -330,10 +328,10 @@ int main(int argc, char** argv) { //at such a time this interferes with a real world use case of the bindings //we can revisit it // - check(pkpy_vm_run(vm, "def error_from_python() : raise NotImplementedError()")); - check(pkpy_push_function(vm, test_nested_error, 0)); - check(pkpy_set_global(vm, "test_nested_error")); - error(pkpy_vm_run(vm, "test_nested_error()")); + //check(pkpy_vm_run(vm, "def error_from_python() : raise NotImplementedError()")); + //check(pkpy_push_function(vm, test_nested_error, 0)); + //check(pkpy_set_global(vm, "test_nested_error")); + //error(pkpy_vm_run(vm, "test_nested_error()")); check(pkpy_vm_run(vm, "import math")); check(pkpy_get_global(vm, "math")); @@ -353,6 +351,10 @@ int main(int argc, char** argv) { check(pkpy_setattr(vm, "pi")); check(pkpy_vm_run(vm, "print(math.pi)")); - pkpy_vm_destroy(vm); + + //should give a type error + check(pkpy_push_float(vm, 2.0)); + error(pkpy_to_int(vm, -1, &r_int)); + return 0; } diff --git a/c_bindings/test_answers.txt b/c_bindings/test_answers.txt index 91c872b8..5d23e763 100644 --- a/c_bindings/test_answers.txt +++ b/c_bindings/test_answers.txt @@ -54,7 +54,7 @@ successfully errored with this message: Traceback (most recent call last): File "", line 1 test_error_propagate() -NameError: does not exist +NameError: catch me successfully errored with this message: Traceback (most recent call last): File "", line 1 @@ -63,13 +63,8 @@ NameError: testing error throwing from python successfully errored with this message: Traceback (most recent call last): _: test direct error mechanism -successfully errored with this message: -Traceback (most recent call last): - File "", line 1 - test_nested_error() - File "", line 1 - def error_from_python() : raise NotImplementedError() -NotImplementedError pi: 3.14 pi: 3.14 2 +successfully errored with this message: +TypeError: expected 'int', but got 'float' diff --git a/docs/LuaC-API/stack.md b/docs/LuaC-API/stack.md index ec9fbd34..3f66c97a 100644 --- a/docs/LuaC-API/stack.md +++ b/docs/LuaC-API/stack.md @@ -17,6 +17,7 @@ Pop `n` items from the stack. #### `bool pkpy_push_function(pkpy_vm*, pkpy_function, int argc)` Push a function onto the stack. The function is of `typedef int (*pkpy_function)(pkpy_vm*);` +The provided function should return the number of return values it leaves on the stack #### `bool pkpy_push_int(pkpy_vm*, int)`