106 lines
2.3 KiB
C
106 lines
2.3 KiB
C
#include "fe.h"
|
|
#include "file.h"
|
|
#include "raygint/display.h"
|
|
#include <stdlib.h>
|
|
|
|
#define UNUSED(c) (void)(c)
|
|
|
|
static fe_Object *f_dblock(fe_Context *ctx, fe_Object *arg);
|
|
static fe_Object *f_dcolor(fe_Context *ctx, fe_Object *arg);
|
|
static fe_Object *f_dclear(fe_Context *ctx, fe_Object *arg);
|
|
static fe_Object *f_drect(fe_Context *ctx, fe_Object *arg);
|
|
static char read_custom(fe_Context *ctx, void *udata);
|
|
|
|
static int r = 0;
|
|
static int g = 0;
|
|
static int b = 0;
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const int size = 0xffffff;
|
|
void *data = malloc(size);
|
|
fe_Context *ctx = fe_open(data, size);
|
|
int gc = fe_savegc(ctx);
|
|
|
|
fe_set(ctx, fe_symbol(ctx, "dblock"), fe_cfunc(ctx, f_dblock));
|
|
fe_set(ctx, fe_symbol(ctx, "dcolor"), fe_cfunc(ctx, f_dcolor));
|
|
fe_set(ctx, fe_symbol(ctx, "dclear"), fe_cfunc(ctx, f_dclear));
|
|
fe_set(ctx, fe_symbol(ctx, "drect"), fe_cfunc(ctx, f_drect));
|
|
|
|
rDisplayInit();
|
|
#ifdef RAYLIB
|
|
SetTargetFPS(30);
|
|
#endif
|
|
|
|
for (;;) {
|
|
fe_Object *obj = fe_read(ctx, read_custom, test_fe);
|
|
|
|
/* break if there's nothing left to read */
|
|
if (!obj)
|
|
break;
|
|
|
|
/* evaluate read object */
|
|
fe_eval(ctx, obj);
|
|
|
|
/* restore GC stack which would now contain both the
|
|
* read object and result from evaluation */
|
|
fe_restoregc(ctx, gc);
|
|
}
|
|
|
|
rDisplayDeinit();
|
|
fe_close(ctx);
|
|
free(data);
|
|
return 0;
|
|
}
|
|
|
|
static fe_Object *
|
|
f_dblock(fe_Context *ctx, fe_Object *arg)
|
|
{
|
|
rDrawBegin();
|
|
while (fe_nextarg(ctx, &arg))
|
|
;
|
|
rDrawEnd();
|
|
return NULL;
|
|
}
|
|
|
|
static fe_Object *
|
|
f_dcolor(fe_Context *ctx, fe_Object *arg)
|
|
{
|
|
r = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
|
|
g = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
|
|
b = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
|
|
return NULL;
|
|
}
|
|
|
|
static fe_Object *
|
|
f_dclear(fe_Context *ctx, fe_Object *arg)
|
|
{
|
|
UNUSED(ctx);
|
|
UNUSED(arg);
|
|
dclear(C_RGB(r, g, b));
|
|
return NULL;
|
|
}
|
|
|
|
static fe_Object *
|
|
f_drect(fe_Context *ctx, fe_Object *arg)
|
|
{
|
|
const int x = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
|
|
const int y = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
|
|
const int w = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
|
|
const int h = fe_tonumber(ctx, fe_nextarg(ctx, &arg));
|
|
drect(x, y, x + w - 1, y + h - 1, C_RGB(r, g, b));
|
|
return NULL;
|
|
}
|
|
|
|
static char
|
|
read_custom(fe_Context *ctx, void *udata)
|
|
{
|
|
static int cursor = 0;
|
|
const char *data = (char *)udata;
|
|
UNUSED(ctx);
|
|
if (data[cursor])
|
|
return data[cursor++];
|
|
return data[cursor];
|
|
}
|