Skip to content

Commit c58190c

Browse files
feat: Plugin system refactor (#149)
* migrate work on core improvements from feature/better-trait-system to bevy 0.15 * bring over bevy api gen work * don't check for all std traits being present * bring in bms_lua changes * Finally get a world proxy going for lua ✨ * FIRST PASSING LUA WORLD API TESTS * Lua integration tests with some of the API's working! * Add lua test API and add pass more tests * remove git repo in test_utils * add tests for api availability * remove unused file * make things clone * Fix some tests * more tests * Complete test suite for world methods * re-implement dynamic queries Co-authored-by: Lily <mistrustfully@gmail.com> * Re-implement changes to rhai and rune, and fix event recipients example * update more examples * register option lua types for ALL THE TYPES BABY * register vec lua types FOR ALL THE TYPES BABY * improve type data, and add iterator to reflect ref * WIP --------- Co-authored-by: Lily <mistrustfully@gmail.com>
1 parent b238bfc commit c58190c

File tree

149 files changed

+45586
-2637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+45586
-2637
lines changed

.github/workflows/bevy_mod_scripting.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@ jobs:
2727
strategy:
2828
matrix:
2929
run_args: [
30-
{label: Windows - All Features, os: windows-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: x86_64-pc-windows-msvc },
31-
{label: MacOS - All Features, os: macOS-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: x86_64-apple-darwin },
32-
{label: Ubuntu - All Features, os: ubuntu-latest, features: "lua54,lua_script_api,rhai,teal,rhai_script_api,rune", cross: x86_64-unknown-linux-gnu },
33-
{label: Ubuntu Aarch64 - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: aarch64-unknown-linux-gnu },
34-
{label: Ubuntu - Lua51, os: ubuntu-latest, features: "lua51,lua_script_api", cross: x86_64-unknown-linux-gnu },
35-
{label: Ubuntu - Lua52, os: ubuntu-latest, features: "lua52,lua_script_api", cross: x86_64-unknown-linux-gnu },
36-
{label: Ubuntu - Lua53, os: ubuntu-latest, features: "lua53,lua_script_api", cross: x86_64-unknown-linux-gnu },
37-
{label: Ubuntu - Luajit, os: ubuntu-latest, features: "luajit,lua_script_api", cross: x86_64-unknown-linux-gnu },
38-
{label: Ubuntu - Luajit52, os: ubuntu-latest, features: "luajit52,lua_script_api", cross: x86_64-unknown-linux-gnu },
39-
{label: Ubuntu - Luau, os: ubuntu-latest, features: "luau,lua_script_api", cross: x86_64-unknown-linux-gnu }
40-
30+
{label: Windows - All Features, os: windows-latest, features: "lua54,rhai,teal,rune", cross: x86_64-pc-windows-msvc },
31+
{label: MacOS - All Features, os: macOS-latest, features: "lua54,rhai,teal,rune", cross: x86_64-apple-darwin },
32+
{label: Ubuntu - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,rune", cross: x86_64-unknown-linux-gnu },
33+
{label: Ubuntu Aarch64 - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,rune", cross: aarch64-unknown-linux-gnu },
34+
{label: Ubuntu - Lua51, os: ubuntu-latest, features: "lua51", cross: x86_64-unknown-linux-gnu },
35+
{label: Ubuntu - Lua52, os: ubuntu-latest, features: "lua52", cross: x86_64-unknown-linux-gnu },
36+
{label: Ubuntu - Lua53, os: ubuntu-latest, features: "lua53", cross: x86_64-unknown-linux-gnu },
37+
{label: Ubuntu - Luajit, os: ubuntu-latest, features: "luajit", cross: x86_64-unknown-linux-gnu },
38+
{label: Ubuntu - Luajit52, os: ubuntu-latest, features: "luajit52", cross: x86_64-unknown-linux-gnu },
39+
{label: Ubuntu - Luau, os: ubuntu-latest, features: "luau", cross: x86_64-unknown-linux-gnu }
4140
]
4241
steps:
4342
- if: runner.os == 'linux'
@@ -97,7 +96,7 @@ jobs:
9796
- uses: actions-rs/cargo@v1
9897
with:
9998
command: clippy
100-
args: --features=lua54,rhai,teal,lua_script_api,rhai_script_api,rune --profile=ephemeral-build -- -D warnings
99+
args: --features=lua54,rhai,teal,rune --profile=ephemeral-build -- -D warnings
101100
tests:
102101
name: Tests
103102
runs-on: ubuntu-latest
@@ -117,7 +116,7 @@ jobs:
117116
- uses: actions-rs/cargo@v1
118117
with:
119118
command: test
120-
args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api,rune --profile=ephemeral-build
119+
args: --workspace --features=lua54,rhai,teal,rune --profile=ephemeral-build
121120
docs:
122121
name: Docs
123122
runs-on: ubuntu-latest

.github/workflows/doc_gen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- uses: actions-rs/cargo@v1
3333
with:
3434
command: run
35-
args: --features=lua54,lua_script_api lua
35+
args: --features=lua54 lua
3636
- run: cat ./assets/scripts/doc/tealr_doc_gen_config.json
3737
- name: Push to pages
3838
uses: cpina/github-action-push-to-another-repository@main

.rustfmt.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# max_width = 60
22
# use_small_heuristics = "Max"
33
# format_generated_files = false
4+
5+
reorder_imports = true
6+
# currently unsupported but want them in when stable
7+
imports_granularity = "Crate"
8+
group_imports = "StdExternalCrate"

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"build",
2626
"--example=game_of_life_lua",
2727
"--package=bevy_mod_scripting",
28-
"--features=lua54,teal,lua_script_api",
28+
"--features=lua54,teal",
2929
],
3030
"filter": {
3131
"name": "game_of_life_lua",

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
],
2525
"rust-analyzer.showUnlinkedFileNotification": false,
2626
// "rust-analyzer.semanticHighlighting.operator.enable": false
27-
}
27+
}

.vscode/tasks.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"type": "promptString",
1313
"description": "The crate location of this unit test",
1414
"default": "bevy_mod_scripting"
15+
},
16+
{
17+
"id": "features",
18+
"type": "promptString",
19+
"description": "The features to enable for this unit test",
20+
"default": ""
1521
}
1622
],
1723
"tasks": [
@@ -22,7 +28,8 @@
2228
"args": [
2329
"build_test_in_package",
2430
"PACKAGE=${input:package}",
25-
"TEST_NAME=${input:test_name}"
31+
"TEST_NAME=${input:test_name}",
32+
"TEST_FEATURES=${input:features}"
2633
]
2734
}
2835
]

Cargo.toml

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ name = "bevy_mod_scripting"
2121
path = "src/lib.rs"
2222

2323
[package.metadata."docs.rs"]
24-
features = [
25-
"lua",
26-
"lua54",
27-
"rhai",
28-
"lua_script_api",
29-
"rhai_script_api",
30-
"teal",
31-
"rune",
32-
]
24+
features = ["lua", "lua54", "rhai", "teal", "rune"]
3325

3426
[features]
3527
## core
@@ -47,7 +39,6 @@ luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"]
4739
luau = ["bevy_mod_scripting_lua/luau", "lua"]
4840

4941
# optional
50-
lua_script_api = ["bevy_script_api/lua"]
5142
unsafe_lua_modules = ["bevy_mod_scripting_lua/unsafe_lua_modules"]
5243
teal = ["bevy_mod_scripting_lua/teal"]
5344
mlua_serialize = ["bevy_mod_scripting_lua/mlua_serialize"]
@@ -56,7 +47,6 @@ mlua_async = ["bevy_mod_scripting_lua/mlua_async"]
5647

5748
## rhai
5849
rhai = ["bevy_mod_scripting_rhai"]
59-
rhai_script_api = ["bevy_script_api/rhai"]
6050

6151
## rune
6252
rune = ["bevy_mod_scripting_rune"]
@@ -67,13 +57,13 @@ bevy_mod_scripting_core = { workspace = true }
6757
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.8.0-alpha.2", optional = true }
6858
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.8.0-alpha.2", optional = true }
6959
bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.8.0-alpha.2", optional = true }
70-
bevy_script_api = { path = "crates/bevy_script_api", version = "0.8.0-alpha.2", optional = true }
7160

7261

7362
[workspace.dependencies]
7463
bevy = { version = "0.15.0", default-features = false }
7564
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.8.0-alpha.2" }
7665
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.8.0-alpha.2" }
66+
test_utils = { path = "crates/test_utils" }
7767

7868
[dev-dependencies]
7969
bevy = { workspace = true, default-features = true }
@@ -86,13 +76,14 @@ rhai-rand = "0.1"
8676
members = [
8777
"crates/bevy_mod_scripting_core",
8878
"crates/bevy_event_priority",
89-
"crates/bevy_script_api",
9079
"crates/languages/bevy_mod_scripting_lua",
9180
"crates/languages/bevy_mod_scripting_lua_derive",
9281
"crates/languages/bevy_mod_scripting_rhai",
9382
"crates/languages/bevy_mod_scripting_rhai_derive",
9483
"crates/languages/bevy_mod_scripting_rune",
9584
"crates/bevy_mod_scripting_common",
85+
"crates/bevy_mod_scripting_derive",
86+
"crates/test_utils",
9687
]
9788
resolver = "2"
9889
exclude = ["crates/bevy_api_gen", "crates/macro_tests"]
@@ -117,7 +108,6 @@ name = "console_integration_lua"
117108
path = "examples/lua/console_integration.rs"
118109
required-features = [
119110
"lua54",
120-
"lua_script_api",
121111
"bevy/file_watcher",
122112
"bevy/multi_threaded",
123113
]
@@ -127,7 +117,6 @@ name = "console_integration_rhai"
127117
path = "examples/rhai/console_integration.rs"
128118
required-features = [
129119
"rhai",
130-
"rhai_script_api",
131120
"bevy/file_watcher",
132121
"bevy/multi_threaded",
133122
]
@@ -140,32 +129,22 @@ required-features = ["lua54"]
140129
[[example]]
141130
name = "dynamic_queries_lua"
142131
path = "examples/lua/dynamic_queries.rs"
143-
required-features = ["lua54", "lua_script_api"]
132+
required-features = ["lua54"]
144133

145134
[[example]]
146135
name = "dynamic_queries_rhai"
147136
path = "examples/rhai/dynamic_queries.rs"
148-
required-features = ["rhai", "rhai_script_api"]
137+
required-features = ["rhai"]
149138

150139
[[example]]
151140
name = "game_of_life_lua"
152141
path = "examples/lua/game_of_life.rs"
153-
required-features = [
154-
"lua54",
155-
"lua_script_api",
156-
"bevy/file_watcher",
157-
"bevy/multi_threaded",
158-
]
142+
required-features = ["lua54", "bevy/file_watcher", "bevy/multi_threaded"]
159143

160144
[[example]]
145+
required-features = ["rhai", "bevy/file_watcher", "bevy/multi_threaded"]
161146
name = "game_of_life_rhai"
162147
path = "examples/rhai/game_of_life.rs"
163-
required-features = [
164-
"rhai",
165-
"rhai_script_api",
166-
"bevy/file_watcher",
167-
"bevy/multi_threaded",
168-
]
169148

170149
[[example]]
171150
name = "event_recipients_lua"
@@ -180,22 +159,22 @@ required-features = ["lua54"]
180159
[[example]]
181160
name = "documentation_gen_lua"
182161
path = "examples/lua/documentation_gen.rs"
183-
required-features = ["lua54", "teal", "lua_script_api"]
162+
required-features = ["lua54", "teal"]
184163

185164
[[example]]
186165
name = "bevy_api_lua"
187166
path = "examples/lua/bevy_api.rs"
188-
required-features = ["lua54", "lua_script_api"]
167+
required-features = ["lua54"]
189168

190169
[[example]]
191170
name = "bevy_api_rhai"
192171
path = "examples/rhai/bevy_api.rs"
193-
required-features = ["rhai", "rhai_script_api"]
172+
required-features = ["rhai"]
194173

195174
[[example]]
196175
name = "wrappers"
197176
path = "examples/wrappers.rs"
198-
required-features = ["lua54", "lua_script_api"]
177+
required-features = ["lua54"]
199178

200179
[[example]]
201180
name = "minimal_rune"

assets/scripts/bevy_api.lua

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
function table_to_string(t)
2+
local result = "["
3+
for k,v in pairs(t) do
4+
result = result .. string.format("%s:%s,",k,v)
5+
end
6+
return result .. "]"
7+
end
8+
9+
10+
function on_event()
11+
12+
print(entity)
13+
print(script)
14+
print(world)
15+
16+
17+
local my_component_type = world:get_type_by_name("MyComponent")
18+
19+
local comp = world:get_component(entity, my_component_type)
20+
print("Before script: ", comp)
21+
22+
print("\noption")
23+
print(comp.option_usize)
24+
comp.option_usize = 69
25+
print(comp.option_usize)
26+
comp.option_usize = nil
27+
print(comp.option_usize)
28+
29+
print("\nvec")
30+
print(table_to_string(comp.vec_of_usize))
31+
comp.vec_of_usize = {42,69,72}
32+
comp.vec_of_usize[1] = 0
33+
print(comp.vec_of_usize[2])
34+
print(table_to_string(comp.vec_of_usize))
35+
comp.vec_of_usize = {}
36+
print(table_to_string(comp.vec_of_usize))
37+
comp.vec_of_usize = comp.vec_of_usize2
38+
print(table_to_string(comp.vec_of_usize))
39+
comp.vec_of_usize = comp.vec_of_usize
40+
print(table_to_string(comp.vec_of_usize))
41+
42+
43+
print("============")
44+
45+
-- vec's and matrices have custom __index and __newindex overrides
46+
print("comp.vec2 before: ", comp.vec2)
47+
comp.vec2[1] = 69
48+
print("comp.vec2 after: ", comp.vec2)
49+
50+
-- Option's get converted to nil or the value inside
51+
print("comp.option_vec3 before: ", comp.option_vec3)
52+
comp.option_vec3 = Vec3.new(2,1,3)
53+
print("comp.option_vec3 after: ", comp.option_vec3)
54+
55+
-- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing
56+
print("comp.option_vec3[1] before: ", comp.option_vec3[1])
57+
comp.option_vec3[1] = 5
58+
print("comp.option_vec3[1] after: ", comp.option_vec3[1])
59+
60+
print("============")
61+
62+
-- Vec<T> references get converted to a custom proxy `LuaVec<T>` which is
63+
-- also assignable via lua tables
64+
65+
print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools))
66+
comp.vec_of_option_bools = {true,false,true}
67+
print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools))
68+
69+
print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1])
70+
comp.vec_of_option_bools[1] = false
71+
print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1])
72+
73+
-- there are some additional methods available on LuaVec proxies imitating the Vec<T> api
74+
print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools))
75+
comp.vec_of_option_bools:insert(1,nil)
76+
print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools))
77+
78+
print("comp.vec_of_option_bools before push: ", table_to_string(comp.vec_of_option_bools))
79+
comp.vec_of_option_bools:push(false)
80+
print("comp.vec_of_option_bools after push: ", table_to_string(comp.vec_of_option_bools))
81+
82+
print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools)
83+
84+
print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools))
85+
print(comp.vec_of_option_bools:pop())
86+
print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools))
87+
88+
print("the pairs inside comp.vec_of_option_bools: ")
89+
for k,v in pairs(comp.vec_of_option_bools) do
90+
print(string.format(" - %s:%s",k,v))
91+
end
92+
93+
comp.vec_of_option_bools:clear()
94+
print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools))
95+
96+
print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools)
97+
print("============")
98+
99+
print("comp.option_vec_of_bools before: ", table_to_string(comp.option_vec_of_bools))
100+
print(comp.option_vec_of_bools:pop())
101+
print("comp.option_vec_of_bools after pop: ", table_to_string(comp.option_vec_of_bools))
102+
103+
104+
print("comp.option_vec_of_bools len after pop: ", #comp.option_vec_of_bools)
105+
106+
print("the pairs inside comp.option_vec_of_bools: ")
107+
for k,v in pairs(comp.option_vec_of_bools) do
108+
print(string.format(" - %s:%s",k,v))
109+
end
110+
111+
print("============")
112+
113+
local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis
114+
print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op)
115+
116+
local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1))
117+
print("new_mat3 is:", new_mat3)
118+
119+
comp.vec2 = comp.vec2 + comp.vec2
120+
comp.usize = comp.vec2:min_element()
121+
comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element()
122+
comp.vec2 = Vec2.new(2,1)
123+
comp.quat = Quat.from_xyzw(3,2,1,4)
124+
comp.mat3.x_axis = Vec3.new(69,69,69)
125+
126+
print("============")
127+
128+
-- this is an example of something impossible to achieve with plain bevy reflection under the hood
129+
comp.mat3[1][1] = 42
130+
131+
-- now let's retrieve these again to see if we actually changed their values permanently
132+
comp = world:get_component(entity,my_component_type)
133+
134+
print("After script:")
135+
print(comp)
136+
137+
world:exit()
138+
end

0 commit comments

Comments
 (0)