[WIP] add generic file object constructor (pic_funopen)
This commit is contained in:
parent
1cb9b0347d
commit
63d23bdeda
|
@ -41,4 +41,6 @@ struct pic_port *pic_stdin(pic_state *);
|
||||||
struct pic_port *pic_stdout(pic_state *);
|
struct pic_port *pic_stdout(pic_state *);
|
||||||
struct pic_port *pic_stderr(pic_state *);
|
struct pic_port *pic_stderr(pic_state *);
|
||||||
|
|
||||||
|
pic_file *pic_funopen(void *cookie, int (*read)(void *, char *, int), int (*write)(void *, const char *, int), fpos_t (*seek)(void *, fpos_t, int), int (*close)(void *));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
22
src/port.c
22
src/port.c
|
@ -37,6 +37,28 @@ pic_stdout(pic_state *pic)
|
||||||
return pic_port_ptr(pic_apply(pic, proc, pic_nil_value()));
|
return pic_port_ptr(pic_apply(pic, proc, pic_nil_value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pic_file *
|
||||||
|
pic_funopen(void *cookie,
|
||||||
|
int (*read)(void *, char *, int),
|
||||||
|
int (*write)(void *, const char *, int),
|
||||||
|
fpos_t (*seek)(void *, fpos_t, int),
|
||||||
|
int (*close)(void *))
|
||||||
|
{
|
||||||
|
pic_file *file;
|
||||||
|
|
||||||
|
file = (pic_file *)malloc(sizeof(pic_file));
|
||||||
|
if (! file) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
file->vtable.cookie = cookie;
|
||||||
|
file->vtable.read = read;
|
||||||
|
file->vtable.write = write;
|
||||||
|
file->vtable.seek = seek;
|
||||||
|
file->vtable.close = close;
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
static void write_pair(pic_state *pic, struct pic_pair *pair);
|
static void write_pair(pic_state *pic, struct pic_pair *pair);
|
||||||
static void write_str(pic_state *pic, struct pic_string *str);
|
static void write_str(pic_state *pic, struct pic_string *str);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue