variable.c: a new function mrb_mod_const_at()

And mrb_mod_constants() use the new function now.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-04-12 16:27:42 +09:00
parent cda551ce25
commit 118e13d85c
2 changed files with 11 additions and 3 deletions
+3 -2
View File
@@ -176,11 +176,12 @@ size_t mrb_obj_iv_tbl_memsize(mrb_value);
mrb_value mrb_obj_iv_inspect(mrb_state*, struct RObject*);
void mrb_obj_iv_set_force(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v);
mrb_value mrb_mod_constants(mrb_state *mrb, mrb_value mod);
mrb_value mrb_mod_const_at(mrb_state *mrb, struct RClass *c, mrb_value ary);
mrb_value mrb_f_global_variables(mrb_state *mrb, mrb_value self);
mrb_value mrb_obj_instance_variables(mrb_state*, mrb_value);
mrb_value mrb_mod_class_variables(mrb_state*, mrb_value);
mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym);
mrb_bool mrb_mod_cv_defined(mrb_state *mrb, struct RClass * c, mrb_sym sym);
mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass *c, mrb_sym sym);
mrb_bool mrb_mod_cv_defined(mrb_state *mrb, struct RClass *c, mrb_sym sym);
mrb_bool mrb_ident_p(const char *s, mrb_int len);
mrb_value mrb_exc_const_get(mrb_state *mrb, mrb_sym sym);
+8 -1
View File
@@ -924,6 +924,13 @@ const_i(mrb_state *mrb, mrb_sym sym, mrb_value v, void *p)
return 0;
}
mrb_value
mrb_mod_const_at(mrb_state *mrb, struct RClass *c, mrb_value ary)
{
iv_foreach(mrb, class_iv_ptr(c), const_i, &ary);
return ary;
}
/* 15.2.2.4.24 */
/*
* call-seq:
@@ -941,7 +948,7 @@ mrb_mod_constants(mrb_state *mrb, mrb_value mod)
mrb_get_args(mrb, "|b", &inherit);
ary = mrb_ary_new(mrb);
while (c) {
iv_foreach(mrb, class_iv_ptr(c), const_i, &ary);
mrb_mod_const_at(mrb, c, ary);
if (!inherit) break;
c = c->super;
if (c == mrb->object_class) break;