mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
added a pkpy_error method
This commit is contained in:
parent
ae34a6304a
commit
ceab1e0609
@ -550,3 +550,12 @@ bool pkpy_push(pkpy_vm* vm_handle, int index) {
|
|||||||
vm->c_data->push(vm->c_data->begin()[index]);
|
vm->c_data->push(vm->c_data->begin()[index]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool pkpy_error(pkpy_vm* vm_handle, const char* message) {
|
||||||
|
CVM* vm = (CVM*) vm_handle;
|
||||||
|
ERRHANDLER_OPEN
|
||||||
|
throw Exception("CBindingError", message);
|
||||||
|
ERRHANDLER_CLOSE
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,13 @@ typedef struct pkpy_vm_handle pkpy_vm;
|
|||||||
bool pkpy_clear_error(pkpy_vm*, char** message);
|
bool pkpy_clear_error(pkpy_vm*, char** message);
|
||||||
//NOTE you are responsible for freeing message
|
//NOTE you are responsible for freeing message
|
||||||
|
|
||||||
|
//this will cause the vm to enter an error state and report the given message
|
||||||
|
//when queried
|
||||||
|
//note that at the moment this is more like a panic than throwing an error
|
||||||
|
//the user will not be able to catch it with python code
|
||||||
|
bool pkpy_error(pkpy_vm*, const char* message);
|
||||||
|
|
||||||
|
|
||||||
pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os);
|
pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os);
|
||||||
bool pkpy_vm_run(pkpy_vm*, const char* source);
|
bool pkpy_vm_run(pkpy_vm*, const char* source);
|
||||||
void pkpy_vm_destroy(pkpy_vm*);
|
void pkpy_vm_destroy(pkpy_vm*);
|
||||||
|
@ -317,6 +317,8 @@ int main(int argc, char** argv) {
|
|||||||
//maybe worth fixing someday, but for now it is functionating as implemented
|
//maybe worth fixing someday, but for now it is functionating as implemented
|
||||||
error(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass"));
|
error(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass"));
|
||||||
|
|
||||||
|
error(pkpy_error(vm, "test direct error mechanism"));
|
||||||
|
|
||||||
|
|
||||||
//more complicated error handling
|
//more complicated error handling
|
||||||
//
|
//
|
||||||
|
@ -61,3 +61,6 @@ NameError: testing error throwing from python
|
|||||||
successfully errored with this message:
|
successfully errored with this message:
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
NameError: could not find requested global
|
NameError: could not find requested global
|
||||||
|
successfully errored with this message:
|
||||||
|
Traceback (most recent call last):
|
||||||
|
CBindingError: test direct error mechanism
|
||||||
|
@ -19,8 +19,8 @@ echo "checking results (they should be identical)"
|
|||||||
diff -q -s binding_test_scratch c_bindings/test_answers.txt
|
diff -q -s binding_test_scratch c_bindings/test_answers.txt
|
||||||
|
|
||||||
echo "cleaning up"
|
echo "cleaning up"
|
||||||
rm pocketpy_c.o
|
#rm pocketpy_c.o
|
||||||
rm test.o
|
rm test.o
|
||||||
rm binding_test_scratch
|
rm binding_test_scratch
|
||||||
rm c_binding_test
|
#rm c_binding_test
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user