Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
script_schema.hpp
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include <any>
12
#include <cstdint>
13
#include <limits>
14
#include <string>
15
#include <string_view>
16
#include <vector>
17
18
namespace
scripting {
19
20
enum class
LuaVarKind : uint8_t {
21
boolean,
22
integer,
23
number,
24
string,
25
vec2,
26
vec3,
27
vec4,
28
color3,
29
color4,
30
node_ref,
31
asset_ref,
32
};
33
34
struct
LuaVarDesc
{
35
std::string name;
36
std::string path;
37
std::string display_name;
38
LuaVarKind kind = LuaVarKind::boolean;
39
bool
is_array =
false
;
40
bool
read_only =
false
;
41
bool
hidden =
false
;
42
double
min = -std::numeric_limits<double>::infinity();
43
double
max = std::numeric_limits<double>::infinity();
44
std::string unit;
45
std::string ref_type;
46
std::any default_value;
47
};
48
49
struct
LuaSubgroup
{
50
std::string name;
51
std::vector<LuaVarDesc> fields;
52
};
53
54
struct
LuaGroup
{
55
std::string name;
56
std::vector<LuaVarDesc> fields;
57
std::vector<LuaSubgroup> subgroups;
58
};
59
60
struct
LuaFunctionDesc
{
61
std::string name;
62
std::vector<std::string> parameters;
63
bool
is_vararg =
false
;
64
};
65
66
struct
ScriptSchema
{
67
std::vector<LuaVarDesc> fields;
68
std::vector<LuaGroup> groups;
69
std::vector<LuaFunctionDesc> functions;
70
72
template
<
typename
F>
73
void
forEach
(F&& fn)
const
{
74
for
(
const
auto
& f : fields) {
75
fn(f);
76
}
77
for
(
const
auto
& g : groups) {
78
for
(
const
auto
& f : g.fields) {
79
fn(f);
80
}
81
for
(
const
auto
& s : g.subgroups) {
82
for
(
const
auto
& f : s.fields) {
83
fn(f);
84
}
85
}
86
}
87
}
88
90
[[nodiscard]]
91
auto
find
(std::string_view path)
const
->
const
LuaVarDesc
* {
92
const
LuaVarDesc
* found =
nullptr
;
93
forEach
([&](
const
LuaVarDesc
& d) {
94
if
(found ==
nullptr
&& d.path == path) {
95
found = &d;
96
}
97
});
98
return
found;
99
}
100
};
101
102
}
scripting::LuaFunctionDesc
Definition
script_schema.hpp:60
scripting::LuaGroup
Definition
script_schema.hpp:54
scripting::LuaSubgroup
Definition
script_schema.hpp:49
scripting::LuaVarDesc
Definition
script_schema.hpp:34
scripting::ScriptSchema
Definition
script_schema.hpp:66
scripting::ScriptSchema::forEach
void forEach(F &&fn) const
Calls fn(const LuaVarDesc&) for every var.
Definition
script_schema.hpp:73
scripting::ScriptSchema::find
auto find(std::string_view path) const -> const LuaVarDesc *
Finds a var by its path.
Definition
script_schema.hpp:91
engine
src
toast
scripting
script_schema.hpp
Generated by
1.17.0