-
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 union TaghaVal value.
constant C string (pointer to 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 Tagha *vm, union TaghaVal *ret, size_t args, union TaghaVal params[]);
struct Tagha *Tagha_New(void *script);Allocates a struct Tagha pointer from heap and initializes it with a script pointer.
script - pointer to raw script data.
pointer to a newly allocated struct Tagha pointer, return NULL if an error occured or heap is exhausted.
struct Tagha *Tagha_NewNatives(void *script, const struct NativeInfo natives[]);Allocates a struct Tagha pointer from heap and initializes it with a script pointer and a constant array of natives for registration.
script - pointer to raw script data.
natives - constant array of natives to register.
pointer to a newly allocated struct Tagha pointer, return NULL if an error occured or heap is exhausted.
void Tagha_Free(struct Tagha **tagharef);Deallocates an allocated struct Tagha pointer and sets the pointer to NULL. Does NOT deallocate the script memory initialized to it; you need to use Tagha_GetRawScriptPtr to free it.
tagharef - reference to a struct Tagha pointer.
None.
void Tagha_Init(struct Tagha *vm, void *script);Initializes a script unto a pointer to struct Tagha and prepares the script data.
vm - pointer to a struct Tagha instance.
script - pointer to raw script data.
None.
void Tagha_InitNatives(struct Tagha *vm, void *script, const struct NativeInfo natives[]);Initializes a script unto a pointer to struct Tagha and prepares the script data, then registers the natives array.
vm - pointer to a struct Tagha instance.
script - pointer to raw script data.
natives - constant array of natives to register.
None.
void Tagha_PrintVMState(const struct Tagha *vm);Prints the registers and condition flag of a Tagha VM instance.
vm - pointer to a struct Tagha instance.
None.
const char *Tagha_GetError(const struct Tagha *vm);Returns a constant string of an error message to check what error had occurred. When an error or exception occurs in the VM, a return value of -1 is returned and the VMs error field is set.
vm - pointer to a struct Tagha instance.
const char C string error message. Returns NULL if the VM instance was NULL.
bool Tagha_RegisterNatives(struct Tagha *vm, const struct NativeInfo natives[]);Registers the native C functions to the VMs script for data communication between C code and the script's bytecode.
vm - pointer to a struct Tagha instance.
natives - array of C natives to register.
true or false if the operation was successful or not.
void *Tagha_GetGlobalVarByName(struct Tagha *vm, const char name[]);Returns a pointer to a script-defined global variable. If the global variable is defined a pointer, then the returning pointer will be a pointer to that pointer.
vm - pointer to a struct Tagha instance.
name - string name of the global variable to retrieve.
pointer to the global variable, NULL if the variable doesn't exist, the VM doesn't have script data/memory, or VM instance was NULL.
void *Tagha_GetRawScriptPtr(const struct Tagha *vm);Returns a pointer to a VMs script memory.
vm - pointer to a struct Tagha instance.
pointer to the script datum, NULL if no script was initialized to it or VM instance was NULL.
int32_t Tagha_CallFunc(struct Tagha *vm, const char name[], size_t args, union TaghaVal params[]);Manually calls a script function from C.
vm - pointer to a struct Tagha instance.
name - name of script function to invoke.
args - amount of arguments to pass.
params - function params to be passed, as an array of union TaghaVal.
returns a status int32 value, returns -1 if an error occurred. Use Tagha_GetReturnValue to get the proper return value as required from the function.
union TaghaVal Tagha_GetReturnValue(const struct Tagha *vm);retrieves the return value from a script bytecode function invocation as a type of union TaghaVal for easier type coercion.
vm - pointer to a struct Tagha instance.
value of type union TaghaVal, returns 0 as union TaghaVal if the VM instance is NULL.
int32_t Tagha_RunScript(struct Tagha *vm, int32_t argc, char *argv[]);Executes a script by calling its main function.
vm - pointer to a struct Tagha instance.
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 value, returns -1 if an error occurred.
constant C-style string (pointer to const char) of the name of the native function.
pointer to native C++ function.
The native must have the signature: void (*)(class CTagha *, union TaghaVal *, size_t, union TaghaVal []);
Inherits from struct Tagha C interface.
CTagha::CTagha(void *script);Constructor, functions similar to Tagha_Init.
script - pointer to raw script data.
None.
CTagha::CTagha(void *script, const struct CNativeInfo natives[]);Overloaded constructor, functions similar to Tagha_InitNatives.
script - pointer to raw script data.
natives - array of CNativeInfo values.
None.
bool CTagha::RegisterNatives(const struct CNativeInfo natives[]);registers an array of C++ natives, similar to Tagha_RegisterNatives.
natives - array of CNativeInfo values.
true or false if operation was successful.
void *CTagha::GetGlobalVarByName(const char name[]);Same as Tagha_GetGlobalVarByName but in a C++ class setting.
name - string name of global variable to retrieve.
returns pointer to global variable. NULL if an issue occurred.
int32_t CTagha::CallFunc(const char name[], size_t args, union TaghaVal params[]);Same as Tagha_CallFunc but in a C++ class setting.
name - name of script function to invoke.
args - amount of arguments to pass.
params - function params to be passed, as an array of union TaghaVal.
returns a status int32 value, returns -1 if an error occurred. Use CTagha::GetReturnValue to get the proper return value as required from the function.
union TaghaVal CTagha::GetReturnValue();Same as Tagha_GetReturnValue but in a C++ class setting.
None.
value of type union TaghaVal, returns 0 as union TaghaVal if issue occurred.
int32_t CTagha::RunScript(int32_t argc, char *argv[]);Same as Tagha_RunScript but in a C++ class setting.
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 value, returns -1 if an error occurred.
const char *CTagha::GetError();Same as Tagha_GetError but in a C++ class setting.
None.
const char C string error message.
void CTagha::PrintVMState();Same as Tagha_PrintVMState but in a C++ class setting.
None.
None.
void *CTagha::GetRawScriptPtr();Same as Tagha_GetRawScriptPtr but in a C++ class setting.
None.
pointer to the script datum, NULL if no script was initialized to it.