diff options
| author | takkaw <[email protected]> | 2019-09-09 22:32:10 +0900 |
|---|---|---|
| committer | takkaw <[email protected]> | 2019-09-09 22:32:10 +0900 |
| commit | e28451585db8828e18b4638b1513352efb98f86c (patch) | |
| tree | 5430fe6291d86d218aeab1ca01579cc799d07de1 | |
| parent | 715afd6fdb7c5c080fa8e3c2060394cf84f530ac (diff) | |
| download | mruby-e28451585db8828e18b4638b1513352efb98f86c.tar.gz mruby-e28451585db8828e18b4638b1513352efb98f86c.zip | |
add special local variable _ in mirb
| -rw-r--r-- | mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index 17b2ca16c..fc85cdac0 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -406,6 +406,26 @@ ctrl_c_handler(int signo) } #endif +#ifdef ENABLE_MIRB_UNDERSCORE +void decl_lv_underscore(mrb_state *mrb, mrbc_context *cxt) +{ + struct RProc *proc; + struct mrb_parser_state *parser; + + parser = mrb_parse_string(mrb, "_=nil", cxt); + if (parser == NULL) { + fputs("create parser state error\n", stderr); + mrb_close(mrb); + exit(EXIT_FAILURE); + } + + proc = mrb_generate_code(mrb, parser); + mrb_vm_run(mrb, proc, mrb_top_self(mrb), 0); + + mrb_parser_free(parser); +} +#endif + int main(int argc, char **argv) { @@ -471,6 +491,10 @@ main(int argc, char **argv) cxt = mrbc_context_new(mrb); +#ifdef ENABLE_MIRB_UNDERSCORE + decl_lv_underscore(mrb, cxt); +#endif + /* Load libraries */ for (i = 0; i < args.libc; i++) { FILE *lfp = fopen(args.libv[i], "r"); @@ -643,6 +667,9 @@ main(int argc, char **argv) result = mrb_any_to_s(mrb, result); } p(mrb, result, 1); +#ifdef ENABLE_MIRB_UNDERSCORE + *(mrb->c->stack + 1) = result; +#endif } } ruby_code[0] = '\0'; |
