summaryrefslogtreecommitdiffhomepage
path: root/src/variable.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2012-12-21 07:19:25 -0800
committerYukihiro "Matz" Matsumoto <[email protected]>2012-12-21 07:19:25 -0800
commit429359819a9a3155984c134f62976a42d314244c (patch)
treef542feb09ad9a800ed1c89da2551760bef9ae8be /src/variable.c
parent46a3bd76e5baa787933cb61acbb7b5cae851fdcf (diff)
parentf612f32aef65e5c1f16ebf50fcf9221309251d25 (diff)
downloadmruby-429359819a9a3155984c134f62976a42d314244c.tar.gz
mruby-429359819a9a3155984c134f62976a42d314244c.zip
Merge pull request #662 from skandhas/pr-add-Module-class_variable_set
Add Module#class_variable_set for mruby
Diffstat (limited to 'src/variable.c')
-rw-r--r--src/variable.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/variable.c b/src/variable.c
index 147373bd4..7743c6309 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -695,6 +695,36 @@ 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)
+{
+ struct RClass * cls = c;
+
+ 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 (!cls->iv) {
+ cls->iv = iv_new(mrb);
+ }
+
+ iv_put(mrb, cls->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)
{