Add support for passing commandline arguments set in mkxp.json to the Ruby environment.

This commit is contained in:
Aeodyn 2021-01-08 19:48:41 -05:00
parent f25acdd7e9
commit 63b92d3815
4 changed files with 23 additions and 10 deletions

View file

@ -780,6 +780,8 @@ static void showExc(VALUE exc, const BacktraceData &btData) {
}
static void mriBindingExecute() {
Config &conf = shState->rtData().config;
#if RAPI_MAJOR >= 2
/* Normally only a ruby executable would do a sysinit,
* but not doing it will lead to crashes due to closed
@ -791,16 +793,19 @@ static void mriBindingExecute() {
RUBY_INIT_STACK;
ruby_init();
rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
std::vector<const char*> rubyArgsC{""};
for(const auto& string : conf.rubyArgs)
rubyArgsC.push_back(string.c_str());
rubyArgsC.push_back("-e ");
void *node = ruby_process_options(rubyArgsC.size(), const_cast<char**>(rubyArgsC.data()));
int state;
bool valid = ruby_executable_node(node, &state);
state = ruby_exec_node(node);
#else
ruby_init();
rb_eval_string("$KCODE='U'");
#ifdef MKXPZ_JIT
const char *rubyOpts[] = {"--jit-verbose=1"};
void *node = ruby_process_options(1, const_cast<char**>(rubyOpts);
int state;
bool valid = ruby_executable_node(node, &state);
state = ruby_exec_node(node);
#endif
#endif
#if defined(MKXPZ_ESSENTIALS_DEBUG) && !defined(__WIN32__)
@ -809,8 +814,6 @@ static void mriBindingExecute() {
setenv("TEMP", tmpdir, false);
#endif
Config &conf = shState->rtData().config;
VALUE lpaths = rb_gv_get(":");
if (!conf.rubyLoadpaths.empty()) {
/* Setup custom load paths */

View file

@ -284,6 +284,12 @@
// "rubyLoadpath": ["/usr/lib64/ruby/",
// "/usr/local/share/ruby/site_ruby"],
// Commandline arguments to pass to Ruby, such as to enable JIT.
// Only supported for Ruby 2.
// (default: none)
//
// "rubyArg": ["--jit-verbose=1"],
// SoundFont to use for midi playback (via fluidsynth)
// (default: none)

View file

@ -90,7 +90,8 @@ void Config::read(int argc, char *argv[]) {
{"preloadScript", json::array({})},
{"RTP", json::array({})},
{"fontSub", json::array({})},
{"rubyLoadpath", json::array({})}
{"rubyLoadpath", json::array({})},
{"rubyArg", json::array({})}
}).as_object();
#define GUARD(exp) \
@ -177,6 +178,7 @@ try { exp } catch (...) {}
fillStringVec(opts["RTP"], rtps);
fillStringVec(opts["fontSub"], fontSubs);
fillStringVec(opts["rubyLoadpath"], rubyLoadpaths);
fillStringVec(opts["rubyArg"], rubyArgs);
rgssVersion = clamp(rgssVersion, 0, 3);
SE.sourceCount = clamp(SE.sourceCount, 1, 64);

View file

@ -86,6 +86,8 @@ struct Config {
std::vector<std::string> rubyLoadpaths;
std::vector<std::string> rubyArgs;
/* Editor flags */
struct {
bool debug;