Skip to content

Commit 140c93c

Browse files
committed
separate out modules
1 parent a8664d1 commit 140c93c

File tree

6 files changed

+616
-0
lines changed

6 files changed

+616
-0
lines changed

docs/src/SUMMARY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@
1212

1313
[Introduction](./ScriptingReference/introduction.md)
1414
- [Core Bindings](./ScriptingReference/core-api.md)
15+
- [World](./ScriptingReference/world.md)
16+
- [ReflectReference](./ScriptingReference/reflect-reference.md)
17+
- [ScriptTypeRegistration](./ScriptingReference/script-type-registration.md)
18+
- [ScriptQueryBuilder](./ScriptingReference/script-query-builder.md)
19+
- [ScriptQueryResult](./ScriptingReference/script-query-result.md)
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# ReflectReference
2+
3+
ReflectReferences are simply references to date living either:
4+
- In a component
5+
- In a resource
6+
- In the allocator
7+
8+
Reflect references contain a standard interface which operates over the reflection layer exposed by `Bevy` and also provides a way to call various dynamic functions registered on the underlying pointed to data.
9+
10+
## display_ref
11+
12+
| Argument | Type | Description |
13+
| --- | --- | --- |
14+
| `s` | `ReflectReference` | The reference to display |
15+
16+
17+
18+
| Return | Description |
19+
| --- | --- |
20+
| `String` | The reference in string format |
21+
22+
```lua
23+
print(ref:display_ref())
24+
print(ref)
25+
```
26+
27+
## display_value
28+
29+
| Argument | Type | Description |
30+
| --- | --- | --- |
31+
| `s` | `ReflectReference` | The reference to display |
32+
33+
34+
| Return | Description |
35+
| --- | --- |
36+
| `String` | The value in string format |
37+
38+
```lua
39+
print(ref:display_value())
40+
```
41+
42+
## get
43+
The index function, allows you to index into the reflect reference.
44+
45+
| Argument | Type | Description |
46+
| --- | --- | --- |
47+
| `key` | `ScriptValue` | The key to get the value for |
48+
49+
50+
| Return | Description |
51+
| --- | --- |
52+
| `ScriptValue` | The value |
53+
54+
```lua
55+
local value = ref:get(key)
56+
-- same as
57+
local value = ref.key
58+
local value = ref[key]
59+
local value = ref["key"]
60+
-- for tuple structs
61+
local valye = ref._1
62+
```
63+
64+
## set
65+
66+
| Argument | Type | Description |
67+
| --- | --- | --- |
68+
| `key` | `ScriptValue` | The key to set the value for |
69+
| `value` | `ScriptValue` | The value to set |
70+
71+
72+
| Return | Description |
73+
| --- | --- |
74+
| `ScriptValue` | The result |
75+
76+
```lua
77+
ref:set(key, value)
78+
-- same as
79+
ref.key = value
80+
ref[key] = value
81+
ref["key"] = value
82+
-- for tuple structs
83+
ref._1 = value
84+
```
85+
86+
## push
87+
Generic push method, if the underlying type supports it, will push the value into the end of the reference.
88+
89+
| Argument | Type | Description |
90+
| --- | --- | --- |
91+
| `value` | `ScriptValue` | The value to push |
92+
93+
```lua
94+
ref:push(value)
95+
```
96+
97+
## pop
98+
Generic pop method, if the underlying type supports it, will pop the value from the end of the reference.
99+
100+
| Argument | Type | Description |
101+
| --- | --- | --- |
102+
| `s` | `ReflectReference` | The reference to pop from |
103+
104+
105+
| Return | Description |
106+
| --- | --- |
107+
| `ScriptValue` | The popped value |
108+
109+
```lua
110+
local value = ref:pop()
111+
```
112+
113+
## insert
114+
Generic insert method, if the underlying type supports it, will insert the value at the key.
115+
116+
| Argument | Type | Description |
117+
| --- | --- | --- |
118+
| `key` | `ScriptValue` | The key to insert the value for |
119+
| `value` | `ScriptValue` | The value to insert |
120+
121+
```lua
122+
ref:insert(key, value)
123+
```
124+
125+
## clear
126+
Generic clear method, if the underlying type supports it, will clear the referenced container type.
127+
128+
| Argument | Type | Description |
129+
| --- | --- | --- |
130+
| `s` | `ReflectReference` | The reference to clear |
131+
132+
133+
```lua
134+
ref:clear()
135+
```
136+
137+
## len
138+
Generic length method, if the underlying type supports it, will return the length of the referenced container or length relevant to the type itself (number of fields etc.).
139+
140+
| Argument | Type | Description |
141+
| --- | --- | --- |
142+
| `s` | `ReflectReference` | The reference to get the length of |
143+
144+
145+
| Return | Description |
146+
| --- | --- |
147+
| `usize` | The length |
148+
149+
```lua
150+
length = ref:len()
151+
```
152+
153+
## remove
154+
Generic remove method, if the underlying type supports it, will remove the value at the key.
155+
156+
| Argument | Type | Description |
157+
| --- | --- | --- |
158+
| `key` | `ScriptValue` | The key to remove the value for |
159+
160+
161+
| Return | Description |
162+
| --- | --- |
163+
| `ScriptValue` | The removed value |
164+
165+
```lua
166+
local value = ref:remove(key)
167+
```
168+
169+
## iter
170+
The iterator function, returns a function which can be called to iterate over the reference.
171+
172+
| Argument | Type | Description |
173+
| --- | --- | --- |
174+
| `s` | `ReflectReference` | The reference to iterate over |
175+
176+
177+
| Return | Description |
178+
| --- | --- |
179+
| `ScriptFunctionMut` | The iterator function |
180+
181+
```lua
182+
local iter = ref:iter()
183+
local val = iter()
184+
while val do
185+
print(val)
186+
next = iter()
187+
end
188+
189+
-- same as
190+
for val in pairs(ref) do
191+
print(val)
192+
end
193+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ScriptQueryBuilder
2+
3+
The query builder is used to build queries for entities with specific components. Can be used to interact with arbitrary entities in the world.
4+
5+
## with
6+
7+
| Argument | Type | Description |
8+
| --- | --- | --- |
9+
| `s` | `ScriptQueryBuilder` | The query builder |
10+
| `with` | `ScriptTypeRegistration` | The component to include in the query |
11+
12+
13+
| Return | Description |
14+
| --- | --- |
15+
| `ScriptQueryBuilder` | The updated query builder |
16+
17+
```lua
18+
query:with(MyType):with(MyOtherType)
19+
```
20+
21+
## without
22+
23+
| Argument | Type | Description |
24+
| --- | --- | --- |
25+
| `s` | `ScriptQueryBuilder` | The query builder |
26+
| `without` | `ScriptTypeRegistration` | The component to exclude from the query |
27+
28+
29+
| Return | Description |
30+
| --- | --- |
31+
| `ScriptQueryBuilder` | The updated query builder |
32+
33+
```lua
34+
query:without(MyType):without(MyOtherType)
35+
```
36+
37+
## build
38+
39+
| Argument | Type | Description |
40+
| --- | --- | --- |
41+
| `s` | `ScriptQueryBuilder` | The query builder |
42+
43+
44+
| Return | Description |
45+
| --- | --- |
46+
| `Vec<ScriptQueryResult>` | The query results |
47+
48+
```lua
49+
local results = query.build()
50+
for _, result in pairs(results) do
51+
print(result)
52+
end
53+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ScriptQueryResult
2+
3+
The result of a query, built by the query builder.
4+
5+
## entity
6+
7+
| Argument | Type | Description |
8+
| --- | --- | --- |
9+
| `s` | `ScriptQueryResult` | The query result |
10+
11+
12+
| Return | Description |
13+
| --- | --- |
14+
| `Entity` | The entity |
15+
16+
```lua
17+
local entity = result:entity()
18+
```
19+
20+
## components
21+
22+
| Argument | Type | Description |
23+
| --- | --- | --- |
24+
| `s` | `ScriptQueryResult` | The query result |
25+
26+
27+
| Return | Description |
28+
| --- | --- |
29+
| `Vec<ReflectReference>` | The components |
30+
31+
```lua
32+
for _, component in pairs(result:components()) do
33+
print(component)
34+
end
35+
```
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ScriptTypeRegistration
2+
3+
A reference to a type registration, in general think of this as a handle to a type.
4+
5+
## type_name
6+
7+
| Argument | Type | Description |
8+
| --- | --- | --- |
9+
| `s` | `ScriptTypeRegistration` | The type registration as returned by `get_type_by_name` |
10+
11+
12+
| Return | Description |
13+
| --- | --- |
14+
| `String` | The type name |
15+
16+
```lua
17+
local name = MyType:type_name()
18+
```
19+
20+
## short_name
21+
22+
| Argument | Type | Description |
23+
| --- | --- | --- |
24+
| `s` | `ScriptTypeRegistration` | The type registration as returned by `get_type_by_name` |
25+
26+
27+
| Return | Description |
28+
| --- | --- |
29+
| `String` | The short name |
30+
31+
```lua
32+
local name = MyType:short_name()
33+
```
34+
35+
## is_resource
36+
37+
| Argument | Type | Description |
38+
| --- | --- | --- |
39+
| `s` | `ScriptTypeRegistration` | The type registration as returned by `get_type_by_name` |
40+
41+
42+
| Return | Description |
43+
| --- | --- |
44+
| `bool` | `true` if the type is a resource, otherwise `false` |
45+
46+
```lua
47+
if MyType:is_resource() then
48+
print("MyType is a resource")
49+
end
50+
```
51+
52+
## is_component
53+
54+
| Argument | Type | Description |
55+
| --- | --- | --- |
56+
| `s` | `ScriptTypeRegistration` | The type registration as returned by `get_type_by_name` |
57+
58+
59+
| Return | Description |
60+
| --- | --- |
61+
| `bool` | `true` if the type is a component, otherwise `false` |
62+
63+
```lua
64+
if MyType:is_component() then
65+
print("MyType is a component")
66+
end
67+
```

0 commit comments

Comments
 (0)