Files
asarium 016c07dc3a Add feature to execute Lua coroutines at specific points
This adds a mechanism for running generic operations at specific points
of the frame execution. This can be used by any part of the code an not
just Lua since it simply executes std::functions. It also adds an
"execution context" concept that specifies in which situation an
operation should be executed.

This is then used by the Lua Coroutines code for resuming coroutines at
specific points instead of always when the awaited promise resolves.
2020-06-06 21:29:48 +02:00

32 lines
455 B
C++

#pragma once
#include <utility>
namespace util {
namespace detail {
template <typename F>
struct FinalAction {
FinalAction(F f) : m_finally{std::move(f)} {}
~FinalAction()
{
if (m_enabled) {
m_finally();
}
}
void disable() { m_enabled = false; };
private:
F m_finally;
bool m_enabled{true};
};
} // namespace detail
template <typename F>
detail::FinalAction<F> finally(F f)
{
return detail::FinalAction<F>(f);
}
} // namespace util