diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 0bd1d96..ea0d5f2 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -398,17 +398,47 @@ static void showExc(VALUE exc) showMsg(StringValueCStr(ms)); } +/* Appends if exists, sets if not */ +static void globalAryAppend(const char *globalName, VALUE ary) +{ + VALUE existing = rb_gv_get(globalName); + + if (NIL_P(existing)) + rb_gv_set(globalName, ary); + else + rb_ary_concat(existing, ary); +} + static void mriBindingExecute() { ruby_setup(); rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding())); + Config &conf = shState->rtData().config; + + if (!conf.rubyLoadpaths.empty()) + { + /* Setup custom load paths */ + VALUE lpaths = rb_ary_new_capa(conf.rubyLoadpaths.size()); + + for (size_t i = 0; i < conf.rubyLoadpaths.size(); ++i) + { + std::string &path = conf.rubyLoadpaths[i]; + + VALUE pathv = rb_str_new(path.c_str(), path.size()); + rb_ary_push(lpaths, pathv); + } + + globalAryAppend("$", lpaths); + globalAryAppend("LOAD_PATH", lpaths); + } + RbData rbData; shState->setBindingData(&rbData); mriBindingInit(); - std::string &customScript = shState->rtData().config.customScript; + std::string &customScript = conf.customScript; if (!customScript.empty()) runCustomScript(customScript); else diff --git a/mkxp.conf.sample b/mkxp.conf.sample index a99865a..574369e 100644 --- a/mkxp.conf.sample +++ b/mkxp.conf.sample @@ -135,3 +135,15 @@ # # fontSub=Arial>Open Sans # fontSub=Times New Roman>Liberation Serif + + +# Because mkxp is usually distributed as a stand alone +# build, no predefined load paths are initialized +# ($:, $LOAD_PATH) in the MRI backend. With this option, +# they can be specified manually (eg. when using a system +# libruby.so). It is however recommended to statically +# link all required gems into libruby.so. +# (default: none) +# +# rubyLoadpath=/usr/lib64/ruby/ +# rubyLoadpath=/usr/local/share/ruby/site_ruby diff --git a/src/config.cpp b/src/config.cpp index 6a187ad..99f2e80 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -84,6 +84,7 @@ void Config::read(int argc, char *argv[]) PO_DESC_ALL ("RTP", po::value()->composing()) ("fontSub", po::value()->composing()) + ("rubyLoadpath", po::value()->composing()) ; po::variables_map vm; @@ -118,6 +119,8 @@ void Config::read(int argc, char *argv[]) GUARD_ALL( fontSubs = vm["fontSub"].as(); ); + GUARD_ALL( rubyLoadpaths = vm["rubyLoadpath"].as(); ) + #undef PO_DESC #undef PO_DESC_ALL } diff --git a/src/config.h b/src/config.h index b2e3218..ade57b1 100644 --- a/src/config.h +++ b/src/config.h @@ -57,6 +57,8 @@ struct Config std::vector fontSubs; + std::vector rubyLoadpaths; + /* Game INI contents */ struct { std::string scripts;