Implement surface style API and improve plugin calling

This commit is contained in:
Ted John
2020-02-29 13:18:31 +00:00
parent 32d72471b8
commit 4d5e7f19ca
8 changed files with 86 additions and 66 deletions

View File

@@ -356,7 +356,7 @@ DukContext::~DukContext()
ScriptEngine::ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& env)
: _console(console)
, _env(env)
, _hookEngine(_execInfo)
, _hookEngine(*this, _execInfo)
{
}
@@ -652,6 +652,34 @@ std::future<void> ScriptEngine::Eval(const std::string& s)
return future;
}
bool ScriptEngine::ExecutePluginCall(
const std::shared_ptr<Plugin>& plugin, const DukValue& func, const std::vector<DukValue>& args, bool isGameStateMutable)
{
if (func.is_function())
{
ScriptExecutionInfo::PluginScope scope(_execInfo, plugin, isGameStateMutable);
func.push();
for (const auto& arg : args)
{
arg.push();
}
auto result = duk_pcall(_context, static_cast<duk_idx_t>(args.size()));
if (result == DUK_EXEC_SUCCESS)
{
// TODO allow result to be returned as a DukValue
duk_pop(_context);
return true;
}
else
{
auto message = duk_safe_to_string(_context, -1);
LogPluginInfo(plugin, message);
duk_pop(_context);
}
}
return false;
}
void ScriptEngine::LogPluginInfo(const std::shared_ptr<Plugin>& plugin, const std::string_view& message)
{
const auto& pluginName = plugin->GetMetadata().Name;