next: *
This commit is contained in:
parent
1746d12266
commit
d279bf1d31
17 changed files with 407 additions and 137 deletions
29
next/core/native.c
Normal file
29
next/core/native.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <growl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dynarray.h"
|
||||
|
||||
static void call_native(GrowlVM *vm, void *data) {
|
||||
void (*fn)(GrowlVM *) = data;
|
||||
fn(vm);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
static GrowlAlienType native_type = {
|
||||
.name = "native",
|
||||
.finalizer = NULL,
|
||||
.call = call_native,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
void growl_register_native(GrowlVM *vm, const char *name,
|
||||
void (*fn)(GrowlVM *)) {
|
||||
Growl alien = growl_make_alien_tenured(vm, &native_type, (void *)fn);
|
||||
GrowlDictionary *entry =
|
||||
growl_dictionary_upsert(&vm->dictionary, name, &vm->arena);
|
||||
GrowlDefinition *def = push(&vm->defs, &vm->arena);
|
||||
def->name = growl_arena_strdup(&vm->arena, name);
|
||||
def->callable = alien;
|
||||
entry->callable = alien;
|
||||
entry->index = vm->defs.count - 1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue