18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-28 12:36:20 +01:00
Files
maszyna/utilities/inionlysettings.cpp
jerrrrycho 3ae8d4e72e fix(scripting): typed scenery handles, sandbox keys from eu07.ini only, GCC 13 build
- the scenery API (eu07.events) hands out a full userdata of its own locked
  metatable for each kind of object (event, track, isolated, vehicle,
  memcell), checked with luaL_checkudata: a handle of another kind, a light
  userdata or any other value is a Lua error, not an object taken for
  another. nil stays "no object". one object has one handle while the
  script holds it, so handles compare and key tables as before. event
  handlers get their handles built inside lua_cpcall, and nil for no
  activator
- memcell_values keeps its text as a std::string: the text of a number was
  read from a stack slot popped before use
- newproxy is gone from the sandboxed libraries
- a config block of a scenery no longer changes what only eu07.ini sets
  (lua.fulllibraries, execonexit, extcam.cmd/rec, screenshotsdir,
  network.server/client, zmq.address, motiontelemetry, uart, feedbackmode,
  feedbackport, python/luascreens/wasm.enabled): kept before its keys are
  read, put back before FinalizeConfig(), each attempt logged
- open_file_library() iterates luaL_Reg instead of a std::pair GCC 13
  deduces as a pair of an array and a function
2026-11-16 08:54:00 +01:00

83 lines
3.1 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "utilities/inionlysettings.h"
namespace
{
// puts Kept back into Current, and adds Key to Changed when they differed
template <typename Type_> void keep(Type_ &Current, Type_ const &Kept, std::string_view const Key, std::vector<std::string_view> &Changed)
{
if (false == (Current == Kept))
{
Current = Kept;
Changed.push_back(Key);
}
}
} // namespace
ini_only_settings::ini_only_settings(global_settings const &Settings)
: m_exec_on_exit{Settings.exec_on_exit}, m_screenshot_dir{Settings.screenshot_dir}, m_extcam_cmd{Settings.extcam_cmd},
m_extcam_rec{Settings.extcam_rec}, m_network_servers{Settings.network_servers}, m_network_client{Settings.network_client},
#ifdef WITH_ZMQ
m_zmq_address{Settings.zmq_address},
#endif
m_motiontelemetry{Settings.motiontelemetry_conf},
#ifdef WITH_UART
m_uart{Settings.uart_conf},
#endif
m_feedback_mode{Settings.iFeedbackMode}, m_feedback_port{Settings.iFeedbackPort}, m_python_enabled{Settings.python_enabled},
m_luascreens_enabled{Settings.luascreens_enabled}, m_lua_fulllibraries{Settings.lua_fulllibraries}, m_wasm_enabled{Settings.wasm_enabled}
{
}
std::vector<std::string_view> ini_only_settings::restore(global_settings &Settings) const
{
std::vector<std::string_view> changed;
keep(Settings.exec_on_exit, m_exec_on_exit, "execonexit", changed);
keep(Settings.screenshot_dir, m_screenshot_dir, "screenshotsdir", changed);
keep(Settings.extcam_cmd, m_extcam_cmd, "extcam.cmd", changed);
keep(Settings.extcam_rec, m_extcam_rec, "extcam.rec", changed);
keep(Settings.network_servers, m_network_servers, "network.server", changed);
keep(Settings.network_client, m_network_client, "network.client", changed);
#ifdef WITH_ZMQ
keep(Settings.zmq_address, m_zmq_address, "zmq.address", changed);
#endif
// the structures as a whole, told apart by what turns them on and where they lead
{
auto &current{Settings.motiontelemetry_conf};
if (current.enable != m_motiontelemetry.enable || current.proto != m_motiontelemetry.proto || current.address != m_motiontelemetry.address ||
current.port != m_motiontelemetry.port)
{
changed.emplace_back("motiontelemetry");
}
current = m_motiontelemetry;
}
#ifdef WITH_UART
{
auto &current{Settings.uart_conf};
if (current.enable != m_uart.enable || current.port != m_uart.port)
{
changed.emplace_back("uart");
}
current = m_uart;
}
#endif
keep(Settings.iFeedbackMode, m_feedback_mode, "feedbackmode", changed);
keep(Settings.iFeedbackPort, m_feedback_port, "feedbackport", changed);
keep(Settings.python_enabled, m_python_enabled, "python.enabled", changed);
keep(Settings.luascreens_enabled, m_luascreens_enabled, "luascreens.enabled", changed);
keep(Settings.lua_fulllibraries, m_lua_fulllibraries, "lua.fulllibraries", changed);
keep(Settings.wasm_enabled, m_wasm_enabled, "wasm.enabled", changed);
return changed;
}