I am embedding ruby version 2.1.2 into a wxWidgets application, compiling on - and targeting - Windows. Linking to msvcrt-ruby210.dll and calling
ruby_sysinit(&argc, &argv);
RUBY_INIT_STACK;
ruby_init();
ruby_init_loadpath();
is enough to get me running with the basic VM and built-in classes. However, I am also packaging the standard library with my application, as I intend use facilities like FileUtils and Resolv from my application. I can require
and use some of the libraries just fine, yet when I require 'resolv'
I get an error reporting unitialized constant Encoding::UTF_16LE
. After some googling and digging around in ruby.c, I've found I can fix this with the following initialization code...
ruby_sysinit(&argc, &argv);
RUBY_INIT_STACK;
ruby_init();
ruby_init_loadpath();
rb_enc_find_index("encdb");
Which clears the previous error, but leaves me with code converter not found (UTF-8 to UTF-16LE)
. This is fixed by adding an additional line rb_eval_string("require 'enc/trans/transdb'");
, but, it is not my desire to replicate, piece by piece, the initialization code performed by ruby's ruby_options
function, so I tried to use it directly, as in ruby's own main
function...
int my_argc = 2;
char* arg1 = "myapp.exe";
char* arg2 = "scripts/bootstrap.rb";
char** my_argv = new char*[2]{arg1, arg2};
ruby_sysinit(&my_argc, &my_argv);
RUBY_INIT_STACK;
ruby_init();
ruby_run_node(ruby_options(my_argc, my_argv));
This, however, is only effective if I run my application with myapp.exe scripts/bootstrap.rb
. It seems that ruby is ignoring my parameters to ruby_options
and using the system supplied values of argc & argv (Apparently this has been the case for some time on Windows). This is bothersome, as I would like my application to run with a simple double-click of the executable, and not require users to supply command line arguments indicating the location of the "bootstrap" script.
So, is there a convenient API or some incantation I can use to initialize ruby in this case without requiring the command line parameters?
Note that if at all possible, I would like to avoid having to package my application as a ruby extension.