jes-ruby/src/main.cc

51 lines
1.0 KiB
C++

#include <iostream>
#include "GUI.h"
#include "ruby.h"
using namespace std;
RUBY_GLOBAL_SETUP
static void handle_bootstrap_error()
{
VALUE e = rb_errinfo();
VALUE s = rb_funcall(e, rb_intern("message"), 0);
fprintf(stderr, "%s\n", StringValueCStr(s));
rb_set_errinfo(Qnil);
}
static int bootstrap()
{
int rv = 0;
int err_state = 0;
rb_eval_string_protect(
"load File.expand_path('../../runtime/main.rb', $0)",
&err_state);
if (err_state != 0)
{
handle_bootstrap_error();
rv = 1;
}
return rv;
}
int main(int argc, char *argv[])
{
int rv = 0;
int ruby_argc = 1;
char prog_name[] = "main";
char * ruby_argv[] = {&prog_name[0]};
char ** ruby_argv_p = &ruby_argv[0];
ruby_sysinit(&ruby_argc, &ruby_argv_p);
{
RUBY_INIT_STACK;
ruby_init();
ruby_init_loadpath();
ruby_script(argv[0]);
ruby_set_argv(argc, argv);
rv = bootstrap();
ruby_finalize();
}
return rv;
}