mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
rewrite IO.for_fd.
IO.for_fd should call IO#initialize to initialize the created object properly. It cannot be implemented in Ruby.
This commit is contained in:
@@ -11,10 +11,6 @@ class IO
|
||||
|
||||
BUF_SIZE = 4096
|
||||
|
||||
def self.for_fd *args
|
||||
self.new(*args)
|
||||
end
|
||||
|
||||
def self.open(*args, &block)
|
||||
io = self.new(*args)
|
||||
|
||||
|
||||
@@ -356,6 +356,19 @@ fptr_finalize(mrb_state *mrb, struct mrb_io *fptr, int noraise)
|
||||
}
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_io_s_for_fd(mrb_state *mrb, mrb_value klass)
|
||||
{
|
||||
struct RClass *c = mrb_class_ptr(klass);
|
||||
enum mrb_vtype ttype = MRB_INSTANCE_TT(c);
|
||||
mrb_value obj;
|
||||
|
||||
/* copied from mrb_instance_alloc() */
|
||||
if (ttype == 0) ttype = MRB_TT_OBJECT;
|
||||
obj = mrb_obj_value((struct RObject*)mrb_obj_alloc(mrb, ttype, c));
|
||||
return mrb_io_initialize(mrb, obj);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_io_s_sysclose(mrb_state *mrb, mrb_value klass)
|
||||
{
|
||||
@@ -847,6 +860,7 @@ mrb_init_io(mrb_state *mrb)
|
||||
mrb_define_class_method(mrb, io, "_popen", mrb_io_s_popen, MRB_ARGS_ANY());
|
||||
mrb_define_class_method(mrb, io, "_sysclose", mrb_io_s_sysclose, MRB_ARGS_REQ(1));
|
||||
#endif
|
||||
mrb_define_class_method(mrb, io, "for_fd", mrb_io_s_for_fd, MRB_ARGS_ANY());
|
||||
mrb_define_class_method(mrb, io, "select", mrb_io_s_select, MRB_ARGS_ANY());
|
||||
mrb_define_class_method(mrb, io, "sysopen", mrb_io_s_sysopen, MRB_ARGS_ANY());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user