mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-03-28 14:56:22 +01:00
Merge pull request #158 from Nathan-MV/plugin-script
Some checks failed
Automatic Build / Ubuntu 22.04 x86_64 (push) Failing after 5s
Automatic Build / Ubuntu 22.04 arm64 (push) Failing after 3s
Automatic Build / Ubuntu 22.04 armv6 (push) Failing after 3s
Automatic Build / Ubuntu 22.04 armv7 (push) Failing after 2s
Automatic Build / Ubuntu 22.04 power8le (push) Failing after 2s
Automatic Build / Ubuntu 22.04 armv7-neon (push) Failing after 2s
Automatic Build / Ubuntu 22.04 power9le (push) Failing after 2s
Automatic Build / Ubuntu 22.04 riscv64 (push) Failing after 2s
Automatic Build / Ubuntu 22.04 s390x (push) Failing after 2s
Automatic Build / Windows (push) Has been cancelled
Automatic Build / macOS (push) Has been cancelled
Some checks failed
Automatic Build / Ubuntu 22.04 x86_64 (push) Failing after 5s
Automatic Build / Ubuntu 22.04 arm64 (push) Failing after 3s
Automatic Build / Ubuntu 22.04 armv6 (push) Failing after 3s
Automatic Build / Ubuntu 22.04 armv7 (push) Failing after 2s
Automatic Build / Ubuntu 22.04 power8le (push) Failing after 2s
Automatic Build / Ubuntu 22.04 armv7-neon (push) Failing after 2s
Automatic Build / Ubuntu 22.04 power9le (push) Failing after 2s
Automatic Build / Ubuntu 22.04 riscv64 (push) Failing after 2s
Automatic Build / Ubuntu 22.04 s390x (push) Failing after 2s
Automatic Build / Windows (push) Has been cancelled
Automatic Build / macOS (push) Has been cancelled
Postload Scripts
This commit is contained in:
commit
711f9a4553
4 changed files with 58 additions and 36 deletions
|
@ -811,9 +811,54 @@ static bool processReset(bool rubyExc) {
|
|||
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_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) {
|
||||
VALUE exc = Qnil;
|
||||
#if RAPI_FULL < 270
|
||||
|
@ -880,41 +925,6 @@ RB_METHOD(_kernelCaller) {
|
|||
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);
|
||||
|
||||
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
|
||||
// (emulates windows case insensitivity)
|
||||
// (default: enabled)
|
||||
|
|
|
@ -187,6 +187,7 @@ void Config::read(int argc, char *argv[]) {
|
|||
{"pathCache", true},
|
||||
{"useScriptNames", true},
|
||||
{"preloadScript", json::array({})},
|
||||
{"postloadScript", json::array({})},
|
||||
{"RTP", json::array({})},
|
||||
{"patches", json::array({})},
|
||||
{"fontSub", json::array({})},
|
||||
|
@ -316,6 +317,7 @@ try { exp } catch (...) {}
|
|||
SET_OPT(dumpAtlas, boolean);
|
||||
|
||||
fillStringVec(opts["preloadScript"], preloadScripts);
|
||||
fillStringVec(opts["postloadScript"], postloadScripts);
|
||||
fillStringVec(opts["RTP"], rtps);
|
||||
fillStringVec(opts["patches"], patches);
|
||||
fillStringVec(opts["fontSub"], fontSubs);
|
||||
|
|
|
@ -113,6 +113,7 @@ struct Config {
|
|||
|
||||
std::vector<std::string> launchArgs;
|
||||
std::vector<std::string> preloadScripts;
|
||||
std::vector<std::string> postloadScripts;
|
||||
std::vector<std::string> rtps;
|
||||
std::vector<std::string> patches;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue