hack out io functions for fxCG50

This commit is contained in:
KikooDX 2021-11-18 12:16:39 +01:00
parent ed4cda96bd
commit 0c0d60706c
1 changed files with 20 additions and 2 deletions

View File

@ -89,11 +89,15 @@ void fe_error(fe_Context *ctx, const char *msg) {
/* do error handler */
if (ctx->handlers.error) { ctx->handlers.error(ctx, msg, cl); }
/* error handler returned -- print error and traceback, exit */
#ifdef RAYLIB
fprintf(stderr, "error: %s\n", msg);
#endif
for (; !isnil(cl); cl = cdr(cl)) {
char buf[64];
fe_tostring(ctx, car(cl), buf, sizeof(buf));
#ifdef RAYLIB
fprintf(stderr, "=> %s\n", buf);
#endif
}
exit(EXIT_FAILURE);
}
@ -398,7 +402,7 @@ void fe_write(fe_Context *ctx, fe_Object *obj, fe_WriteFn fn, void *udata, int q
static void writefp(fe_Context *ctx, void *udata, char chr) {
unused(ctx);
fputc(chr, udata);
/* fputc(chr, udata); */
}
void fe_writefp(fe_Context *ctx, fe_Object *obj, FILE *fp) {
@ -547,7 +551,8 @@ fe_Object* fe_read(fe_Context *ctx, fe_ReadFn fn, void *udata) {
static char readfp(fe_Context *ctx, void *udata) {
int chr;
unused(ctx);
return (chr = fgetc(udata)) == EOF ? '\0' : chr;
/* return (chr = fgetc(udata)) == EOF ? '\0' : chr; */
return '\0';
}
fe_Object* fe_readfp(fe_Context *ctx, FILE *fp) {
@ -730,10 +735,17 @@ static fe_Object* eval(fe_Context *ctx, fe_Object *obj, fe_Object *env, fe_Objec
case P_PRINT:
while (!isnil(arg)) {
#ifdef RAYLIB
fe_writefp(ctx, evalarg(), stdout);
if (!isnil(arg)) { printf(" "); }
#else
evalarg();
unused(isnil(arg));
#endif
}
#ifdef RAYLIB
printf("\n");
#endif
break;
case P_LT: numcmpop(<); break;
@ -843,7 +855,9 @@ static char buf[64000];
static void onerror(fe_Context *ctx, const char *msg, fe_Object *cl) {
unused(ctx), unused(cl);
#ifdef RAYLIB
fprintf(stderr, "error: %s\n", msg);
#endif
longjmp(toplevel, -1);
}
@ -867,10 +881,14 @@ int main(int argc, char **argv) {
/* re(p)l */
for (;;) {
fe_restoregc(ctx, gc);
#ifdef RAYLIB
if (fp == stdin) { printf("> "); }
#endif
if (!(obj = fe_readfp(ctx, fp))) { break; }
obj = fe_eval(ctx, obj);
#ifdef RAYLIB
if (fp == stdin) { fe_writefp(ctx, obj, stdout); printf("\n"); }
#endif
}
return EXIT_SUCCESS;