Janet 1.0.0-dev Documentation

Wrapping Types

Janet has several built in fundamental data types. These data types are the bread and butter of the Janet C API, and most functions and macros in the API expect some of their arguments to be if these types. However, as Janet is a dynamically language, Janet internally uses a boxed representation of these types, simply called Janet.

Functions that are specific to a particular type expect the unboxed or unwrapped type, while operations that are generic to Janet values will typically expect a Janet.

Wrapping Functions

These functions convert a C type into a generic Janet value.

Janet janet_wrap_nil(void);
Janet janet_wrap_number(double x);
Janet janet_wrap_true(void);
Janet janet_wrap_false(void);
Janet janet_wrap_boolean(int x);
Janet janet_wrap_string(const uint8_t *x);
Janet janet_wrap_symbol(const uint8_t *x);
Janet janet_wrap_keyword(const uint8_t *x);
Janet janet_wrap_array(JanetArray *x);
Janet janet_wrap_tuple(const Janet *x);
Janet janet_wrap_struct(const JanetKV *x);
Janet janet_wrap_fiber(JanetFiber *x);
Janet janet_wrap_buffer(JanetBuffer *x);
Janet janet_wrap_function(JanetFunction *x);
Janet janet_wrap_cfunction(JanetCFunction x);
Janet janet_wrap_table(JanetTable *x);
Janet janet_wrap_abstract(void *x);
Janet janet_wrap_pointer(void *x);
Janet janet_wrap_integer(int32_t x);

Unwrapping Functions

These function convert from a Janet to a more specific C type. If the Janet being unwrapped is not actually the returned type, the behavior is undefined.

const JanetKV *janet_unwrap_struct(Janet x);
const Janet *janet_unwrap_tuple(Janet x);
JanetFiber *janet_unwrap_fiber(Janet x);
JanetArray *janet_unwrap_array(Janet x);
JanetTable *janet_unwrap_table(Janet x);
JanetBuffer *janet_unwrap_buffer(Janet x);
const uint8_t *janet_unwrap_string(Janet x);
const uint8_t *janet_unwrap_symbol(Janet x);
const uint8_t *janet_unwrap_keyword(Janet x);
void *janet_unwrap_abstract(Janet x);
void *janet_unwrap_pointer(Janet x);
JanetFunction *janet_unwrap_function(Janet x);
JanetCFunction janet_unwrap_cfunction(Janet x);
int janet_unwrap_boolean(Janet x);
double janet_unwrap_number(Janet x);
int32_t janet_unwrap_integer(Janet x);