Add get and set for scriptSystemAccessPolicy in CelestiaCore
parent
776f93bedb
commit
45984abfc5
|
@ -4053,6 +4053,18 @@ bool CelestiaCore::initSimulation(const fs::path& configFileName,
|
|||
GetLogger()->warn("Unknown temperature scale {}\n", config->temperatureScale);
|
||||
}
|
||||
|
||||
if (!config->scriptSystemAccessPolicy.empty())
|
||||
{
|
||||
if (compareIgnoringCase(config->scriptSystemAccessPolicy, "ask") == 0)
|
||||
scriptSystemAccessPolicy = Ask;
|
||||
else if (compareIgnoringCase(config->scriptSystemAccessPolicy, "allow") == 0)
|
||||
scriptSystemAccessPolicy = Allow;
|
||||
else if (compareIgnoringCase(config->scriptSystemAccessPolicy, "deny") == 0)
|
||||
scriptSystemAccessPolicy = Deny;
|
||||
else
|
||||
GetLogger()->warn("Unknown script system access policy {}\n", config->scriptSystemAccessPolicy);
|
||||
}
|
||||
|
||||
sim = new Simulation(universe);
|
||||
if ((renderer->getRenderFlags() & Renderer::ShowAutoMag) == 0)
|
||||
{
|
||||
|
@ -4813,6 +4825,16 @@ View* CelestiaCore::getViewByObserver(const Observer *obs) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void CelestiaCore::setScriptSystemAccessPolicy(ScriptSystemAccessPolicy policy)
|
||||
{
|
||||
scriptSystemAccessPolicy = policy;
|
||||
}
|
||||
|
||||
CelestiaCore::ScriptSystemAccessPolicy CelestiaCore::getScriptSystemAccessPolicy() const
|
||||
{
|
||||
return scriptSystemAccessPolicy;
|
||||
}
|
||||
|
||||
void CelestiaCore::getCaptureInfo(std::array<int, 4>& viewport, celestia::PixelFormat& format) const
|
||||
{
|
||||
renderer->getViewport(viewport);
|
||||
|
|
|
@ -194,6 +194,13 @@ class CelestiaCore // : public Watchable<CelestiaCore>
|
|||
Fahrenheit = 2,
|
||||
};
|
||||
|
||||
enum ScriptSystemAccessPolicy
|
||||
{
|
||||
Ask = 0,
|
||||
Allow = 1,
|
||||
Deny = 2,
|
||||
};
|
||||
|
||||
struct EdgeInsets
|
||||
{
|
||||
int left;
|
||||
|
@ -396,6 +403,9 @@ class CelestiaCore // : public Watchable<CelestiaCore>
|
|||
const std::string& getTypedText() const { return typedText; }
|
||||
void setTypedText(const char *);
|
||||
|
||||
void setScriptSystemAccessPolicy(ScriptSystemAccessPolicy);
|
||||
ScriptSystemAccessPolicy getScriptSystemAccessPolicy() const;
|
||||
|
||||
void setScriptHook(std::unique_ptr<celestia::scripts::IScriptHook> &&hook) { m_scriptHook = std::move(hook); }
|
||||
const std::shared_ptr<celestia::scripts::ScriptMaps>& scriptMaps() const { return m_scriptMaps; }
|
||||
|
||||
|
@ -471,6 +481,8 @@ class CelestiaCore // : public Watchable<CelestiaCore>
|
|||
|
||||
Timer* timer{ nullptr };
|
||||
|
||||
ScriptSystemAccessPolicy scriptSystemAccessPolicy{ Ask };
|
||||
|
||||
std::unique_ptr<celestia::scripts::IScript> m_script;
|
||||
std::unique_ptr<celestia::scripts::IScriptHook> m_scriptHook;
|
||||
std::unique_ptr<celestia::scripts::LegacyScriptPlugin> m_legacyPlugin;
|
||||
|
|
|
@ -118,7 +118,6 @@ CelestiaConfig* ReadCelestiaConfig(const fs::path& filename, CelestiaConfig *con
|
|||
config->reverseMouseWheel = false;
|
||||
configParams->getBoolean("ReverseMouseWheel", config->reverseMouseWheel);
|
||||
configParams->getPath("ScriptScreenshotDirectory", config->scriptScreenshotDirectory);
|
||||
config->scriptSystemAccessPolicy = "ask";
|
||||
configParams->getString("ScriptSystemAccessPolicy", config->scriptSystemAccessPolicy);
|
||||
|
||||
config->orbitWindowEnd = 0.5f;
|
||||
|
|
|
@ -829,15 +829,15 @@ void LuaState::requestIO()
|
|||
if (ioMode == NoIO)
|
||||
{
|
||||
CelestiaCore* appCore = getAppCore(state, AllErrors);
|
||||
string policy = appCore->getConfig()->scriptSystemAccessPolicy;
|
||||
if (policy == "allow")
|
||||
auto policy = appCore->getScriptSystemAccessPolicy();
|
||||
if (policy == CelestiaCore::Allow)
|
||||
{
|
||||
openLuaLibrary(costate, LUA_LOADLIBNAME, luaopen_package);
|
||||
openLuaLibrary(costate, LUA_IOLIBNAME, luaopen_io);
|
||||
openLuaLibrary(costate, LUA_OSLIBNAME, luaopen_os);
|
||||
ioMode = IOAllowed;
|
||||
}
|
||||
else if (policy == "deny")
|
||||
else if (policy == CelestiaCore::Deny)
|
||||
{
|
||||
ioMode = IODenied;
|
||||
}
|
||||
|
|
|
@ -256,7 +256,7 @@ bool CreateLuaEnvironment(CelestiaCore *appCore, const CelestiaConfig *config, P
|
|||
// Set up the script context; if the system access policy is allow,
|
||||
// it will share the same context as the Lua hook. Otherwise, we
|
||||
// create a private context.
|
||||
if (config->scriptSystemAccessPolicy == "allow")
|
||||
if (appCore->getScriptSystemAccessPolicy() == CelestiaCore::Allow)
|
||||
{
|
||||
if (luaHook != nullptr)
|
||||
SetScriptedObjectContext(luaHook->getState());
|
||||
|
|
Loading…
Reference in New Issue