From 1c14feffa4e0a93d8c698536fc8c3765b80b1d9f Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jan 2014 00:51:19 +0900 Subject: [PATCH] add accessors of stdio ports --- include/picrin/port.h | 4 ++++ src/port.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/picrin/port.h b/include/picrin/port.h index b02c173d..0340b3a3 100644 --- a/include/picrin/port.h +++ b/include/picrin/port.h @@ -27,4 +27,8 @@ struct pic_port { pic_value pic_eof_object(); +struct pic_port *pic_stdin(pic_state *); +struct pic_port *pic_stdout(pic_state *); +struct pic_port *pic_stderr(pic_state *); + #endif diff --git a/src/port.c b/src/port.c index 4a73d3ad..cfe6b1bc 100644 --- a/src/port.c +++ b/src/port.c @@ -17,6 +17,16 @@ pic_eof_object() return v; } +struct pic_port * +pic_stdin(pic_state *pic) +{ + struct pic_proc *proc; + + proc = pic_proc_ptr(pic_ref(pic, "current-input-port")); + + return pic_port_ptr(pic_apply(pic, proc, pic_nil_value())); +} + static void write_pair(pic_state *pic, struct pic_pair *pair); static void write_str(pic_state *pic, struct pic_string *str);