Skip to content

Commit

Permalink
Hotkeys are now stable
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Feb 17, 2021
1 parent e8c8cac commit 47f04d6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/scripting/ScriptContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ ScriptContext::ScriptContext(LuaSandbox& aLuaSandbox, const std::filesystem::pat
m_logger->error("Tried to register an unknown event '{}'!", acName);
};

env["registerHotkey"] = [this, &env](const std::string& acID, const std::string& acDescription, sol::function aCallback)
env["registerHotkey"] = [this, &sb = m_sandbox, id = m_sandboxID](const std::string& acID, const std::string& acDescription,
sol::function aCallback)
{
if (acID.empty() ||
(std::find_if(acID.cbegin(), acID.cend(), [](char c){ return !(isalpha(c) || isdigit(c) || c == '_'); }) != acID.cend()))
Expand All @@ -74,8 +75,9 @@ ScriptContext::ScriptContext(LuaSandbox& aLuaSandbox, const std::filesystem::pat

auto loggerRef = m_logger;
std::string vkBindID = m_name + '.' + acID;
VKBind vkBind = { vkBindID, acDescription, [loggerRef, aCallback, &env]()
VKBind vkBind = {vkBindID, acDescription, [loggerRef, aCallback, &sb, id]()
{
auto& env = sb[id].GetEnvironment();
TryLuaFunction(loggerRef, env, aCallback);
}};

Expand Down

0 comments on commit 47f04d6

Please sign in to comment.