-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,14 @@ | |
|
||
// TODO: proper exception handling for Lua funcs! | ||
template <typename ...Args> | ||
static sol::protected_function_result TryLuaFunction(std::shared_ptr<spdlog::logger> aLogger, sol::function aFunc, Args... aArgs) | ||
static sol::protected_function_result TryLuaFunction(std::shared_ptr<spdlog::logger> aLogger, sol::environment& aEnv, sol::function aFunc, Args... aArgs) | ||
{ | ||
sol::protected_function_result result{ }; | ||
if (aFunc) | ||
{ | ||
try | ||
{ | ||
result = aFunc(aArgs...); | ||
result = aFunc(aArgs..., aEnv); | ||
} | ||
catch(std::exception& e) | ||
{ | ||
|
@@ -74,9 +74,12 @@ ScriptContext::ScriptContext(LuaSandbox& aLuaSandbox, const std::filesystem::pat | |
|
||
auto loggerRef = m_logger; | ||
std::string vkBindID = m_name + '.' + acID; | ||
VKBind vkBind = { vkBindID, acDescription, [loggerRef, aCallback]() | ||
VKBind vkBind = { vkBindID, acDescription, [loggerRef, aCallback, this]() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
WSSDude
Collaborator
|
||
{ | ||
TryLuaFunction(loggerRef, aCallback); | ||
auto& sb = m_sandbox[m_sandboxID]; | ||
auto& env = sb.GetEnvironment(); | ||
|
||
TryLuaFunction(loggerRef, env, aCallback); | ||
}}; | ||
|
||
m_vkBindInfos.emplace_back(VKBindInfo{vkBind}); | ||
|
@@ -130,37 +133,52 @@ const std::vector<VKBindInfo>& ScriptContext::GetBinds() const | |
|
||
void ScriptContext::TriggerOnInit() const | ||
{ | ||
auto& sb = m_sandbox[m_sandboxID]; | ||
auto& env = sb.GetEnvironment(); | ||
|
||
auto state = m_sandbox.GetState(); | ||
|
||
TryLuaFunction(m_logger, m_onInit); | ||
TryLuaFunction(m_logger, env, m_onInit); | ||
} | ||
|
||
void ScriptContext::TriggerOnUpdate(float aDeltaTime) const | ||
{ | ||
auto& sb = m_sandbox[m_sandboxID]; | ||
auto& env = sb.GetEnvironment(); | ||
|
||
auto state = m_sandbox.GetState(); | ||
|
||
TryLuaFunction(m_logger, m_onUpdate, aDeltaTime); | ||
TryLuaFunction(m_logger, env, m_onUpdate, aDeltaTime); | ||
} | ||
|
||
void ScriptContext::TriggerOnDraw() const | ||
{ | ||
auto& sb = m_sandbox[m_sandboxID]; | ||
auto& env = sb.GetEnvironment(); | ||
|
||
auto state = m_sandbox.GetState(); | ||
|
||
TryLuaFunction(m_logger, m_onDraw); | ||
TryLuaFunction(m_logger, env, m_onDraw); | ||
} | ||
|
||
void ScriptContext::TriggerOnOverlayOpen() const | ||
{ | ||
auto& sb = m_sandbox[m_sandboxID]; | ||
auto& env = sb.GetEnvironment(); | ||
|
||
auto state = m_sandbox.GetState(); | ||
|
||
TryLuaFunction(m_logger, m_onOverlayOpen); | ||
TryLuaFunction(m_logger, env, m_onOverlayOpen); | ||
} | ||
|
||
void ScriptContext::TriggerOnOverlayClose() const | ||
{ | ||
auto& sb = m_sandbox[m_sandboxID]; | ||
auto& env = sb.GetEnvironment(); | ||
|
||
auto state = m_sandbox.GetState(); | ||
|
||
TryLuaFunction(m_logger, m_onOverlayClose); | ||
TryLuaFunction(m_logger, env, m_onOverlayClose); | ||
} | ||
|
||
sol::object ScriptContext::GetRootObject() const | ||
|
@@ -170,7 +188,10 @@ sol::object ScriptContext::GetRootObject() const | |
|
||
void ScriptContext::TriggerOnShutdown() const | ||
{ | ||
auto& sb = m_sandbox[m_sandboxID]; | ||
auto& env = sb.GetEnvironment(); | ||
|
||
auto state = m_sandbox.GetState(); | ||
|
||
TryLuaFunction(m_logger, m_onShutdown); | ||
TryLuaFunction(m_logger, env, m_onShutdown); | ||
} |
this may be toxic, i would rather pass reference to sandbox or even better, just environment