Skip to content
Browse files

add mrb_mod_cv_defined and mrb_cv_defined

  • Loading branch information...
1 parent b42d17a commit 9599381ae334ac474d40dc617407d2b05f17a328 @skandhas skandhas committed Dec 23, 2012
Showing with 22 additions and 0 deletions.
  1. +2 −0 include/mruby/variable.h
  2. +20 −0 src/variable.c
View
2 include/mruby/variable.h
@@ -59,6 +59,8 @@ mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym);
mrb_value mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym);
void mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v);
void mrb_cv_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v);
+int mrb_mod_cv_defined(mrb_state *mrb, struct RClass * c, mrb_sym sym);
+int mrb_cv_defined(mrb_state *mrb, mrb_value mod, mrb_sym sym);
/* GC functions */
void mrb_gc_mark_gv(mrb_state*);
View
20 src/variable.c
@@ -730,6 +730,26 @@ mrb_cv_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v)
mrb_mod_cv_set(mrb, mrb_class_ptr(mod), sym, v);
}
+int
+mrb_mod_cv_defined(mrb_state *mrb, struct RClass * c, mrb_sym sym)
+{
+ while (c) {
+ if (c->iv) {
+ iv_tbl *t = c->iv;
+ if (iv_get(mrb, t, sym, NULL)) return TRUE;
+ }
+ c = c->super;
+ }
+
+ return FALSE;
+}
+
+int
+mrb_cv_defined(mrb_state *mrb, mrb_value mod, mrb_sym sym)
+{
+ return mrb_mod_cv_defined(mrb, mrb_class_ptr(mod), sym);
+}
+
mrb_value
mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym)
{

0 comments on commit 9599381

Please sign in to comment.
Something went wrong with that request. Please try again.