void GENERATED_TMP_mrb_mruby_print_gem_init(mrb_state *mrb) { int ai = mrb_gc_arena_save(mrb); mrb_mruby_print_gem_init(mrb); mrb_load_irep(mrb, gem_mrblib_irep_mruby_print); if (mrb->exc) { mrb_p(mrb, mrb_obj_value(mrb->exc)); exit(EXIT_FAILURE); } mrb_gc_arena_restore(mrb, ai); }
int main(void) { mrb_state *mrb = mrb_open(); mrb_load_irep(mrb, simplest_mrb); mrb_close(mrb); return 0; }
void mrb_init_mrbtest(mrb_state *mrb) { mrb_load_irep(mrb, mrbtest_irep); #ifndef DISABLE_GEMS mrbgemtest_init(mrb); #endif if (mrb->exc) { mrb_p(mrb, mrb_obj_value(mrb->exc)); exit(EXIT_FAILURE); } }
bool init_mruby() { Serial2.println("init_mruby enter"); g_mrb = mrb_open_allocf(myallocfCCM, NULL); // g_mrb = mrb_open_allocf(myallocf, NULL); Serial2.print("mrb_open done. total allocated : "); Serial2.println(total_size, DEC); mrb_load_irep(g_mrb, blinker); RClass *freeRTOSModule = mrb_define_module(g_mrb, "FreeRTOS"); mrb_define_module_function(g_mrb, freeRTOSModule, "sleep", mrb_freertos_sleep, ARGS_REQ(1)); Serial2.println("mruby initialized"); return true; }
int main(void) { mrb_state *mrb = mrb_open(); struct RClass *foo_module = mrb_define_module(mrb, "Foo"); struct RClass *foo_class = mrb_define_class_under(mrb, foo_module, "Bar", mrb->object_class); mrb_define_method(mrb, foo_class, "initialize", foo_bar_init, MRB_ARGS_REQ(1)); mrb_define_method(mrb, foo_class, "baz", foo_bar_baz, MRB_ARGS_REQ(1)); // To get the class use: mrb_class_get_under(mrb, foo_module, "Bar"); mrb_load_irep(mrb, class_under_module_mrb); mrb_close(mrb); return 0; }
//---------------------------------------------------------- void ScriptEngine::setup() { string dataRoot = dirname(mScriptPath); // set texture & script root ofSetDataPathRoot(dataRoot); // open mrb open(); // load builtin library mrb_load_irep(mMrb, BuiltIn); mConsoleModule = mrb_class_get(mMrb, "Console"); // bind Bind::All(mMrb); // load user script load(); // call setup funcallIf("setup"); }
int main(int argc, char **argv) { mrb_state *mrb = mrb_open(); int n = -1; int i; struct _args args; mrb_value ARGV; if (mrb == NULL) { fprintf(stderr, "Invalid mrb_state, exiting mruby"); return EXIT_FAILURE; } n = parse_args(mrb, argc, argv, &args); if (n < 0 || (args.cmdline == NULL && args.rfp == NULL)) { cleanup(mrb, &args); usage(argv[0]); return n; } ARGV = mrb_ary_new_capa(mrb, args.argc); for (i = 0; i < args.argc; i++) { mrb_ary_push(mrb, ARGV, mrb_str_new(mrb, args.argv[i], strlen(args.argv[i]))); } mrb_define_global_const(mrb, "ARGV", ARGV); if (args.mrbfile) { n = mrb_load_irep(mrb, args.rfp); if (n >= 0) { if (!args.check_syntax) { mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); if (mrb->exc) { p(mrb, mrb_obj_value(mrb->exc)); } } } } else { mrbc_context *c = mrbc_context_new(mrb); mrb_value v; if (args.verbose) c->dump_result = 1; if (args.check_syntax) c->no_exec = 1; if (args.rfp) { mrbc_filename(mrb, c, args.cmdline ? args.cmdline : "-"); v = mrb_load_file_cxt(mrb, args.rfp, c); } else { mrbc_filename(mrb, c, "-e"); v = mrb_load_string_cxt(mrb, args.cmdline, c); } mrbc_context_free(mrb, c); if (mrb->exc) { if (!mrb_undef_p(v)) { p(mrb, mrb_obj_value(mrb->exc)); } n = -1; } else if (args.check_syntax) { printf("Syntax OK\n"); } } cleanup(mrb, &args); return n == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
void mrb_init_mrblib(mrb_state *mrb) { mrb_load_irep(mrb, mrblib_irep); }
void init_uefi_mrblib(mrb_state *mrb) { mrb_load_irep(mrb, uefi_mrblib_irep); }
int webruby_internal_run_bytecode(mrb_state* mrb, const uint8_t *bc, int print_level) { return check_and_print_errors(mrb, mrb_load_irep(mrb, bc), print_level); }
int main(int argc, char **argv) { mrb_state *mrb = mrb_open(); int n = -1; int i; struct _args args; struct mrb_parser_state *p; n = parse_args(mrb, argc, argv, &args); if (n < 0 || (args.cmdline == NULL && args.rfp == NULL)) { cleanup(mrb, &args); usage(argv[0]); return n; } if (args.mrbfile) { n = mrb_load_irep(mrb, args.rfp); } else { if (args.cmdline) { p = mrb_parse_string(mrb, (char*)args.cmdline); } else { p = mrb_parser_new(mrb); if (p) { mrb_parser_filename(p, argv[1]); p->f = args.rfp; mrb_parser_parse(p); } } if (!p || !p->tree || p->nerr) { cleanup(mrb, &args); return -1; } if (args.verbose) parser_dump(mrb, p->tree, 0); n = mrb_generate_code(mrb, p->tree); mrb_pool_close(p->pool); } if (n >= 0) { mrb_value ARGV = mrb_ary_new(mrb); for (i = 0; i < args.argc; i++) { mrb_ary_push(mrb, ARGV, mrb_str_new(mrb, args.argv[i], strlen(args.argv[i]))); } mrb_define_global_const(mrb, "ARGV", ARGV); if (args.verbose) codedump_all(mrb, n); if (!args.check_syntax) { mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); if (mrb->exc) { mrb_p(mrb, mrb_obj_value(mrb->exc)); } } } cleanup(mrb, &args); return n > 0 ? 0 : 1; }