-
Notifications
You must be signed in to change notification settings - Fork 9
Tagha API Reference
boolean value.
signed char value.
signed short value.
signed long value.
signed long long value.
unsigned char value.
unsigned short value.
unsigned long value.
unsigned long long value.
size_t value.
uintptr_t value.
intptr_t value.
32-bit float value. exists only if __TAGHA_FLOAT32_DEFINED is defined.
64-bit float value. exists only if __TAGHA_FLOAT64_DEFINED is defined.
pointer to bool value.
pointer to signed char value.
pointer to signed short value.
pointer to signed long value.
pointer to signed long long value.
pointer to unsigned char value.
pointer to unsigned short value.
pointer to unsigned long value.
pointer to unsigned long long value.
pointer to size_t value.
pointer to 32-bit float value. exists only if __TAGHA_FLOAT32_DEFINED is defined.
pointer to 64-bit float value. exists only if __TAGHA_FLOAT64_DEFINED is defined.
pointer to void type value.
pointer to a C string (const char *)
pointer to union TaghaVal value.
constant C string (const char *) of the name of the native function.
pointer to native C function (C++ interface has it's own implementation).
The native must have the signature: void (*)(struct TaghaModule *ctxt, union TaghaVal *ret, size_t args, union TaghaVal params[]);
integer code that defines an out of bounds error. Value of -1.
integer code that defines execution was successful. Value of 0.
integer code that defines either a NULL or invalid pointer dereference attempt. Value of 1.
integer code that defines a missing/NULL bytecode function. Value of 2.
integer code that defines a missing/unresolved/NULL native function. Value of 3.
integer code that defines an invalid script during loading. Value of 4.
integer code that defines an invalid stack size given. Value of 5.
integer code that defines a stack overflow. Value of 6.
member of union TaghaVal that is given a pointer of union TaghaVal to an array of arguments.
member of uint64_t, stores the size of the array that is referenced by Area.
struct TaghaModule *tagha_module_new_from_file(const char filename[]);Allocates a struct TaghaModule pointer from a script file.
-
filename- filename string of the script to load.
pointer to a newly allocated struct TaghaModule pointer, returns NULL if an error occured or problems reading the script.
struct TaghaModule *tagha_module_new_from_buffer(uint8_t buffer[]);Allocates a struct TaghaModule pointer from an existing data buffer.
-
buffer- pointer to raw script data.
pointer to a newly allocated struct TaghaModule pointer, return NULL if an error occured or problem reading the buffer data.
bool tagha_module_free(struct TaghaModule **module_ref);Deallocates a struct TaghaModule pointer's data, deallocates the pointer itself, and then sets the pointer to NULL.
-
module_ref- reference to astruct TaghaModulepointer.
boolean value whether the deallocation was successful or not.
bool tagha_module_from_file(struct TaghaModule *module, const char filename[]);builds a module, from an existing pointer, from a file.
-
module- pointer to astruct TaghaModuleinstance. -
filename- filename string of the script to load.
True if building the module from the file was a success, false otherwise.
bool tagha_module_from_buffer(struct TaghaModule *module, uint8_t buffer[]);builds a module, from an existing pointer, from an existing data buffer.
-
module- pointer to astruct TaghaModuleinstance. -
buffer- pointer to raw script data.
True if building the module from buffer was a success, false otherwise.
bool tagha_module_del(struct TaghaModule *module);Deallocates a struct TaghaModule pointer's data and zeroes the data. The module pointer itself is NOT freed.
-
module- pointer to astruct TaghaModuleinstance.
boolean value whether the deallocation was successful or not.
void tagha_module_print_vm_state(const struct TaghaModule *module);Prints the registers and condition flag of a Tagha module instance.
-
module- pointer to astruct TaghaModuleinstance.
None.
const char *tagha_module_get_error(const struct TaghaModule *module);Returns a constant string of an error message to check what error had occurred. When an error or exception occurs in the VM portion of a module, a return value of -1 is returned and the module's error field is set.
-
module- pointer to astruct TaghaModuleinstance.
constant C string (const char *) error message. Returns NULL if the module instance was NULL.
bool tagha_module_register_natives(struct TaghaModule *module, const struct TaghaNative natives[]);Registers the native C functions to a module for data communication between C code and the script's bytecode.
-
module- pointer to astruct TaghaModuleinstance. -
natives- array ofstruct TaghaNative's to register.
true or false if the operation was successful or not.
bool tagha_module_register_ptr(struct TaghaModule *module, const char varname[], void *ptr);Registers a pointer to a script's global pointer variable by name. Example - registering 'stdin' standard input FILE *:
tagha_module_register_ptr(module, "stdin", stdin);Will crash the program if the variable name given is not a pointer on the script's side.
-
module- pointer to astruct TaghaModuleinstance. -
varname- string name of the global ptr variable to register. -
ptr- ptr value to register.
true or false if the operation was successful or not.
void *tagha_module_get_globalvar_by_name(struct TaghaModule *module, const char name[]);Returns a pointer to a script-defined global variable. If the global variable is defined as a pointer in the script, then the returning pointer will be a pointer to that pointer.
-
module- pointer to astruct TaghaModuleinstance. -
name- string name of the global variable to retrieve.
pointer to the global variable, NULL if the variable doesn't exist, the module doesn't have script data/memory, or module instance was NULL.
int32_t tagha_module_call(struct TaghaModule *module, const char funcname[], size_t args, union TaghaVal params[], union TaghaVal *return_val);Manually calls a script function from C by name.
-
module- pointer to astruct TaghaModuleinstance. -
name- name of script function to invoke. -
args- amount of arguments to pass. -
params- function params to be passed, as an array ofunion TaghaVal. -
return_val- pointer tounion TaghaValfor use as a return value buffer.
returns a status int32_t value, returns -1 if an error occurred. Use return_val to get a proper return value.
int32_t tagha_module_invoke(struct TaghaModule *module, int64_t func_index, size_t args, union TaghaVal params[], union TaghaVal *return_val);Manually calls a script function from C by function index. Designed to be used for natives that take a function pointer from bytecode.
-
module- pointer to astruct TaghaModuleinstance. -
func_index- index of script function to invoke. -
args- amount of arguments to pass. -
params- function params to be passed, as an array ofunion TaghaVal. -
return_val- pointer tounion TaghaValfor use as a return value buffer.
returns a status int32_t value, returns -1 if an error occurred. Use return_val to get a proper return value.
int32_t tagha_module_run(struct TaghaModule *module, int32_t argc, char *argv[]);Executes a script by calling its main function.
-
module- pointer to astruct TaghaModuleinstance. -
argc- amount of strings given. -
argv- array of C string ptrs to give to the script, the C string MUST be modifiable as per the C language standard.
returns a status int32_t value, returns -1 if an error occurred.
void tagha_module_throw_error(struct TaghaModule *module, int32_t err);Allows a developer to manually throw a VM runtime exception. Only use within a native C or C++ function call and that the script needs to stop running.
-
module- pointer to astruct TaghaModuleinstance. -
err- value that's higher or lower than 0, can be either a user defined error or anenum TaghaErrCodevalue.
None.
void tagha_module_force_safemode(struct TaghaModule *module);Forces a module to run in safemode.
-
module- pointer to astruct TaghaModuleinstance.
None.