mirror of https://github.com/mgba-emu/mgba.git
Add a `--script` option to load scripts automatically on startup
This commit is contained in:
parent
0815443aeb
commit
7cacae1262
|
@ -19,6 +19,9 @@
|
|||
static const mOption s_frontendOptions[] = {
|
||||
{ "ecard", true, '\0' },
|
||||
{ "mb", true, '\0' },
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
{ "script", true, '\0' },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
@ -153,7 +156,12 @@ ConfigController::ConfigController(QObject* parent)
|
|||
m_subparsers[1].usage = "Frontend options:\n"
|
||||
" --ecard FILE Scan an e-Reader card in the first loaded game\n"
|
||||
" Can be passed multiple times for multiple cards\n"
|
||||
" --mb FILE Boot a multiboot image with FILE inserted into the ROM slot";
|
||||
" --mb FILE Boot a multiboot image with FILE inserted into the ROM slot"
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
"\n --script FILE Script file to load on start"
|
||||
#endif
|
||||
;
|
||||
|
||||
m_subparsers[1].parse = nullptr;
|
||||
m_subparsers[1].parseLong = [](struct mSubParser* parser, const char* option, const char* arg) {
|
||||
ConfigController* self = static_cast<ConfigController*>(parser->opts);
|
||||
|
@ -171,6 +179,17 @@ ConfigController::ConfigController(QObject* parent)
|
|||
self->m_argvOptions[optionName] = QString::fromUtf8(arg);
|
||||
return true;
|
||||
}
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
if (optionName == QLatin1String("script")) {
|
||||
QStringList scripts;
|
||||
if (self->m_argvOptions.contains(optionName)) {
|
||||
scripts = self->m_argvOptions[optionName].toStringList();
|
||||
}
|
||||
scripts.append(QString::fromUtf8(arg));
|
||||
self->m_argvOptions[optionName] = scripts;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
};
|
||||
m_subparsers[1].apply = nullptr;
|
||||
|
|
|
@ -2184,6 +2184,18 @@ void Window::setController(CoreController* controller, const QString& fname) {
|
|||
m_controller->setPaused(true);
|
||||
m_pendingPause = false;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
if (!m_scripting) {
|
||||
QStringList scripts = m_config->getArgvOption("script").toStringList();
|
||||
if (!scripts.isEmpty()) {
|
||||
scriptingOpen();
|
||||
for (const auto& scriptPath : scripts) {
|
||||
m_scripting->loadFile(scriptPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Window::attachDisplay() {
|
||||
|
|
Loading…
Reference in New Issue