From 417ffc09f8ebf9f98ddcff55db11df1adb2a8d59 Mon Sep 17 00:00:00 2001 From: BornPosthumous Date: Sun, 21 Nov 2021 09:16:11 -0500 Subject: [PATCH] Allows override of flycast.lua file (#411) --- core/cfg/option.cpp | 4 ++++ core/cfg/option.h | 4 ++++ core/lua/lua.cpp | 15 ++++++++++++++- core/rend/gui.cpp | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/core/cfg/option.cpp b/core/cfg/option.cpp index 9ea1e8bc2..e1eaf44b5 100644 --- a/core/cfg/option.cpp +++ b/core/cfg/option.cpp @@ -160,4 +160,8 @@ std::array, 2>, 4> MapleExpansionDevices { Option UseRawInput("RawInput", false, "input"); #endif +#ifdef USE_LUA +OptionString LuaFileName("LuaFileName", "flycast.lua"); +#endif + } // namespace config diff --git a/core/cfg/option.h b/core/cfg/option.h index add56cb9b..ef88e8130 100644 --- a/core/cfg/option.h +++ b/core/cfg/option.h @@ -484,5 +484,9 @@ extern Option UseRawInput; constexpr bool UseRawInput = false; #endif +#ifdef USE_LUA +extern OptionString LuaFileName; +#endif + } // namespace config diff --git a/core/lua/lua.cpp b/core/lua/lua.cpp index 9491d40cd..313b2d27f 100644 --- a/core/lua/lua.cpp +++ b/core/lua/lua.cpp @@ -578,6 +578,19 @@ static void luaRegister(lua_State *L) .endNamespace(); } +static std::string getLuaFile() +{ + std::string initFile; + if( !config::LuaFileName.get().empty()){ + initFile = get_readonly_config_path(config::LuaFileName.get()); + } else { + initFile = get_readonly_config_path("flycast.lua"); + } + + return initFile; + +} + static void doExec(const std::string& path) { if (L == nullptr) @@ -598,7 +611,7 @@ void exec(const std::string& path) void init() { - std::string initFile = get_readonly_config_path("flycast.lua"); + std::string initFile = getLuaFile(); if (!file_exists(initFile)) return; L = luaL_newstate(); diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 7fa9350da..bc0160ef7 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1965,6 +1965,20 @@ static void gui_display_settings() } ImGui::PopStyleVar(); ImGui::EndTabItem(); + + #ifdef USE_LUA + header("Lua Scripting"); + { + char LuaFileName[256]; + + strcpy(LuaFileName, config::LuaFileName.get().c_str()); + ImGui::InputText("Lua Filename", LuaFileName, sizeof(LuaFileName), ImGuiInputTextFlags_CharsNoBlank, nullptr, nullptr); + ImGui::SameLine(); + ShowHelpMarker("Specify lua filename to use. Should be located in Flycasts root directory. Defaults to flycast.lua when empty."); + config::LuaFileName = LuaFileName; + + } + #endif } if (ImGui::BeginTabItem("About")) {