embed a Ruby; load runtime/main.rb

This commit is contained in:
Josh Holtrop 2014-07-12 10:09:24 -04:00
parent a717ed4a38
commit f0db52e3d7
3 changed files with 38 additions and 7 deletions

View File

@ -14,6 +14,7 @@ base_env = Rscons::Environment.new do |env|
env["CXXFLAGS"] << "-std=gnu++11"
env.parse_flags!("!sdl2-config --cflags --libs")
env.parse_flags!("!freetype-config --cflags --libs")
env.parse_flags!("!pkg-config --cflags --libs ruby-1.9")
env["LIBS"] += ["dl"]
if RUBY_PLATFORM =~ /mingw/
env["LIBS"] += ["opengl32"]

1
runtime/main.rb Normal file
View File

@ -0,0 +1 @@
puts "hi from main.rb"

View File

@ -1,15 +1,44 @@
#include <iostream>
#include "GUI.h"
#include "Core.h"
#include "ruby.h"
using namespace std;
RUBY_GLOBAL_SETUP
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)
{
VALUE e = rb_errinfo();
VALUE s = rb_funcall(e, rb_intern("message"), 0);
fprintf(stderr, "%s\n", StringValueCStr(s));
rb_set_errinfo(Qnil);
rv = 1;
}
return rv;
}
int main(int argc, char *argv[])
{
jes::Core::instance.init(argv[0]);
jes::GUIRef gui = new jes::GUI();
if (!gui->load())
return 2;
return gui->run();
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]);
rv = bootstrap();
ruby_finalize();
}
return rv;
}