1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Start work on intransient plugins

This commit is contained in:
Ted John
2021-03-02 00:17:13 +00:00
parent 91ceecc6fc
commit 6fea0b5025
5 changed files with 235 additions and 27 deletions

View File

@@ -23,7 +23,7 @@
using namespace OpenRCT2::Scripting;
Plugin::Plugin(duk_context* context, const std::string& path)
Plugin::Plugin(duk_context* context, std::string_view path)
: _context(context)
, _path(path)
{
@@ -73,10 +73,16 @@ void Plugin::Load()
}
_metadata = GetMetadata(DukValue::take_from_stack(_context));
_hasLoaded = true;
}
void Plugin::Start()
{
if (!_hasLoaded)
{
throw std::runtime_error("Plugin has not been loaded.");
}
const auto& mainFunc = _metadata.Main;
if (mainFunc.context() == nullptr)
{
@@ -115,6 +121,12 @@ void Plugin::ThrowIfStopping() const
}
}
void Plugin::Unload()
{
_metadata.Main = {};
_hasLoaded = false;
}
void Plugin::LoadCodeFromFile()
{
_code = File::ReadAllText(_path);
@@ -174,6 +186,8 @@ PluginType Plugin::ParsePluginType(std::string_view type)
return PluginType::Local;
if (type == "remote")
return PluginType::Remote;
if (type == "intransient")
return PluginType::Intransient;
throw std::invalid_argument("Unknown plugin type.");
}
@@ -192,4 +206,9 @@ int32_t Plugin::GetTargetAPIVersion() const
return 33;
}
bool Plugin::IsTransient() const
{
return _metadata.Type != PluginType::Intransient;
}
#endif