embed a Ruby; load runtime/main.rb
This commit is contained in:
parent
a717ed4a38
commit
f0db52e3d7
@ -14,6 +14,7 @@ base_env = Rscons::Environment.new do |env|
|
|||||||
env["CXXFLAGS"] << "-std=gnu++11"
|
env["CXXFLAGS"] << "-std=gnu++11"
|
||||||
env.parse_flags!("!sdl2-config --cflags --libs")
|
env.parse_flags!("!sdl2-config --cflags --libs")
|
||||||
env.parse_flags!("!freetype-config --cflags --libs")
|
env.parse_flags!("!freetype-config --cflags --libs")
|
||||||
|
env.parse_flags!("!pkg-config --cflags --libs ruby-1.9")
|
||||||
env["LIBS"] += ["dl"]
|
env["LIBS"] += ["dl"]
|
||||||
if RUBY_PLATFORM =~ /mingw/
|
if RUBY_PLATFORM =~ /mingw/
|
||||||
env["LIBS"] += ["opengl32"]
|
env["LIBS"] += ["opengl32"]
|
||||||
|
1
runtime/main.rb
Normal file
1
runtime/main.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
puts "hi from main.rb"
|
43
src/main.cc
43
src/main.cc
@ -1,15 +1,44 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
#include "ruby.h"
|
||||||
#include "Core.h"
|
|
||||||
|
|
||||||
using namespace std;
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
jes::Core::instance.init(argv[0]);
|
int rv = 0;
|
||||||
jes::GUIRef gui = new jes::GUI();
|
int ruby_argc = 1;
|
||||||
if (!gui->load())
|
char prog_name[] = "main";
|
||||||
return 2;
|
char * ruby_argv[] = {&prog_name[0]};
|
||||||
return gui->run();
|
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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user