mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
errno.c (mrb_exxx_init): simplify the function.
Code duplication with mrb_sce_init has been unified.
This commit is contained in:
@@ -51,8 +51,6 @@ static const struct {
|
||||
#define E2C_LEN (sizeof(e2c) / sizeof(e2c[0]))
|
||||
#define NOE2C_LEN (sizeof(noe2c) / sizeof(noe2c[0]))
|
||||
|
||||
static mrb_value mrb_exxx_init(mrb_state *mrb, mrb_value self);
|
||||
|
||||
static struct RClass*
|
||||
mrb_errno_define_exxx(mrb_state *mrb, mrb_sym name, int eno)
|
||||
{
|
||||
@@ -226,6 +224,16 @@ mrb_sce_init(mrb_state *mrb, mrb_value self, mrb_value m, mrb_value no)
|
||||
mrb_exc_mesg_set(mrb, mrb_exc_ptr(self), str);
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
mrb_exxx_init(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value m = mrb_nil_value();
|
||||
|
||||
mrb_get_args(mrb, "|S", &m);
|
||||
mrb_sce_init(mrb, self, m, mrb_nil_value());
|
||||
return self;
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
mrb_sce_init_m(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
@@ -286,24 +294,6 @@ mrb_sce_sys_fail(mrb_state *mrb, mrb_value cls)
|
||||
return mrb_nil_value(); /* NOTREACHED */
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
mrb_exxx_init(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value m, no, str;
|
||||
|
||||
no = mrb_const_get(mrb, mrb_obj_value(mrb_class(mrb, self)), MRB_SYM(Errno));
|
||||
str = mrb_str_new_cstr(mrb, strerror((int)mrb_fixnum(no)));
|
||||
|
||||
m = mrb_nil_value();
|
||||
mrb_get_args(mrb, "|S", &m);
|
||||
if (!mrb_nil_p(m)) {
|
||||
mrb_str_cat2(mrb, str, " - ");
|
||||
mrb_str_append(mrb, str, m);
|
||||
}
|
||||
mrb_exc_mesg_set(mrb, mrb_exc_ptr(self), str);
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
mrb_mruby_errno_gem_init(mrb_state *mrb)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user