get owned
This commit is contained in:
102
src/noom.h
102
src/noom.h
@@ -7,7 +7,7 @@
|
||||
#define NOOM_VERSION_MAJOR 0
|
||||
#define NOOM_VERSION_MINOR 0
|
||||
#define NOOM_VERSION_PATCH 0
|
||||
#if NOOM_VERSION_PATCH==0
|
||||
#if NOOM_VERSION_PATCH == 0
|
||||
#define NOOM_VERSION_FULL NN_XSTR(NOOM_VERSION_MAJOR) "." NN_XSTR(NOOM_VERSION_MINOR)
|
||||
#else
|
||||
#define NOOM_VERSION_FULL NN_XSTR(NOOM_VERSION_MAJOR) "." NN_XSTR(NOOM_VERSION_MINOR) "." NN_XSTR(NOOM_VERSION_PATCH)
|
||||
@@ -140,11 +140,11 @@ typedef enum noom_CoroutineStatus {
|
||||
|
||||
typedef struct noom_LuaVM noom_LuaVM;
|
||||
|
||||
typedef noom_Exit noom_CFunction(noom_LuaVM *vm);
|
||||
typedef noom_Exit noom_KFunction(noom_LuaVM *vm, noom_Exit status, void *ctx);
|
||||
typedef noom_Exit noom_CFunction(noom_LuaVM* vm);
|
||||
typedef noom_Exit noom_KFunction(noom_LuaVM* vm, noom_Exit status, void* ctx);
|
||||
|
||||
noom_LuaVM *noom_createVM(noom_LuaVersion version);
|
||||
void noom_destroyVM(noom_LuaVM *vm);
|
||||
noom_LuaVM* noom_createVM(noom_LuaVersion version);
|
||||
void noom_destroyVM(noom_LuaVM* vm);
|
||||
|
||||
// type of a stack slot.
|
||||
// If negative, its relative to the top where -1 is the top.
|
||||
@@ -154,57 +154,57 @@ typedef noom_int_t noom_slot_t;
|
||||
|
||||
// Push data
|
||||
|
||||
noom_Exit noom_pushint(noom_LuaVM *vm, noom_int_t integer);
|
||||
noom_Exit noom_pushnumber(noom_LuaVM *vm, noom_float_t number);
|
||||
noom_Exit noom_pushbool(noom_LuaVM *vm, noom_bool_t boolean);
|
||||
noom_Exit noom_pushstring(noom_LuaVM *vm, const char *s);
|
||||
noom_Exit noom_pushlstring(noom_LuaVM *vm, const char *s, noom_uint_t len);
|
||||
noom_Exit noom_createtable(noom_LuaVM *vm, noom_uint_t prealloc);
|
||||
noom_Exit noom_pushint(noom_LuaVM* vm, noom_int_t integer);
|
||||
noom_Exit noom_pushnumber(noom_LuaVM* vm, noom_float_t number);
|
||||
noom_Exit noom_pushbool(noom_LuaVM* vm, noom_bool_t boolean);
|
||||
noom_Exit noom_pushstring(noom_LuaVM* vm, const char* s);
|
||||
noom_Exit noom_pushlstring(noom_LuaVM* vm, const char* s, noom_uint_t len);
|
||||
noom_Exit noom_createtable(noom_LuaVM* vm, noom_uint_t prealloc);
|
||||
// Push a C closure using the top [upvalues] stackslots as upvalues
|
||||
noom_Exit noom_pushcclosure(noom_LuaVM *vm, noom_CFunction *f, noom_uint_t upvalues);
|
||||
noom_Exit noom_pushcclosure(noom_LuaVM* vm, noom_CFunction* f, noom_uint_t upvalues);
|
||||
#define noom_pushcfunction(vm, f) noom_pushcclosure((vm), (f), 0)
|
||||
noom_Exit noom_pushuserdata(noom_LuaVM *vm, void *userdata);
|
||||
noom_Exit noom_pushlightuserdata(noom_LuaVM *vm, void *userdata);
|
||||
noom_Exit noom_pushuserdata(noom_LuaVM* vm, void* userdata);
|
||||
noom_Exit noom_pushlightuserdata(noom_LuaVM* vm, void* userdata);
|
||||
// Pops the top function and pushes a new coroutine with that function being called
|
||||
noom_Exit noom_pushcoroutine(noom_LuaVM *vm);
|
||||
noom_Exit noom_pushcoroutine(noom_LuaVM* vm);
|
||||
// Pushes the error object, if any. If no error, nil is pushed
|
||||
noom_Exit noom_pusherror(noom_LuaVM *vm);
|
||||
noom_Exit noom_pusherror(noom_LuaVM* vm);
|
||||
// Pushes the globals table itself
|
||||
noom_Exit noom_pushglobals(noom_LuaVM *vm);
|
||||
noom_Exit noom_pushglobals(noom_LuaVM* vm);
|
||||
// Pushes the registry itself
|
||||
noom_Exit noom_pushregistry(noom_LuaVM *vm);
|
||||
noom_Exit noom_pushregistry(noom_LuaVM* vm);
|
||||
// Pushes the running coroutine
|
||||
noom_Exit noom_pushrunning(noom_LuaVM *vm);
|
||||
noom_Exit noom_pushrunning(noom_LuaVM* vm);
|
||||
|
||||
// Stack stuff
|
||||
|
||||
// Gets the amount of values on the stack
|
||||
// Signed because of C math rules, but it cannot be negative and is perfectly safe to cast to unsigned
|
||||
noom_int_t noom_getstacksize(noom_LuaVM *vm);
|
||||
noom_int_t noom_getstacksize(noom_LuaVM* vm);
|
||||
// Sets the stack size, popping or pushing nil as need be.
|
||||
// Its signed so it gives a stack *underflow* on negative values, instead of a confusing stack overflow
|
||||
noom_Exit noom_setstacksize(noom_LuaVM *vm, noom_int_t amount);
|
||||
#define noom_pushnils(vm, x) noom_setstacksize((vm), noom_getstacksize((vm))+(x))
|
||||
noom_Exit noom_setstacksize(noom_LuaVM* vm, noom_int_t amount);
|
||||
#define noom_pushnils(vm, x) noom_setstacksize((vm), noom_getstacksize((vm)) + (x))
|
||||
#define noom_pushnil(vm) noom_pushnils((vm), 1)
|
||||
#define noom_popn(vm, n) noom_setstacksize((vm), noom_getstacksize((vm)) - (n))
|
||||
#define noom_pop(vm) noom_popn((vm), 1)
|
||||
// Marks a stackslot as to-be-closed
|
||||
noom_Exit noom_markTBC(noom_LuaVM *vm, noom_slot_t slot);
|
||||
noom_Exit noom_markTBC(noom_LuaVM* vm, noom_slot_t slot);
|
||||
// Preallocate stack space to OOM/stack overflow *early*
|
||||
noom_Exit noom_preallocStack(noom_LuaVM *vm, noom_uint_t amount);
|
||||
noom_Exit noom_preallocStack(noom_LuaVM* vm, noom_uint_t amount);
|
||||
// Set the value at [dst] to [src]
|
||||
noom_Exit noom_copyto(noom_LuaVM *vm, noom_slot_t dst, noom_slot_t src);
|
||||
noom_Exit noom_copyto(noom_LuaVM* vm, noom_slot_t dst, noom_slot_t src);
|
||||
// Set the value at [dst] to be a pointer to [src].
|
||||
// This is used to link upvalues.
|
||||
// This means that writes to either are reflected in both.
|
||||
noom_Exit noom_linkto(noom_LuaVM *vm, noom_slot_t dst, noom_slot_t src);
|
||||
noom_Exit noom_linkto(noom_LuaVM* vm, noom_slot_t dst, noom_slot_t src);
|
||||
// Stack rotation
|
||||
noom_Exit noom_rotate(noom_LuaVM *vm, noom_int_t amount);
|
||||
noom_Exit noom_rotate(noom_LuaVM* vm, noom_int_t amount);
|
||||
|
||||
// Operations
|
||||
|
||||
// Dupes the top [n] values [m] times
|
||||
noom_Exit noom_dupearr(noom_LuaVM *vm, noom_uint_t n, noom_uint_t m);
|
||||
noom_Exit noom_dupearr(noom_LuaVM* vm, noom_uint_t n, noom_uint_t m);
|
||||
#define noom_dupen(vm, n) noom_dupearr((vm), 1, (n))
|
||||
#define noom_dupe(vm) noom_dupen((vm), 1)
|
||||
|
||||
@@ -215,82 +215,82 @@ noom_Exit noom_dupearr(noom_LuaVM *vm, noom_uint_t n, noom_uint_t m);
|
||||
// This will pop argc+1 values, where the first one, at [-argc-1], is the value being called, and everything after is arguments.
|
||||
// [retc] is the desired return count. It is signed, as negative values mean to return ALL values, regardless of how many.
|
||||
// If the function returns too many values, the excess is popped. If it returns too few, nils are pushed.
|
||||
noom_Exit noom_callk(noom_LuaVM *vm, noom_uint_t argc, noom_int_t retc, noom_KFunction *f, void *ctx);
|
||||
noom_Exit noom_callk(noom_LuaVM* vm, noom_uint_t argc, noom_int_t retc, noom_KFunction* f, void* ctx);
|
||||
#define noom_call(vm, argc, retc) noom_callk((vm), (argc), (retc), 0, 0)
|
||||
// Sets the return count of the function. Should be the last statement to prevent confusing behavior.
|
||||
// The actual *values* returned are the top [retc] values on the stack after the function exits.
|
||||
noom_Exit noom_return(noom_LuaVM *vm, noom_uint_t retc);
|
||||
noom_Exit noom_return(noom_LuaVM* vm, noom_uint_t retc);
|
||||
// Attempts to yield the current coroutine with the top [n] values and a supplied continuation function.
|
||||
// If the continuation function's memory address is 0, it is replaced with a default function which
|
||||
// does nothing and returns no values.
|
||||
// When the coroutine is resumed, the continuation function is invoked.
|
||||
noom_Exit noom_yieldk(noom_LuaVM *vm, noom_uint_t n, noom_KFunction *f, void *ctx);
|
||||
noom_Exit noom_yieldk(noom_LuaVM* vm, noom_uint_t n, noom_KFunction* f, void* ctx);
|
||||
#define noom_yield(vm, n) noom_yieldk((vm), (n), 0, 0)
|
||||
|
||||
// Like a noom_call, except instead of calling, it resumes coroutines.
|
||||
// This cannot yield but allows yields.
|
||||
noom_Exit noom_resume(noom_LuaVM *vm, noom_uint_t argc, noom_uint_t retc);
|
||||
noom_Exit noom_resume(noom_LuaVM* vm, noom_uint_t argc, noom_uint_t retc);
|
||||
// Pops a coroutine, gives its status through the out-pointer
|
||||
noom_Exit noom_corostatus(noom_LuaVM *vm, noom_CoroutineStatus *status);
|
||||
noom_Exit noom_corostatus(noom_LuaVM* vm, noom_CoroutineStatus* status);
|
||||
// Pops a coroutine, closes it.
|
||||
// This means it'll unwind the callstack of the coroutine and call to-be-closed values as needed.
|
||||
// If those error, which can happen, this errors as well.
|
||||
noom_Exit noom_coroclose(noom_LuaVM *vm);
|
||||
noom_Exit noom_coroclose(noom_LuaVM* vm);
|
||||
|
||||
// Get the type of a slot. Invalid slots are just [nil]
|
||||
noom_LuaType noom_typeof(noom_LuaVM *vm, noom_slot_t x);
|
||||
noom_LuaType noom_typeof(noom_LuaVM* vm, noom_slot_t x);
|
||||
|
||||
// TODO: evaluate if k variants of these should be used, as
|
||||
// these *could* yield due to metatables
|
||||
|
||||
// Pops the top 2 values and pushes the result of the operation
|
||||
noom_Exit noom_binop(noom_LuaVM *vm, noom_BinOp op);
|
||||
noom_Exit noom_binop(noom_LuaVM* vm, noom_BinOp op);
|
||||
// Pops the top 2 values and pushes the result of the operation
|
||||
noom_Exit noom_unaryop(noom_LuaVM *vm, noom_UnaryOp op);
|
||||
noom_Exit noom_unaryop(noom_LuaVM* vm, noom_UnaryOp op);
|
||||
|
||||
// Pops (table, key) and pushes `table[key]`
|
||||
noom_Exit noom_gettable(noom_LuaVM *vm);
|
||||
noom_Exit noom_gettable(noom_LuaVM* vm);
|
||||
// Pops (table, key, value) and sets `table[key] = value`
|
||||
noom_Exit noom_settable(noom_LuaVM *vm);
|
||||
noom_Exit noom_settable(noom_LuaVM* vm);
|
||||
// Gets the metatable. This gets the actual metatable, __metatable is ignored
|
||||
noom_Exit noom_getmetatable(noom_LuaVM *vm);
|
||||
noom_Exit noom_getmetatable(noom_LuaVM* vm);
|
||||
// Pops (table, metatable) and sets the metatable of [table] to [metatable]
|
||||
noom_Exit noom_setmetatable(noom_LuaVM *vm);
|
||||
noom_Exit noom_setmetatable(noom_LuaVM* vm);
|
||||
|
||||
// Given stack values (table, key), it pops key and pushes the next key as well as `table[nkey]`.
|
||||
// If key is nil, the next key is actually the first key of the table, as nil cannot be a key.
|
||||
// This lets you iterate stuff with like `pairs`.
|
||||
// This DOES NOT account for __pairs.
|
||||
noom_Exit noom_next(noom_LuaVM *vm);
|
||||
noom_Exit noom_next(noom_LuaVM* vm);
|
||||
|
||||
// Taking data out
|
||||
|
||||
noom_Exit noom_tobool(noom_LuaVM *vm, noom_slot_t x, noom_bool_t *b);
|
||||
noom_Exit noom_toint(noom_LuaVM *vm, noom_slot_t x, noom_int_t *n);
|
||||
noom_Exit noom_tonumber(noom_LuaVM *vm, noom_slot_t x, noom_float_t *n);
|
||||
noom_Exit noom_tobool(noom_LuaVM* vm, noom_slot_t x, noom_bool_t* b);
|
||||
noom_Exit noom_toint(noom_LuaVM* vm, noom_slot_t x, noom_int_t* n);
|
||||
noom_Exit noom_tonumber(noom_LuaVM* vm, noom_slot_t x, noom_float_t* n);
|
||||
// NOTE: the string is not automatically retained until function exit.
|
||||
// KEEP THE VALUE SOMEWHERE OR GC MAY FREE IT.
|
||||
noom_Exit noom_tolstring(noom_LuaVM *vm, noom_slot_t x, const char **s, noom_uint_t *len);
|
||||
noom_Exit noom_tolstring(noom_LuaVM* vm, noom_slot_t x, const char** s, noom_uint_t* len);
|
||||
#define noom_tostring(vm, x, s) noom_tolstring((vm), (x), (s), 0)
|
||||
// Casts to a pointer if applicable, memory address 0x0 if not.
|
||||
// The pointer is effectively meaningless, and only really matters
|
||||
// for the %p format specifier in `string.format()`
|
||||
noom_Exit noom_topointer(noom_LuaVM *vm, noom_slot_t x, const void **p);
|
||||
noom_Exit noom_topointer(noom_LuaVM* vm, noom_slot_t x, const void** p);
|
||||
|
||||
// Type coercion
|
||||
|
||||
// Converts the value at [x] to a boolean
|
||||
noom_Exit noom_cast2truthy(noom_LuaVM *vm, noom_slot_t x);
|
||||
noom_Exit noom_cast2truthy(noom_LuaVM* vm, noom_slot_t x);
|
||||
// Converts the value at [x] to a number
|
||||
noom_Exit noom_cast2num(noom_LuaVM *vm, noom_slot_t x);
|
||||
noom_Exit noom_cast2num(noom_LuaVM* vm, noom_slot_t x);
|
||||
// Converts the value at [x] to a string, ignoring __tostring and __name.
|
||||
noom_Exit noom_cast2str(noom_LuaVM *vm, noom_slot_t x);
|
||||
noom_Exit noom_cast2str(noom_LuaVM* vm, noom_slot_t x);
|
||||
|
||||
// Misc
|
||||
|
||||
// Run the garbage collector to clean up memory.
|
||||
// DO NOT RUN IN THE ALLOCATOR IF ANY IS SUPPLIED, OR YOU WILL GET THE WORST POSSIBLE ERRORS.
|
||||
void noom_gc(noom_LuaVM *vm);
|
||||
void noom_gc(noom_LuaVM* vm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user