|
@@ -14,37 +14,15 @@ typedef struct pkpy_vm_handle pkpy_vm;
|
|
|
typedef int (*pkpy_function)(pkpy_vm*);
|
|
typedef int (*pkpy_function)(pkpy_vm*);
|
|
|
|
|
|
|
|
/* Basic Functions */
|
|
/* Basic Functions */
|
|
|
-PK_EXPORT pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os);
|
|
|
|
|
-PK_EXPORT void pkpy_vm_destroy(pkpy_vm*);
|
|
|
|
|
-
|
|
|
|
|
-//we we take a lot of inspiration from the lua api for these bindings
|
|
|
|
|
-//the key difference being most methods return a bool,
|
|
|
|
|
-//true if it succeeded false if it did not
|
|
|
|
|
-
|
|
|
|
|
-//if a method returns false call the pkpy_clear_error method to check the error and clear it
|
|
|
|
|
-//if pkpy_clear_error returns false it means that no error was set, and it takes no action
|
|
|
|
|
-//if pkpy_clear_error returns true it means there was an error and it was cleared,
|
|
|
|
|
-//it will provide a string summary of the error in the message parameter (if it is not NULL)
|
|
|
|
|
-//if null is passed in as message, and it will just print the message to stderr
|
|
|
|
|
-PK_EXPORT bool pkpy_clear_error(pkpy_vm*, char** 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
|
|
|
|
|
-PK_EXPORT bool pkpy_error(pkpy_vm*, const char* name, const char* message);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+PK_EXPORT pkpy_vm* pkpy_new_vm(bool enable_os);
|
|
|
|
|
+PK_EXPORT void pkpy_delete_vm(pkpy_vm* vm);
|
|
|
|
|
+PK_EXPORT bool pkpy_vm_exec(pkpy_vm* vm, const char* source);
|
|
|
|
|
+PK_EXPORT bool pkpy_vm_exec_2(pkpy_vm* vm, const char* source, const char* filename, int mode, const char* module);
|
|
|
|
|
|
|
|
|
|
+/* Stack Manipulation */
|
|
|
PK_EXPORT bool pkpy_pop(pkpy_vm*, int n);
|
|
PK_EXPORT bool pkpy_pop(pkpy_vm*, int n);
|
|
|
-
|
|
|
|
|
-//push the item at index onto the top of the stack (as well as leaving it where
|
|
|
|
|
-//it is on the stack)
|
|
|
|
|
-PK_EXPORT bool pkpy_push(pkpy_vm*, int index);
|
|
|
|
|
-
|
|
|
|
|
|
|
+PK_EXPORT bool pkpy_dup_top(pkpy_vm*);
|
|
|
|
|
+PK_EXPORT bool pkpy_rot_two(pkpy_vm*);
|
|
|
PK_EXPORT bool pkpy_push_function(pkpy_vm*, pkpy_function, int);
|
|
PK_EXPORT bool pkpy_push_function(pkpy_vm*, pkpy_function, int);
|
|
|
PK_EXPORT bool pkpy_push_int(pkpy_vm*, int);
|
|
PK_EXPORT bool pkpy_push_int(pkpy_vm*, int);
|
|
|
PK_EXPORT bool pkpy_push_float(pkpy_vm*, double);
|
|
PK_EXPORT bool pkpy_push_float(pkpy_vm*, double);
|
|
@@ -53,26 +31,32 @@ PK_EXPORT bool pkpy_push_string(pkpy_vm*, const char*);
|
|
|
PK_EXPORT bool pkpy_push_stringn(pkpy_vm*, const char*, int length);
|
|
PK_EXPORT bool pkpy_push_stringn(pkpy_vm*, const char*, int length);
|
|
|
PK_EXPORT bool pkpy_push_voidp(pkpy_vm*, void*);
|
|
PK_EXPORT bool pkpy_push_voidp(pkpy_vm*, void*);
|
|
|
PK_EXPORT bool pkpy_push_none(pkpy_vm*);
|
|
PK_EXPORT bool pkpy_push_none(pkpy_vm*);
|
|
|
|
|
+PK_EXPORT bool pkpy_push_eval(pkpy_vm*, const char* source);
|
|
|
|
|
+PK_EXPORT bool pkpy_push_module(pkpy_vm*, const char* name);
|
|
|
|
|
+
|
|
|
|
|
+/* Error Handling */
|
|
|
|
|
+
|
|
|
|
|
+PK_EXPORT bool pkpy_clear_error(pkpy_vm*, char** message);
|
|
|
|
|
+PK_EXPORT bool pkpy_error(pkpy_vm*, const char* name, const char* message);
|
|
|
|
|
+//will return true if the vm is currently in an error state
|
|
|
|
|
+PK_EXPORT bool pkpy_check_error(pkpy_vm*);
|
|
|
|
|
+
|
|
|
|
|
+/* Variables */
|
|
|
|
|
|
|
|
PK_EXPORT bool pkpy_set_global(pkpy_vm*, const char* name);
|
|
PK_EXPORT bool pkpy_set_global(pkpy_vm*, const char* name);
|
|
|
PK_EXPORT bool pkpy_get_global(pkpy_vm*, const char* name);
|
|
PK_EXPORT bool pkpy_get_global(pkpy_vm*, const char* name);
|
|
|
|
|
+//will return true if global exists
|
|
|
|
|
+PK_EXPORT bool pkpy_check_global(pkpy_vm*, const char* name);
|
|
|
|
|
+PK_EXPORT bool pkpy_getattr(pkpy_vm*, const char* name);
|
|
|
|
|
+PK_EXPORT bool pkpy_setattr(pkpy_vm*, const char* name);
|
|
|
|
|
|
|
|
-//first push callable you want to call
|
|
|
|
|
-//then push the arguments to send
|
|
|
|
|
-//argc is the number of arguments that was pushed (not counting the callable)
|
|
|
|
|
-PK_EXPORT bool pkpy_call(pkpy_vm*, int argc);
|
|
|
|
|
|
|
+/* Callables */
|
|
|
|
|
|
|
|
-//first push the object the method belongs to (self)
|
|
|
|
|
-//then push the the argments
|
|
|
|
|
-//argc is the number of arguments that was pushed (not counting the callable or self)
|
|
|
|
|
-//name is the name of the method to call on the object
|
|
|
|
|
|
|
+PK_EXPORT bool pkpy_call(pkpy_vm*, int argc);
|
|
|
PK_EXPORT bool pkpy_call_method(pkpy_vm*, const char* name, int argc);
|
|
PK_EXPORT bool pkpy_call_method(pkpy_vm*, const char* name, int argc);
|
|
|
|
|
|
|
|
|
|
+/* Types */
|
|
|
|
|
|
|
|
-//we will break with the lua api here
|
|
|
|
|
-//lua uses 1 as the index to the first pushed element for all of these functions
|
|
|
|
|
-//but we will start counting at zero to match python
|
|
|
|
|
-//we will allow negative numbers to count backwards from the top
|
|
|
|
|
PK_EXPORT bool pkpy_to_int(pkpy_vm*, int index, int* ret);
|
|
PK_EXPORT bool pkpy_to_int(pkpy_vm*, int index, int* ret);
|
|
|
PK_EXPORT bool pkpy_to_float(pkpy_vm*, int index, double* ret);
|
|
PK_EXPORT bool pkpy_to_float(pkpy_vm*, int index, double* ret);
|
|
|
PK_EXPORT bool pkpy_to_bool(pkpy_vm*, int index, bool* ret);
|
|
PK_EXPORT bool pkpy_to_bool(pkpy_vm*, int index, bool* ret);
|
|
@@ -97,34 +81,6 @@ PK_EXPORT bool pkpy_is_string(pkpy_vm*, int index);
|
|
|
PK_EXPORT bool pkpy_is_voidp(pkpy_vm*, int index);
|
|
PK_EXPORT bool pkpy_is_voidp(pkpy_vm*, int index);
|
|
|
PK_EXPORT bool pkpy_is_none(pkpy_vm*, int index);
|
|
PK_EXPORT bool pkpy_is_none(pkpy_vm*, int index);
|
|
|
|
|
|
|
|
-//will return true if global exists
|
|
|
|
|
-PK_EXPORT bool pkpy_check_global(pkpy_vm*, const char* name);
|
|
|
|
|
-
|
|
|
|
|
-//will return true if the vm is currently in an error state
|
|
|
|
|
-PK_EXPORT bool pkpy_check_error(pkpy_vm*);
|
|
|
|
|
-
|
|
|
|
|
-//will return true if at least free empty slots remain on the stack
|
|
|
|
|
-PK_EXPORT bool pkpy_check_stack(pkpy_vm*, int free);
|
|
|
|
|
-
|
|
|
|
|
-//returns the number of elements on the stack
|
|
|
|
|
-PK_EXPORT int pkpy_stack_size(pkpy_vm*);
|
|
|
|
|
-
|
|
|
|
|
-PK_EXPORT bool pkpy_getattr(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);
|
|
|
|
|
-
|
|
|
|
|
-// create a new native module with the given name and push it onto the stack
|
|
|
|
|
-PK_EXPORT bool pkpy_new_module(void* vm, const char* name);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-/* vm api */
|
|
|
|
|
-
|
|
|
|
|
-// for backwards compatibility
|
|
|
|
|
-#define pkpy_vm_run(vm, source) pkpy_vm_exec(vm, source)
|
|
|
|
|
-
|
|
|
|
|
-PK_EXPORT bool pkpy_vm_exec(pkpy_vm* vm, const char* source);
|
|
|
|
|
-PK_EXPORT bool pkpy_vm_exec_2(pkpy_vm* vm, const char* source, const char* filename, int mode, const char* module);
|
|
|
|
|
-
|
|
|
|
|
/* special api */
|
|
/* special api */
|
|
|
|
|
|
|
|
// free a pointer allocated from pkpy's heap
|
|
// free a pointer allocated from pkpy's heap
|