Toast Engine
Loading...
Searching...
No Matches
node_proxy.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <any>
12#include <glm/vec3.hpp>
13#include <string>
14#include <toast/world/box.hpp>
15#include <vector>
16
17struct lua_State;
18
19namespace luabridge {
20class LuaRef;
21}
22
23namespace toast {
24struct FieldInfo;
25class Node;
26}
27
28namespace scripting {
29
30struct TypeMarker;
31
32class Vec3FieldProxy : public glm::vec3 {
33public:
34 Vec3FieldProxy(toast::Box<toast::Node> node, const toast::FieldInfo* field, const glm::vec3& value) noexcept;
35
36 [[nodiscard]]
37 auto getX() const -> float;
38 [[nodiscard]]
39 auto getY() const -> float;
40 [[nodiscard]]
41 auto getZ() const -> float;
42 void setX(float value);
43 void setY(float value);
44 void setZ(float value);
45
46private:
47 [[nodiscard]]
48 auto current() const -> glm::vec3;
49 void commit(const glm::vec3& value);
50
52 const toast::FieldInfo* m_field = nullptr;
53};
54
55class NodeProxy {
56public:
57 NodeProxy() = default;
58 explicit NodeProxy(toast::Box<toast::Node> box) noexcept;
59
60 [[nodiscard]]
61 auto box() noexcept -> toast::Box<toast::Node>& {
62 return m_box;
63 }
64
65 [[nodiscard]]
66 auto box() const noexcept -> const toast::Box<toast::Node>& {
67 return m_box;
68 }
69
70 [[nodiscard]]
71 auto exists() const noexcept -> bool;
72
73 auto find(const std::string& query, lua_State* l) -> luabridge::LuaRef;
74 auto search(const std::string& query) -> std::vector<NodeProxy>;
75 auto parent(lua_State* l) -> luabridge::LuaRef;
76 auto root(lua_State* l) -> luabridge::LuaRef;
77 auto searchType(const std::string& type, lua_State* l) -> std::vector<NodeProxy>;
78 auto searchType(const TypeMarker& type, lua_State* l) -> std::vector<NodeProxy>;
79 auto getChildren(lua_State* l) -> std::vector<NodeProxy>;
80 auto getChildren(const std::string& type, lua_State* l) -> std::vector<NodeProxy>;
81 auto getChildren(const TypeMarker& type, lua_State* l) -> std::vector<NodeProxy>;
82 auto create(const std::string& type, lua_State* l) -> luabridge::LuaRef;
83 void addDependsOn(const NodeProxy& other);
84 void interactsWith(const NodeProxy& other);
85
86 [[nodiscard]]
87 auto name() const -> std::string;
88 [[nodiscard]]
89 auto uid() const -> uint64_t;
90
93 auto call(const std::string& fn_name, lua_State* l) -> luabridge::LuaRef;
94
96 [[nodiscard]]
97 auto hasField(std::string_view key) const noexcept -> bool;
98
99private:
101};
102
103// Called AFTER the normal LuaBridge method/property lookup fails
104auto nodeProxyIndex(NodeProxy& proxy, const luabridge::LuaRef& key, lua_State* l) -> luabridge::LuaRef;
105auto nodeProxyNewindex(NodeProxy& proxy, const luabridge::LuaRef& key, const luabridge::LuaRef& value, lua_State* l)
106 -> luabridge::LuaRef;
107
108auto nodeProxyDispatchMethod(NodeProxy& np, std::string_view name, lua_State* l, int args_base, int n_args) -> int;
109
110auto anyValueToLuaRef(lua_State* l, const std::any& value) -> luabridge::LuaRef;
111
113auto luaRefValueToAny(lua_State* l, const luabridge::LuaRef& v) -> std::any;
114
115}
pseudo shared pointer for Nodes
Definition node_proxy.hpp:55
auto call(const std::string &fn_name, lua_State *l) -> luabridge::LuaRef
Definition node_proxy.cpp:1192
auto hasField(std::string_view key) const noexcept -> bool
Definition node_proxy.cpp:1184
Intrusive reference-counted handle to a Node.
Definition box.hpp:35
Definition node.hpp:81
Lua-side placeholder declaring a typed Node or Asset reference.
Definition lua_types.hpp:22
Runtime descriptor for one reflected field.
Definition reflect.hpp:79