Skip to content

Wi API Reference

cyxigo edited this page Jul 17, 2026 · 3 revisions

Using Wi API to create a library

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.

wi.h

Types

wi_real_t

Wi's number type

wi_object_t

Opaque Wi object handle

wi_run_result_t##

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 via wi_state_abort

wi_state_t

Opaque Wi state handle

wi_foreign_fn_t

Foreign (C) function pointer, called from Wi scripts

wi_userdata_finalizer_fn_t

Userdata finalizer - function called when the state is deleted (freed)

Functions

wi_def_std

Define the standard library in a state
Parameters:

  • state: Wi state instance

wi_def_foreign

Define a foreign (C) function in the state
Parameters:

  • state: Wi state instance
  • name: Function name
  • fn: Pointer to the C function implementation
  • arity: Function's arity (number of arguments it expects), use -1 for variable arguments

wi_def_std

Define the standard library in a state
Parameters:

  • state: Wi state instance

wi_def_std

Define the standard library in a state
Parameters:

  • state: Wi state instance

wi_def_std

Define the standard library in a state
Parameters:

  • state: Wi state instance

Clone this wiki locally