Get local variable names from orphan block; ref
MODIFY
mrbgems/mruby-metaprog/src/metaprog.c
mrbgems/mruby-metaprog/src/metaprog.c
@@ -146,7 +146,7 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
while (proc) {
if (MRB_PROC_CFUNC_P(proc)) break;
irep = proc->body.irep;
- if (!irep->lv) break;
+ if (irep->lv) {
for (i = 0; i + 1 < irep->nlocals; ++i) {
if (irep->lv[i].name) {
mrb_sym sym = irep->lv[i].name;
@@ -160,10 +160,9 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
}
}
}
- if (!MRB_PROC_ENV_P(proc)) break;
+ }
+ if (MRB_PROC_SCOPE_P(proc)) break;
proc = proc->upper;
- //if (MRB_PROC_SCOPE_P(proc)) break;
- if (!proc->c) break;
}
return mrb_hash_keys(mrb, vars);

MODIFY
mrbgems/mruby-metaprog/test/metaprog.rb
mrbgems/mruby-metaprog/test/metaprog.rb
@@ -114,6 +114,15 @@ assert('Kernel.local_variables', '15.3.1.2.7') do
# Kernel#local_variables: 15.3.1.3.28
local_variables.sort
}.call(-1, -2)
+
+ a = Object.new
+ def a.hoge(vars, *, **)
+ Proc.new {
+ x, y = 1, 2
+ local_variables.sort
+ }
+ end
+ assert_equal([:vars, :x, :y]) { a.hoge(0).call }
end
assert('Kernel#define_singleton_method') do

Get local variable names from orphan block; ref #3710