15. Janet
15.1. tangled file
To separate the C99 from C89 code, the monolith-related
janet code is tangled in a file called jmonolith.c
.
<<jmonolith.c>>=
#include <stdio.h>
#include "runt.h"
#include "graforge.h"
#include "soundpipe.h"
#ifdef USE_JANET
#include "janet/janet.h"
#endif
#include "monolith.h"
#ifdef USE_JANET
#include "jan.h"
#endif
<<jfunctions>>
15.2. struct declarations
15.2.1. Janet Env
<<typedefs>>=
#ifndef JANET_H_defined
typedef struct JanetTable JanetTable;
#endif
<<struct_contents>>=
JanetTable *env;
<<init>>=
m->env = NULL;
<<function_declarations>>=
JanetTable * monolith_janet_env(monolith_d *m);
<<functions>>=
JanetTable * monolith_janet_env(monolith_d *m)
{
return m->env;
}
<<function_declarations>>=
void monolith_janet_env_set(monolith_d *m, JanetTable *env);
<<functions>>=
void monolith_janet_env_set(monolith_d *m, JanetTable *env)
{
m->env = env;
}
15.3. deinit
<<cleanup>>=
#ifdef USE_JANET
monolith_janet_deinit(m);
#endif
15.4. jex loader
<<monolith_runt_loader>>=
#ifdef USE_JANET
load_jex(m);
#endif
15.5. DONE core monolith janet functions
CLOSED: [2019-10-24 Thu 11:51]
All core functions are loaded up using the function
monolith_janet_core
. A "core" function is considered
to be anything declared inside of the tangled monolith.c
file.
<<function_declarations>>=
#ifdef USE_JANET
void monolith_janet_core(JanetTable *env);
#endif
<<jfunctions>>=
#ifdef USE_JANET
<<janet_functions>>
static const JanetReg core_cfuns[] =
{
<<core_janet_entries>>
{NULL, NULL, NULL}
};
void monolith_janet_core(JanetTable *env)
{
janet_cfuns(env, "monolith", core_cfuns);
}
#endif
15.6. Foo Janet Function
A simple "foo" function. A good starting point for making core janet functions.
<<core_janet_entries>>=
{
"monolith/foo",
j_foo,
"Just a test function.\n"
},
<<janet_functions>>=
static Janet j_foo(int32_t argc, Janet *argv)
{
janet_fixarity(argc, 0);
printf("Hello from Monolith\n");
return janet_wrap_nil();
}
prev | home | next