Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
lua_callback.hpp
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include <cstdint>
12
#include <functional>
13
#include <lua.hpp>
14
#include <luabridge3/LuaBridge/LuaBridge.h>
15
#include <memory>
16
#include <optional>
17
#include <string>
18
#include <
toast/export.hpp
>
19
20
namespace
scripting {
21
22
class
TOAST_API LuaCallback {
23
public
:
24
LuaCallback() =
default
;
25
29
[[nodiscard]]
30
static
auto
capture
(
const
luabridge::LuaRef& fn, std::string name = {}) -> LuaCallback;
31
32
[[nodiscard]]
33
explicit
operator
bool()
const
noexcept
{
34
return
m_shared !=
nullptr
;
35
}
36
38
[[nodiscard]]
39
auto
alive
()
const
noexcept
-> bool;
40
46
[[nodiscard]]
47
auto
invoke
()
const
noexcept
-> bool;
48
50
[[nodiscard]]
51
auto
invokeBool
()
const
noexcept
-> std::optional<bool>;
52
57
[[nodiscard]]
58
auto
invokeWithArgument
(
const
std::function<
void
(lua_State*)>& push_argument)
const
noexcept
-> std::optional<bool>;
59
60
private
:
61
struct
Shared
;
62
explicit
LuaCallback(std::shared_ptr<Shared> shared)
noexcept
;
63
65
auto
execute(
66
const
std::function<
void
(lua_State*)>* push_argument,
bool
want_result, std::optional<bool>& result,
bool
allow_queue
67
)
const
noexcept
-> bool;
68
69
std::shared_ptr<Shared> m_shared;
70
};
71
72
}
scripting::LuaCallback::invokeWithArgument
auto invokeWithArgument(const std::function< void(lua_State *)> &push_argument) const noexcept -> std::optional< bool >
Calls the function with one argument.
Definition
lua_callback.cpp:89
scripting::LuaCallback::capture
static auto capture(const luabridge::LuaRef &fn, std::string name={}) -> LuaCallback
Keeps function alive on its interpreter.
Definition
lua_callback.cpp:41
scripting::LuaCallback::invoke
auto invoke() const noexcept -> bool
Calls the function with no arguments and ignores the result.
Definition
lua_callback.cpp:73
scripting::LuaCallback::invokeBool
auto invokeBool() const noexcept -> std::optional< bool >
Calls the function and expects a boolean back.
Definition
lua_callback.cpp:78
scripting::LuaCallback::alive
auto alive() const noexcept -> bool
False once the runtime that created the function is gone.
Definition
lua_callback.cpp:69
export.hpp
scripting::LuaCallback::Shared
Definition
lua_callback.cpp:14
engine
src
toast
scripting
lua_callback.hpp
Generated by
1.17.0