91 lines
2.0 KiB
C
91 lines
2.0 KiB
C
#include "fe.h"
|
|
#include "raygint/display.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
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 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);
|
|
#ifdef RAYLIB
|
|
FILE *fp = fopen("test.fe", "rb");
|
|
int gc = fe_savegc(ctx);
|
|
rDisplayInit();
|
|
SetTargetFPS(30);
|
|
|
|
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));
|
|
|
|
for (;;) {
|
|
fe_Object *obj = fe_readfp(ctx, fp);
|
|
|
|
/* 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();
|
|
fclose(fp);
|
|
#endif
|
|
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)
|
|
{
|
|
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;
|
|
}
|