Add read-u8 built-in (R7RS)

io.getc gets UTF-8 characters
This commit is contained in:
Lassi Kortela 2019-08-13 22:53:37 +03:00
parent c2da0753af
commit 2e8153019c
1 changed files with 12 additions and 0 deletions

View File

@ -153,6 +153,17 @@ value_t fl_read(value_t *args, uint32_t nargs)
return v;
}
value_t builtin_read_u8(value_t *args, uint32_t nargs)
{
argcount("read-u8", nargs, 1);
struct ios *s = toiostream(args[0], "read-u8");
int c;
if ((c = ios_getc(s)) == IOS_EOF)
// lerror(IOError, "io.getc: end of file reached");
return FL_EOF;
return fixnum(c);
}
value_t fl_iogetc(value_t *args, uint32_t nargs)
{
argcount("io.getc", nargs, 1);
@ -447,6 +458,7 @@ static struct builtinspec iostreamfunc_info[] = {
{ "file", fl_file },
{ "buffer", fl_buffer },
{ "read", fl_read },
{ "read-u8", builtin_read_u8 },
{ "write", fl_write },
{ "io.flush", fl_ioflush },
{ "io.close", fl_ioclose },