MRI-Binding: Allow manually specifying load paths in config

This commit is contained in:
Jonas Kulla 2014-07-24 23:11:12 +02:00
parent 393a283d99
commit ec16210f8a
4 changed files with 48 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -84,6 +84,7 @@ void Config::read(int argc, char *argv[])
PO_DESC_ALL
("RTP", po::value<StringVec>()->composing())
("fontSub", po::value<StringVec>()->composing())
("rubyLoadpath", po::value<StringVec>()->composing())
;
po::variables_map vm;
@ -118,6 +119,8 @@ void Config::read(int argc, char *argv[])
GUARD_ALL( fontSubs = vm["fontSub"].as<StringVec>(); );
GUARD_ALL( rubyLoadpaths = vm["rubyLoadpath"].as<StringVec>(); )
#undef PO_DESC
#undef PO_DESC_ALL
}

View File

@ -57,6 +57,8 @@ struct Config
std::vector<std::string> fontSubs;
std::vector<std::string> rubyLoadpaths;
/* Game INI contents */
struct {
std::string scripts;