Data Structures | |
struct | CrocRegisterFunc |
Macros | |
#define | croc_ex_registerGlobal(t, f) croc_ex_registerGlobalUV((t), (f), 0) |
#define | croc_ex_registerField(t, f) croc_ex_registerFieldUV((t), (f), 0) |
#define | croc_ex_registerMethod(t, f) croc_ex_registerMethodUV((t), (f), 0) |
Functions | |
void | croc_ex_makeModule (CrocThread *t, const char *name, CrocNativeFunc loader) |
void | croc_ex_registerGlobalUV (CrocThread *t, CrocRegisterFunc f, uword_t numUpvals) |
void | croc_ex_registerFieldUV (CrocThread *t, CrocRegisterFunc f, uword_t numUpvals) |
void | croc_ex_registerMethodUV (CrocThread *t, CrocRegisterFunc f, uword_t numUpvals) |
void | croc_ex_registerGlobals (CrocThread *t, const CrocRegisterFunc *funcs) |
void | croc_ex_registerFields (CrocThread *t, const CrocRegisterFunc *funcs) |
void | croc_ex_registerMethods (CrocThread *t, const CrocRegisterFunc *funcs) |
Helpers for making native libraries.
struct CrocRegisterFunc |
A structure which holds the description of a native function.
Data Fields | ||
---|---|---|
const char * | name | The function's name, or NULL to indicate the end of an array of this structure. |
word_t | maxParams | The maximum number of parameters, or -1 to make it variadic. |
CrocNativeFunc | func | The address of the native function itself. |
#define croc_ex_registerGlobal | ( | t, | |
f | |||
) | croc_ex_registerGlobalUV((t), (f), 0) |
Makes a closure from f
and sets it as a new global in the current environment.
#define croc_ex_registerField | ( | t, | |
f | |||
) | croc_ex_registerFieldUV((t), (f), 0) |
Makes a closure from f
and field-assigns it into the value on top of the stack.
#define croc_ex_registerMethod | ( | t, | |
f | |||
) | croc_ex_registerMethodUV((t), (f), 0) |
Makes a closure from f
and adds it as a method into the class on top of the stack.
void croc_ex_makeModule | ( | CrocThread * | t, |
const char * | name, | ||
CrocNativeFunc | loader | ||
) |
Given a name
and a loader
native function which will act as the top-level function for the module, inserts an entry into the Croc modules.customLoaders
table which will call the loader
when name
is imported.
void croc_ex_registerGlobalUV | ( | CrocThread * | t, |
CrocRegisterFunc | f, | ||
uword_t | numUpvals | ||
) |
Like croc_ex_registerGlobal, but expects numUpvals
values on top of the stack, and creates the function with them as its upvalues.
void croc_ex_registerFieldUV | ( | CrocThread * | t, |
CrocRegisterFunc | f, | ||
uword_t | numUpvals | ||
) |
Like croc_ex_registerField, but expects numUpvals
values on top of the stack, and creates the function with them as its upvalues.
The object that will be given the field should be below the upvalues.
void croc_ex_registerMethodUV | ( | CrocThread * | t, |
CrocRegisterFunc | f, | ||
uword_t | numUpvals | ||
) |
Like croc_ex_registerMethod, but expects numUpvals
values on top of the stack, and creates the function with them as its upvalues.
The object that will be given the method should be below the upvalues.
void croc_ex_registerGlobals | ( | CrocThread * | t, |
const CrocRegisterFunc * | funcs | ||
) |
Takes an array of CrocRegisterFunc structs, terminated by a struct whose name
member is NULL
, and registers them all as globals in the current environment.
For example:
void croc_ex_registerFields | ( | CrocThread * | t, |
const CrocRegisterFunc * | funcs | ||
) |
Like croc_ex_registerGlobals, but field-assigns them into the value on top of the stack.
void croc_ex_registerMethods | ( | CrocThread * | t, |
const CrocRegisterFunc * | funcs | ||
) |
Like croc_ex_registerGlobals, but adds them as methods into the class on top of the stack.