diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-05-14 17:38:27 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-05-14 17:38:27 +0900 |
| commit | 27df1a84bc5310bcd32d90b7157a3ad46ef3ac76 (patch) | |
| tree | 8e7a3c7c64ac392e6dbbb6ef587e7abffdc8cd18 /mrbgems/mruby-proc-ext/src/proc.c | |
| parent | 232ec102d6264cd5e79cf4e900a5cc946ca76a67 (diff) | |
| download | mruby-27df1a84bc5310bcd32d90b7157a3ad46ef3ac76.tar.gz mruby-27df1a84bc5310bcd32d90b7157a3ad46ef3ac76.zip | |
Kernel.local_variables to list UPVAR as well
Diffstat (limited to 'mrbgems/mruby-proc-ext/src/proc.c')
| -rw-r--r-- | mrbgems/mruby-proc-ext/src/proc.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/mrbgems/mruby-proc-ext/src/proc.c b/mrbgems/mruby-proc-ext/src/proc.c index 341001f05..f0e677045 100644 --- a/mrbgems/mruby-proc-ext/src/proc.c +++ b/mrbgems/mruby-proc-ext/src/proc.c @@ -137,10 +137,28 @@ mrb_local_variables(mrb_state *mrb, mrb_value self) } irep = proc->body.irep; + if (!irep->lv) { + return mrb_ary_new(mrb); + } ret = mrb_ary_new_capa(mrb, irep->nlocals - 1); - for (i = 0; i < (irep->nlocals - 1); ++i) { + for (i = 0; i + 1 < irep->nlocals; ++i) { mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name)); } + if (proc->env) { + struct REnv *e = proc->env; + + while (e) { + if (!MRB_PROC_CFUNC_P(mrb->c->cibase[e->cioff].proc)) { + irep = mrb->c->cibase[e->cioff].proc->body.irep; + if (irep->lv) { + for (i = 0; i + 1 < irep->nlocals; ++i) { + mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name)); + } + } + } + e = (struct REnv*)e->c; + } + } return ret; } |
