static void initrb_repl() { char prompt[128]; int idx = 0; while (true) { VALUE arr, result, inspected; char *line; snprintf(prompt, sizeof(prompt), "initrb:%03d> ", ++idx); line = readline(prompt); if (!line) { break; } else { // Evaluate the code arr = rb_ary_new3(4, rb_str_buf_new_cstr(line), rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING")), rb_str_buf_new_cstr("(initrb)"), INT2FIX(idx)); if ((result = initrb_interpreter_protect(initrb_interpreter_eval, arr)) == Qundef) { continue; } else if ((inspected = initrb_interpreter_protect(initrb_interpreter_inspect, result)) == Qundef) { continue; } // Print the result initrb_interpreter_print_result(inspected); // Free the line free(line); } } }
static void load_failed(VALUE fname) { VALUE mesg = rb_str_buf_new_cstr("cannot load such file -- "); rb_str_append(mesg, fname); /* should be ASCII compatible */ rb_exc_raise(rb_exc_new3(rb_eLoadError, mesg)); }
void rb_load_fail(VALUE path, const char *err) { VALUE mesg = rb_str_buf_new_cstr(err); rb_str_cat2(mesg, " -- "); rb_str_append(mesg, path); /* should be ASCII compatible */ raise_loaderror(path, mesg); }
static int initrb_boot(int argc, char **argv) { int ret = 0; while (true) { ret = initrb_interpreter_protect(initrb_interpreter_begin, rb_str_buf_new_cstr(argc > 1 ? argv[argc - 1] : INITRB_SCRIPT)); if (ret != Qundef) { // Exit gracefully break; } else { // Internal error, drop into the REPL initrb_repl(); break; } } return ret; }