diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-07-30 01:33:02 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-07-30 01:33:02 +0900 |
| commit | dbd36128ad652c743ecb9331f7c4b9ba4a9fb933 (patch) | |
| tree | 34db628105703cced8a2be676dfc98939bbdf9f8 | |
| parent | 961cd408a86580c4d428f56153da00fd46738e35 (diff) | |
| download | mruby-dbd36128ad652c743ecb9331f7c4b9ba4a9fb933.tar.gz mruby-dbd36128ad652c743ecb9331f7c4b9ba4a9fb933.zip | |
forget to re-initialize target_class for top-level eval; close #1418
| -rw-r--r-- | include/mruby/compile.h | 1 | ||||
| -rw-r--r-- | src/parse.y | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/include/mruby/compile.h b/include/mruby/compile.h index c1c646508..7c5884e58 100644 --- a/include/mruby/compile.h +++ b/include/mruby/compile.h @@ -23,6 +23,7 @@ typedef struct mrbc_context { short lineno; int (*partial_hook)(struct mrb_parser_state*); void *partial_data; + struct RClass *target_class; mrb_bool capture_errors:1; mrb_bool dump_result:1; mrb_bool no_exec:1; diff --git a/src/parse.y b/src/parse.y index 9a83d5cbd..168dca9f0 100644 --- a/src/parse.y +++ b/src/parse.y @@ -5207,9 +5207,13 @@ mrb_parse_string(mrb_state *mrb, const char *s, mrbc_context *c) return mrb_parse_nstring(mrb, s, strlen(s), c); } +struct RProc* mrb_proc_new_with_target(mrb_state *mrb, mrb_irep *irep, struct RClass *target); + static mrb_value load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c) { + struct RClass *target = mrb->object_class; + struct RProc *proc; int n; mrb_value v; @@ -5243,8 +5247,11 @@ load_exec(mrb_state *mrb, parser_state *p, mrbc_context *c) if (c) { if (c->dump_result) codedump_all(mrb, n); if (c->no_exec) return mrb_fixnum_value(n); + if (c->target_class) target = c->target_class; } - v = mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); + proc = mrb_proc_new(mrb, mrb->irep[n]); + proc->target_class = target; + v = mrb_run(mrb, proc, mrb_top_self(mrb)); if (mrb->exc) return mrb_nil_value(); return v; } |
