mruby-io/io.c: implement IO#flush in C

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-12-31 10:39:05 +09:00
parent 0628669790
commit 965997d91b
2 changed files with 8 additions and 6 deletions
-6
View File
@@ -74,12 +74,6 @@ class IO
str
end
def flush
# mruby-io always writes immediately (no output buffer).
raise IOError, "closed stream" if self.closed?
self
end
def hash
# We must define IO#hash here because IO includes Enumerable and
# Enumerable#hash will call IO#read() otherwise
+8
View File
@@ -1631,6 +1631,13 @@ io_readchar(mrb_state *mrb, mrb_value self)
return io_bufread(mrb, buf, len);
}
static mrb_value
io_flush(mrb_state *mrb, mrb_value self)
{
io_get_open_fptr(mrb, self);
return self;
}
void
mrb_init_io(mrb_state *mrb)
{
@@ -1664,6 +1671,7 @@ mrb_init_io(mrb_state *mrb)
mrb_define_method(mrb, io, "close_on_exec=", io_set_close_on_exec, MRB_ARGS_REQ(1));
mrb_define_method(mrb, io, "close_on_exec?", io_close_on_exec_p, MRB_ARGS_NONE());
mrb_define_method(mrb, io, "closed?", io_closed, MRB_ARGS_NONE()); /* 15.2.20.5.2 */
mrb_define_method(mrb, io, "flush", io_flush, MRB_ARGS_NONE()); /* 15.2.20.5.7 */
mrb_define_method(mrb, io, "ungetc", io_ungetc, MRB_ARGS_REQ(1));
mrb_define_method(mrb, io, "pos", io_pos, MRB_ARGS_NONE());
mrb_define_method(mrb, io, "pid", io_pid, MRB_ARGS_NONE());