Skip to content
Browse files

add mrb_mod_cv_set, mrb_cv_set

  • Loading branch information...
1 parent e48ed9c commit 824bacbee4beea7755e815a4aa733cb05f95268b @skandhas committed Dec 21, 2012
Showing with 30 additions and 0 deletions.
  1. +2 −0 include/mruby/variable.h
  2. +28 −0 src/variable.c
View
2 include/mruby/variable.h
@@ -57,6 +57,8 @@ mrb_sym mrb_class_sym(mrb_state *mrb, struct RClass *c, struct RClass *outer);
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_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);
/* GC functions */
void mrb_gc_mark_gv(mrb_state*);
View
28 src/variable.c
@@ -695,6 +695,34 @@ mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
return mrb_mod_cv_get(mrb, mrb_class_ptr(mod), sym);
}
+void
+mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v)
+{
+ while (c) {
+ if (c->iv) {
+ iv_tbl *t = c->iv;
+
+ if (iv_get(mrb, t, sym, NULL)) {
+ iv_put(mrb, t, sym, v);
+ return;
+ }
+ }
+ c = c->super;
+ }
+
+ if (!c->iv) {
+ c->iv = iv_new(mrb);
+ }
+
+ iv_put(mrb, c->iv, sym, v);
+}
+
+void
+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);
+}
+
mrb_value
mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym)
{

0 comments on commit 824bacb

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