mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-29 19:44:49 +02:00
postload scripts
This commit is contained in:
parent
a5d574984c
commit
17f9ec9c19
4 changed files with 58 additions and 36 deletions
|
@ -779,9 +779,54 @@ static bool processReset(bool rubyExc) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if RAPI_FULL > 187
|
||||||
|
static VALUE newStringUTF8(const char *string, long length) {
|
||||||
|
return rb_enc_str_new(string, length, rb_utf8_encoding());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define newStringUTF8 rb_str_new
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct evalArg {
|
||||||
|
VALUE string;
|
||||||
|
VALUE filename;
|
||||||
|
};
|
||||||
|
|
||||||
|
static VALUE evalHelper(evalArg *arg) {
|
||||||
|
VALUE argv[] = {arg->string, Qnil, arg->filename};
|
||||||
|
return rb_funcall2(Qnil, rb_intern("eval"), ARRAY_SIZE(argv), argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE evalString(VALUE string, VALUE filename, int *state) {
|
||||||
|
evalArg arg = {string, filename};
|
||||||
|
return rb_protect((VALUE(*)(VALUE))evalHelper, (VALUE)&arg, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void runCustomScript(const std::string &filename) {
|
||||||
|
std::string scriptData;
|
||||||
|
|
||||||
|
if (!readFileSDL(filename.c_str(), scriptData)) {
|
||||||
|
showMsg(std::string("Unable to open '") + filename + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
evalString(newStringUTF8(scriptData.c_str(), scriptData.size()),
|
||||||
|
newStringUTF8(filename.c_str(), filename.size()), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
RB_METHOD_GUARD(mriRgssMain) {
|
RB_METHOD_GUARD(mriRgssMain) {
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
/* Execute postload scripts */
|
||||||
|
const Config &conf = shState->rtData().config;
|
||||||
|
for (std::vector<std::string>::const_iterator i = conf.postloadScripts.begin();
|
||||||
|
i != conf.postloadScripts.end(); ++i)
|
||||||
|
{
|
||||||
|
if (shState->rtData().rqTerm)
|
||||||
|
break;
|
||||||
|
runCustomScript(*i);
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
VALUE exc = Qnil;
|
VALUE exc = Qnil;
|
||||||
#if RAPI_FULL < 270
|
#if RAPI_FULL < 270
|
||||||
|
@ -848,41 +893,6 @@ RB_METHOD(_kernelCaller) {
|
||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if RAPI_FULL > 187
|
|
||||||
static VALUE newStringUTF8(const char *string, long length) {
|
|
||||||
return rb_enc_str_new(string, length, rb_utf8_encoding());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define newStringUTF8 rb_str_new
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct evalArg {
|
|
||||||
VALUE string;
|
|
||||||
VALUE filename;
|
|
||||||
};
|
|
||||||
|
|
||||||
static VALUE evalHelper(evalArg *arg) {
|
|
||||||
VALUE argv[] = {arg->string, Qnil, arg->filename};
|
|
||||||
return rb_funcall2(Qnil, rb_intern("eval"), ARRAY_SIZE(argv), argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE evalString(VALUE string, VALUE filename, int *state) {
|
|
||||||
evalArg arg = {string, filename};
|
|
||||||
return rb_protect((VALUE(*)(VALUE))evalHelper, (VALUE)&arg, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void runCustomScript(const std::string &filename) {
|
|
||||||
std::string scriptData;
|
|
||||||
|
|
||||||
if (!readFileSDL(filename.c_str(), scriptData)) {
|
|
||||||
showMsg(std::string("Unable to open '") + filename + "'");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
evalString(newStringUTF8(scriptData.c_str(), scriptData.size()),
|
|
||||||
newStringUTF8(filename.c_str(), filename.size()), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE kernelLoadDataInt(const char *filename, bool rubyExc, bool raw);
|
VALUE kernelLoadDataInt(const char *filename, bool rubyExc, bool raw);
|
||||||
|
|
||||||
struct BacktraceData {
|
struct BacktraceData {
|
||||||
|
|
|
@ -368,6 +368,15 @@
|
||||||
// ],
|
// ],
|
||||||
|
|
||||||
|
|
||||||
|
// Define raw scripts to be executed before the
|
||||||
|
// rgss_main execution starts for RGSS 3.
|
||||||
|
// (default: none)
|
||||||
|
//
|
||||||
|
// "postloadScript": [
|
||||||
|
// "/path/to/script.rb",
|
||||||
|
// ],
|
||||||
|
|
||||||
|
|
||||||
// Index all accesible assets via their lower case path
|
// Index all accesible assets via their lower case path
|
||||||
// (emulates windows case insensitivity)
|
// (emulates windows case insensitivity)
|
||||||
// (default: enabled)
|
// (default: enabled)
|
||||||
|
|
|
@ -187,6 +187,7 @@ void Config::read(int argc, char *argv[]) {
|
||||||
{"pathCache", true},
|
{"pathCache", true},
|
||||||
{"useScriptNames", true},
|
{"useScriptNames", true},
|
||||||
{"preloadScript", json::array({})},
|
{"preloadScript", json::array({})},
|
||||||
|
{"postloadScript", json::array({})},
|
||||||
{"RTP", json::array({})},
|
{"RTP", json::array({})},
|
||||||
{"patches", json::array({})},
|
{"patches", json::array({})},
|
||||||
{"fontSub", json::array({})},
|
{"fontSub", json::array({})},
|
||||||
|
@ -316,6 +317,7 @@ try { exp } catch (...) {}
|
||||||
SET_OPT(dumpAtlas, boolean);
|
SET_OPT(dumpAtlas, boolean);
|
||||||
|
|
||||||
fillStringVec(opts["preloadScript"], preloadScripts);
|
fillStringVec(opts["preloadScript"], preloadScripts);
|
||||||
|
fillStringVec(opts["postloadScript"], postloadScripts);
|
||||||
fillStringVec(opts["RTP"], rtps);
|
fillStringVec(opts["RTP"], rtps);
|
||||||
fillStringVec(opts["patches"], patches);
|
fillStringVec(opts["patches"], patches);
|
||||||
fillStringVec(opts["fontSub"], fontSubs);
|
fillStringVec(opts["fontSub"], fontSubs);
|
||||||
|
|
|
@ -113,6 +113,7 @@ struct Config {
|
||||||
|
|
||||||
std::vector<std::string> launchArgs;
|
std::vector<std::string> launchArgs;
|
||||||
std::vector<std::string> preloadScripts;
|
std::vector<std::string> preloadScripts;
|
||||||
|
std::vector<std::string> postloadScripts;
|
||||||
std::vector<std::string> rtps;
|
std::vector<std::string> rtps;
|
||||||
std::vector<std::string> patches;
|
std::vector<std::string> patches;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue