#!/usr/bin/env ruby require 'tempfile' require 'mruby_tools' # args like: file1.rb file2.rb -o outfile # possibly: file1.rb -o outfile file2.rb -c generated.c opts = MRubyTools.args(ARGV) outfile = opts.fetch(:outfile) c_code = <<'EOF' #include #include #include #include void check_exc(mrb_state *mrb, char *filename) { if (mrb->exc) { mrb_value exc = mrb_obj_value(mrb->exc); mrb_value exc_msg = mrb_funcall(mrb, exc, "to_s", 0); fprintf(stderr, "ERROR in %s - %s: %s\n", filename, mrb_obj_classname(mrb, exc), mrb_str_to_cstr(mrb, exc_msg)); /* mrb_print_backtrace(mrb); # empty */ exit(1); } } int main(void) { mrb_state *mrb = mrb_open(); if (!mrb) { printf("mrb problem"); exit(1); } EOF c_code += opts.fetch(:rb_files).map { |rbf| "\n" + MRubyTools.rb2c(rbf) + "\n\n" }.join c_code += <