diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-12-20 07:35:34 -0800 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-12-20 07:35:34 -0800 |
| commit | e48ed9c9649340544156dba57e3a6f29f536066b (patch) | |
| tree | 6d4e2ebcc3332897df0d7abc1a2bca9f8516d566 /src/variable.c | |
| parent | 3c28241bd76466bafec5555028283e3fc6f2799a (diff) | |
| parent | e6a47323b8d67fdf85f095c30b2d66a00d2d2ca5 (diff) | |
| download | mruby-e48ed9c9649340544156dba57e3a6f29f536066b.tar.gz mruby-e48ed9c9649340544156dba57e3a6f29f536066b.zip | |
Merge pull request #655 from skandhas/pr-add-Module_class_variable_get
Add Module#class_variable_get for mruby
Diffstat (limited to 'src/variable.c')
| -rw-r--r-- | src/variable.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/variable.c b/src/variable.c index 992663408..147373bd4 100644 --- a/src/variable.c +++ b/src/variable.c @@ -673,26 +673,38 @@ mrb_mod_class_variables(mrb_state *mrb, mrb_value mod) return ary; } - mrb_value -mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym) +mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym) { - struct RClass *c = mrb->ci->proc->target_class; - - if (!c) c = mrb->ci->target_class; while (c) { if (c->iv) { iv_tbl *t = c->iv; mrb_value v; if (iv_get(mrb, t, sym, &v)) - return v; + return v; } c = c->super; } return mrb_nil_value(); } +mrb_value +mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym) +{ + return mrb_mod_cv_get(mrb, mrb_class_ptr(mod), sym); +} + +mrb_value +mrb_vm_cv_get(mrb_state *mrb, mrb_sym sym) +{ + struct RClass *c = mrb->ci->proc->target_class; + + if (!c) c = mrb->ci->target_class; + + return mrb_mod_cv_get(mrb, c, sym); +} + void mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v) { |
