small refactoring. use DEFINE_STANDARD_PORT_ACCESSOR macro to define pic_stdxx
This commit is contained in:
parent
61ff69b968
commit
b4c3e2cc4f
|
@ -201,6 +201,10 @@ void pic_load_port(pic_state *, struct pic_port *);
|
|||
void pic_load_cstr(pic_state *, const char *);
|
||||
|
||||
pic_value pic_funcall(pic_state *pic, struct pic_lib *, const char *, pic_list);
|
||||
pic_value pic_funcall0(pic_state *pic, struct pic_lib *, const char *);
|
||||
pic_value pic_funcall1(pic_state *pic, struct pic_lib *, const char *, pic_value);
|
||||
pic_value pic_funcall2(pic_state *pic, struct pic_lib *, const char *, pic_value, pic_value);
|
||||
pic_value pic_funcall3(pic_state *pic, struct pic_lib *, const char *, pic_value, pic_value, pic_value);
|
||||
pic_value pic_ref(pic_state *, struct pic_lib *, const char *);
|
||||
void pic_set(pic_state *, struct pic_lib *, const char *, pic_value);
|
||||
|
||||
|
|
|
@ -14,35 +14,20 @@ pic_eof_object()
|
|||
return v;
|
||||
}
|
||||
|
||||
struct pic_port *
|
||||
pic_stdin(pic_state *pic)
|
||||
{
|
||||
pic_value obj;
|
||||
#define DEFINE_STANDARD_PORT_ACCESSOR(name, var) \
|
||||
struct pic_port * \
|
||||
name(pic_state *pic) \
|
||||
{ \
|
||||
pic_value obj; \
|
||||
\
|
||||
obj = pic_funcall0(pic, pic->PICRIN_BASE, var); \
|
||||
\
|
||||
return pic_port_ptr(obj); \
|
||||
}
|
||||
|
||||
obj = pic_funcall(pic, pic->PICRIN_BASE, "current-input-port", pic_nil_value());
|
||||
|
||||
return pic_port_ptr(obj);
|
||||
}
|
||||
|
||||
struct pic_port *
|
||||
pic_stdout(pic_state *pic)
|
||||
{
|
||||
pic_value obj;
|
||||
|
||||
obj = pic_funcall(pic, pic->PICRIN_BASE, "current-output-port", pic_nil_value());
|
||||
|
||||
return pic_port_ptr(obj);
|
||||
}
|
||||
|
||||
struct pic_port *
|
||||
pic_stderr(pic_state *pic)
|
||||
{
|
||||
pic_value obj;
|
||||
|
||||
obj = pic_funcall(pic, pic->PICRIN_BASE, "current-error-port", pic_nil_value());
|
||||
|
||||
return pic_port_ptr(obj);
|
||||
}
|
||||
DEFINE_STANDARD_PORT_ACCESSOR(pic_stdin, "current-input-port")
|
||||
DEFINE_STANDARD_PORT_ACCESSOR(pic_stdout, "current-output-port")
|
||||
DEFINE_STANDARD_PORT_ACCESSOR(pic_stderr, "current-error-port")
|
||||
|
||||
struct pic_port *
|
||||
pic_make_standard_port(pic_state *pic, xFILE *file, short dir)
|
||||
|
|
|
@ -467,6 +467,12 @@ pic_funcall(pic_state *pic, struct pic_lib *lib, const char *name, pic_list args
|
|||
return pic_apply(pic, pic_proc_ptr(proc), args);
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_funcall0(pic_state *pic, struct pic_lib *lib, const char *name)
|
||||
{
|
||||
return pic_funcall(pic, lib, name, pic_nil_value());
|
||||
}
|
||||
|
||||
void
|
||||
pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue