4. Janet Code

4.1. Loader + Boilerplate

<<funclist>>=
#ifndef BUILD_FUZZYDOT_PLUGIN
#define NAME(s) "monolith/gfx-"s
#else
#define NAME(s) s
#endif

static const JanetReg cfuns[] = {
    {NAME("fuzzydot"),
     j_fuzzydot,
     "Creates a fuzzy dot!"},
    {NULL, NULL, NULL}
};
<<plugin_entry>>=
void monolith_gfx_fuzzydot_loader(JanetTable *env,
                                const char *name)
{
    janet_cfuns(env, name, cfuns);
}

#ifdef BUILD_FUZZYDOT_PLUGIN
JANET_MODULE_ENTRY(JanetTable *env)
{
    monolith_gfx_fuzzydot_loader(env, "fuzzydot");
}
#endif

4.2. The Function

<<funcdefs>>=
static Janet j_fuzzydot(int32_t argc, Janet *argv);
<<janet_function>>=
static Janet j_fuzzydot(int32_t argc, Janet *argv)
{
    int x, y;
    float rad;
    float feather;
    float blend;
    int powslope;
    monolith_d *m;
    monolith_framebuffer *fb;
    monolith_pixel c;

    janet_fixarity(argc, 9);
    m = monolith_data_get();
    x = janet_getinteger(argv, 0);
    y = janet_getinteger(argv, 1);
    rad = janet_getnumber(argv, 2);
    feather = janet_getnumber(argv, 3);
    powslope = janet_getnumber(argv, 4);

    c.r = janet_getinteger(argv, 5);
    c.g = janet_getinteger(argv, 6);
    c.b = janet_getinteger(argv, 7);
    blend = janet_getinteger(argv, 8);

    fb = monolith_fb_get(m);

    monolith_gfx_fuzzydot(fb, x, y, rad, feather, blend, powslope, c);
    return janet_wrap_nil();
}



prev | home | next