-
Notifications
You must be signed in to change notification settings - Fork 0
Wi API Reference
If you're using Wi API to create a library, your library must have a wi_foreign_init function marked as WI_FOREIGN_INIT with wi_foreign_fn_t signature.
Expands to:
-
#ifdef _WIN32:__declspec(dllexport) -
#else:
Used to mark all public API functions
Expands to:
-
#ifdef _WIN32:__declspec(dllexport) -
#else:
Used to mark foreign library entry point (wi_foreign_init)
Wi's number type
Opaque Wi object handle
The result of running Wi code
-
WI_RUN_OK: No errors occurred -
WI_RUN_ERROR: A runtime error or a compile error occurred -
WI_RUN_ABORT: Execution was aborted early viawi_state_abort
Opaque Wi state handle
Foreign (C) function pointer, called from Wi scripts
Userdata finalizer - function called when the state is deleted (freed)
Define the standard library in a state
Parameters:
-
wi_state_t* state: Wi state instance
Define a foreign (C) function in the state
Parameters:
-
wi_state_t* state: Wi state instance -
const char* name: Function name -
wi_foreign_fn_t fn: Pointer to the C function implementation -
int arity: Function's arity (number of arguments it expects), use-1for variable arguments
Define an object in the state (global)
Parameters:
-
wi_state_t* state: Wi state instance -
const char* name: Object name
Returns: Pointer to the created object
Set a real field on an object
Parameters:
-
wi_state_t* state: Wi state instance -
wi_object_t* object: Target object -
const char* name: Field name -
wi_real_t real: Value to set
Set a boolean field on an object
Parameters:
-
wi_state_t* state: Wi state instance -
wi_object_t* object: Target object -
const char* name: Field name -
bool boolean: Value to set
Set a string field on an object
Parameters:
-
wi_state_t* state: Wi state instance -
wi_object_t* object: Target object -
const char* name: Field name -
char* string: Value to set
Set userdata as a field on an object
Parameters:
-
wi_state_t* state: Wi state instance -
wi_object_t* object: Target object -
const char* name: Field name -
void* userdata: Pointer to userdata -
wi_userdata_finalizer_fn_t finalizer: Userdata finalizer
Set a foreign (C) function as a field on an object
Parameters:
-
wi_state_t* state: Wi state instance -
wi_object_t* object: Target object -
const char* name: Field name -
wi_foreign_fn_t fn: Pointer to the C function implementation -
int arity: Function's arity (number of arguments it expects)
Create a new Wi state instance
Parameters:
-
wi_conf_t conf: Wi configuration, seewi_conf.hfor more
Returns: Created Wi state instance
Delete a Wi state instance and free all associated memory
Parameters:
-
wi_state_t* state: Wi state instance
Print the current call stack backtrace to stderr
Parameters:
-
wi_state_t* state: Wi state instance
Throw a runtime error in the state
Parameters:
-
wi_state_t* state: Wi state instance -
const char* format:printfformat string -
...: Format arguments
Request the state to stop execution, returning WI_RUN_ABORT from wi_state_run. Must only be called while a script is running (e.g., from a foreign (C) function). Calling it outside wi_state_run is undefined behavior
Parameters:
-
wi_state_t* state: Wi state instance
Request the state to stop execution as soon as possible, returning WI_RUN_ABORT from wi_state_run. In contrast to wi_state_abort, this function is safe to call asynchronously (e.g., from a signal handler or another thread)
Parameters:
-
wi_state_t* state: Wi state instance
Execute Wi code
Parameters:
-
wi_state_t* state: Wi state instance -
const char* file_path: Path to the script, used for error messages -
const char* src: Code string
Returns: Run result
Slot functions are used in C functions to get arguments from the Wi caller and to set the return value. Slot 0 is reserved for the return value. / / Check if a slot contains a real value
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: bool
Check if a slot contains a null value
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: bool
Check if a slot contains a boolean value
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: bool
Check if a slot contains a string value
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: bool
Check if a slot contains userdata
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: bool
Store a real value in a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Store a null value in a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Store a boolean value in a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Store a string value in a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Store userdata in a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count]) -
const char* name: Userdata name, used for type checking -
void* userdata: Pointer to userdata -
wi_userdata_finalizer_fn_t finalizer: Userdata finalizer
Get a real value from a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: Real stored in a slot
Get a boolean value from a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: Boolean stored in a slot
Get a string value from a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: String stored in a slot
Get userdata from a slot
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: Userdata stored in a slot
Get a real value from a slot with type-checking
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: Real stored in a slot
Get a boolean value from a slot with type-checking
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: Boolean stored in a slot
Get a string value from a slot with type-checking
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count])
Returns: String stored in a slot
Get userdata from a slot with type-checking
Parameters:
-
wi_state_t* state: Wi state instance -
int slot: Slot index (0-[arg_count]) -
const char* name: Userdata name, used for type checking
Returns: Userdata stored in a slot
Expands to: 0
Default configuration (all flags disabled)
Expands to: "1.0.0"
Wi version as a string
Value: 1
Value: 0
Value: 0
Value: 65535
Maximum number of constants in a function
Value: 65535
Maximum jump offset
Value: 65535
Maximum loop offset
Value: 255
Maximum number of local variables in a function
Value: 255
Maximum number of upvalues in a function (closure)
Value: 1048576
Initial heap size before first collection
Value: 2
Heap growth factor per garbage collection run
Value: 15
Maximum number of temporary GC root references
Value: 16384
Maximum number of call frames
Value: 65535
Maximum number of values on the VM stack
Configuration flags for the Wi state
-
WI_CONF_PRINT_CODE: Print bytecode after compilation -
WI_CONF_STRESS_GC: Run garbage collection on every allocation -
WI_CONF_LOG_GC: Log garbage collection
Configuration bitmask type
Set a configuration flag
Parameters:
-
wi_conf_t* conf: Configuration bitmask -
wi_conf_flag_t flag: Configuration flag
Check if a configuration flag is set
Parameters:
-
wi_conf_t* conf: Configuration bitmask -
wi_conf_flag_t flag: Configuration flag
Returns: true if the flag is set, false otherwise