summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/mame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/mame/mame.cpp')
-rw-r--r--src/frontend/mame/mame.cpp91
1 files changed, 72 insertions, 19 deletions
diff --git a/src/frontend/mame/mame.cpp b/src/frontend/mame/mame.cpp
index c7bc0879909..a44bd19814f 100644
--- a/src/frontend/mame/mame.cpp
+++ b/src/frontend/mame/mame.cpp
@@ -19,6 +19,7 @@
#include "cheat.h"
#include "clifront.h"
#include "emuopts.h"
+#include "fileio.h"
#include "luaengine.h"
#include "mameopts.h"
#include "pluginopts.h"
@@ -73,6 +74,7 @@ mame_machine_manager::mame_machine_manager(emu_options &options,osd_interface &o
mame_machine_manager::~mame_machine_manager()
{
+ m_autoboot_script.reset();
m_lua.reset();
s_manager = nullptr;
}
@@ -141,10 +143,7 @@ void mame_machine_manager::start_luaengine()
std::string pluginpath;
while (iter.next(pluginpath))
{
- // user may specify environment variables; subsitute them
- osd_subst_env(pluginpath, pluginpath);
-
- // and then scan the directory recursively
+ // scan the directory recursively
m_plugins->scan_directory(pluginpath, true);
}
@@ -201,9 +200,29 @@ void mame_machine_manager::start_luaengine()
std::error_condition const filerr = file.open("boot.lua");
if (!filerr)
{
- std::string exppath;
- osd_subst_env(exppath, std::string(file.fullpath()));
- m_lua->load_script(exppath.c_str());
+ const std::string exppath = file.fullpath();
+ auto &l(*lua());
+ auto load_result = l.load_script(exppath);
+ if (!load_result.valid())
+ {
+ sol::error err = load_result;
+ sol::load_status status = load_result.status();
+ fatalerror("Error plugin bootstrap script %s: %s error\n%s\n",
+ exppath,
+ sol::to_string(status),
+ err.what());
+ }
+ sol::protected_function func = load_result;
+ sol::protected_function_result call_result = l.invoke(func);
+ if (!call_result.valid())
+ {
+ sol::error err = call_result;
+ sol::call_status status = call_result.status();
+ fatalerror("Error running plugin bootstrap script %s: %s error\n%s\n",
+ options().autoboot_script(),
+ sol::to_string(status),
+ err.what());
+ }
}
}
}
@@ -245,7 +264,7 @@ int mame_machine_manager::execute()
m_options.revert(OPTION_PRIORITY_INI);
std::ostringstream errors;
- mame_options::parse_standard_inis(m_options, errors);
+ mame_options::parse_standard_inis(m_options, errors, system);
}
// otherwise, perform validity checks before anything else
@@ -279,7 +298,10 @@ int mame_machine_manager::execute()
else
{
if (machine.exit_pending())
+ {
m_options.set_system_name("");
+ m_options.set_value(OPTION_BIOS, "", OPTION_PRIORITY_CMDLINE);
+ }
}
if (machine.exit_pending() && (!started_empty || is_empty))
@@ -294,21 +316,35 @@ int mame_machine_manager::execute()
TIMER_CALLBACK_MEMBER(mame_machine_manager::autoboot_callback)
{
- if (strlen(options().autoboot_script())!=0) {
- mame_machine_manager::instance()->lua()->load_script(options().autoboot_script());
+ if (*options().autoboot_script())
+ {
+ assert(m_autoboot_script);
+ sol::protected_function func = *m_autoboot_script;
+ sol::protected_function_result result = lua()->invoke(func);
+ if (!result.valid())
+ {
+ sol::error err = result;
+ sol::call_status status = result.status();
+ fatalerror("Error running autoboot script %s: %s error\n%s\n",
+ options().autoboot_script(),
+ sol::to_string(status),
+ err.what());
+ }
}
- else if (strlen(options().autoboot_command())!=0) {
- std::string cmd = std::string(options().autoboot_command());
+ else if (*options().autoboot_command())
+ {
+ std::string cmd(options().autoboot_command());
strreplace(cmd, "'", "\\'");
std::string val = std::string("emu.keypost('").append(cmd).append("')");
- mame_machine_manager::instance()->lua()->load_string(val.c_str());
+ auto &l(*lua());
+ l.invoke(l.load_string(val).get<sol::protected_function>());
}
}
void mame_machine_manager::reset()
{
// setup autoboot if needed
- m_autoboot_timer->adjust(attotime(options().autoboot_delay(),0),0);
+ m_autoboot_timer->adjust(attotime(options().autoboot_delay(), 0), 0);
}
ui_manager* mame_machine_manager::create_ui(running_machine& machine)
@@ -318,8 +354,6 @@ ui_manager* mame_machine_manager::create_ui(running_machine& machine)
machine.add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(&mame_machine_manager::reset, this));
- m_ui->set_startup_text("Initializing...", true);
-
return m_ui.get();
}
@@ -336,7 +370,7 @@ void mame_machine_manager::before_load_settings(running_machine& machine)
m_lua->on_machine_before_load_settings();
}
-void mame_machine_manager::create_custom(running_machine& machine)
+void mame_machine_manager::create_custom(running_machine &machine)
{
// start the inifile manager
m_inifile = std::make_unique<inifile_manager>(m_ui->options());
@@ -346,6 +380,25 @@ void mame_machine_manager::create_custom(running_machine& machine)
// start favorite manager
m_favorite = std::make_unique<favorite_manager>(m_ui->options());
+
+ // attempt to load the autoboot script if configured
+ m_autoboot_script.reset();
+ if (*options().autoboot_script())
+ {
+ auto result = lua()->load_script(options().autoboot_script());
+ if (!result.valid())
+ {
+ sol::error err = result;
+ sol::load_status status = result.status();
+ fatalerror("Error loading autoboot script %s: %s error\n%s\n",
+ options().autoboot_script(),
+ sol::to_string(status),
+ err.what());
+ }
+ m_autoboot_script.reset(new sol::load_result(std::move(result)));
+ sol::protected_function func = *m_autoboot_script;
+ sol::set_environment(lua()->make_environment(), func);
+ }
}
void mame_machine_manager::load_cheatfiles(running_machine& machine)
@@ -406,9 +459,9 @@ int emulator_info::start_frontend(emu_options &options, osd_interface &osd, int
return start_frontend(options, osd, args);
}
-void emulator_info::draw_user_interface(running_machine& machine)
+bool emulator_info::draw_user_interface(running_machine& machine)
{
- mame_machine_manager::instance()->ui().update_and_render(machine.render().ui_container());
+ return mame_machine_manager::instance()->ui().update_and_render(machine.render().ui_container());
}
void emulator_info::periodic_check()