Skip to content

feat: Plugin system refactor #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
16f4652
migrate work on core improvements from feature/better-trait-system to…
makspll Nov 10, 2024
1eb98b4
bring over bevy api gen work
makspll Nov 10, 2024
44f66c3
don't check for all std traits being present
makspll Nov 10, 2024
1a783f3
bring in bms_lua changes
makspll Nov 10, 2024
2959959
Finally get a world proxy going for lua :sparkles:
makspll Nov 13, 2024
37eb231
FIRST PASSING LUA WORLD API TESTS
makspll Nov 13, 2024
8a36f8f
Lua integration tests with some of the API's working!
makspll Nov 14, 2024
8c16d8c
Add lua test API and add pass more tests
makspll Nov 14, 2024
19985af
remove git repo in test_utils
makspll Nov 14, 2024
01dcf8e
add tests for api availability
makspll Nov 14, 2024
0f64852
remove unused file
makspll Nov 14, 2024
9022289
make things clone
makspll Nov 14, 2024
691b02b
Fix some tests
makspll Nov 14, 2024
b9ca2b0
more tests
makspll Nov 14, 2024
21e3333
Complete test suite for world methods
makspll Nov 15, 2024
0b9e277
re-implement dynamic queries
makspll Nov 15, 2024
debaa16
Re-implement changes to rhai and rune, and fix event recipients example
makspll Nov 19, 2024
1f329aa
update more examples
makspll Nov 19, 2024
d1f37a8
register option lua types for ALL THE TYPES BABY
makspll Nov 24, 2024
60857bb
register vec lua types FOR ALL THE TYPES BABY
makspll Nov 25, 2024
e347a8b
improve type data, and add iterator to reflect ref
makspll Dec 1, 2024
5f34f88
WIP
makspll Dec 2, 2024
48cc5b8
Merge branch 'staging' into feature/bevy-system-refactor
makspll Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions .github/workflows/bevy_mod_scripting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ jobs:
strategy:
matrix:
run_args: [
{label: Windows - All Features, os: windows-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: x86_64-pc-windows-msvc },
{label: MacOS - All Features, os: macOS-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: x86_64-apple-darwin },
{label: Ubuntu - All Features, os: ubuntu-latest, features: "lua54,lua_script_api,rhai,teal,rhai_script_api,rune", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu Aarch64 - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: aarch64-unknown-linux-gnu },
{label: Ubuntu - Lua51, os: ubuntu-latest, features: "lua51,lua_script_api", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Lua52, os: ubuntu-latest, features: "lua52,lua_script_api", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Lua53, os: ubuntu-latest, features: "lua53,lua_script_api", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Luajit, os: ubuntu-latest, features: "luajit,lua_script_api", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Luajit52, os: ubuntu-latest, features: "luajit52,lua_script_api", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Luau, os: ubuntu-latest, features: "luau,lua_script_api", cross: x86_64-unknown-linux-gnu }

{label: Windows - All Features, os: windows-latest, features: "lua54,rhai,teal,rune", cross: x86_64-pc-windows-msvc },
{label: MacOS - All Features, os: macOS-latest, features: "lua54,rhai,teal,rune", cross: x86_64-apple-darwin },
{label: Ubuntu - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,rune", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu Aarch64 - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,rune", cross: aarch64-unknown-linux-gnu },
{label: Ubuntu - Lua51, os: ubuntu-latest, features: "lua51", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Lua52, os: ubuntu-latest, features: "lua52", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Lua53, os: ubuntu-latest, features: "lua53", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Luajit, os: ubuntu-latest, features: "luajit", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Luajit52, os: ubuntu-latest, features: "luajit52", cross: x86_64-unknown-linux-gnu },
{label: Ubuntu - Luau, os: ubuntu-latest, features: "luau", cross: x86_64-unknown-linux-gnu }
]
steps:
- if: runner.os == 'linux'
Expand Down Expand Up @@ -97,7 +96,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --features=lua54,rhai,teal,lua_script_api,rhai_script_api,rune --profile=ephemeral-build -- -D warnings
args: --features=lua54,rhai,teal,rune --profile=ephemeral-build -- -D warnings
tests:
name: Tests
runs-on: ubuntu-latest
Expand All @@ -117,7 +116,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api,rune --profile=ephemeral-build
args: --workspace --features=lua54,rhai,teal,rune --profile=ephemeral-build
docs:
name: Docs
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc_gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: run
args: --features=lua54,lua_script_api lua
args: --features=lua54 lua
- run: cat ./assets/scripts/doc/tealr_doc_gen_config.json
- name: Push to pages
uses: cpina/github-action-push-to-another-repository@main
Expand Down
5 changes: 5 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# max_width = 60
# use_small_heuristics = "Max"
# format_generated_files = false

reorder_imports = true
# currently unsupported but want them in when stable
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build",
"--example=game_of_life_lua",
"--package=bevy_mod_scripting",
"--features=lua54,teal,lua_script_api",
"--features=lua54,teal",
],
"filter": {
"name": "game_of_life_lua",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
],
"rust-analyzer.showUnlinkedFileNotification": false,
// "rust-analyzer.semanticHighlighting.operator.enable": false
}
}
9 changes: 8 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"type": "promptString",
"description": "The crate location of this unit test",
"default": "bevy_mod_scripting"
},
{
"id": "features",
"type": "promptString",
"description": "The features to enable for this unit test",
"default": ""
}
],
"tasks": [
Expand All @@ -22,7 +28,8 @@
"args": [
"build_test_in_package",
"PACKAGE=${input:package}",
"TEST_NAME=${input:test_name}"
"TEST_NAME=${input:test_name}",
"TEST_FEATURES=${input:features}"
]
}
]
Expand Down
45 changes: 12 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ name = "bevy_mod_scripting"
path = "src/lib.rs"

[package.metadata."docs.rs"]
features = [
"lua",
"lua54",
"rhai",
"lua_script_api",
"rhai_script_api",
"teal",
"rune",
]
features = ["lua", "lua54", "rhai", "teal", "rune"]

[features]
## core
Expand All @@ -47,7 +39,6 @@ luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"]
luau = ["bevy_mod_scripting_lua/luau", "lua"]

# optional
lua_script_api = ["bevy_script_api/lua"]
unsafe_lua_modules = ["bevy_mod_scripting_lua/unsafe_lua_modules"]
teal = ["bevy_mod_scripting_lua/teal"]
mlua_serialize = ["bevy_mod_scripting_lua/mlua_serialize"]
Expand All @@ -56,7 +47,6 @@ mlua_async = ["bevy_mod_scripting_lua/mlua_async"]

## rhai
rhai = ["bevy_mod_scripting_rhai"]
rhai_script_api = ["bevy_script_api/rhai"]

## rune
rune = ["bevy_mod_scripting_rune"]
Expand All @@ -67,13 +57,13 @@ bevy_mod_scripting_core = { workspace = true }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.8.0-alpha.2", optional = true }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.8.0-alpha.2", optional = true }
bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.8.0-alpha.2", optional = true }
bevy_script_api = { path = "crates/bevy_script_api", version = "0.8.0-alpha.2", optional = true }


[workspace.dependencies]
bevy = { version = "0.15.0", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.8.0-alpha.2" }
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.8.0-alpha.2" }
test_utils = { path = "crates/test_utils" }

[dev-dependencies]
bevy = { workspace = true, default-features = true }
Expand All @@ -86,13 +76,14 @@ rhai-rand = "0.1"
members = [
"crates/bevy_mod_scripting_core",
"crates/bevy_event_priority",
"crates/bevy_script_api",
"crates/languages/bevy_mod_scripting_lua",
"crates/languages/bevy_mod_scripting_lua_derive",
"crates/languages/bevy_mod_scripting_rhai",
"crates/languages/bevy_mod_scripting_rhai_derive",
"crates/languages/bevy_mod_scripting_rune",
"crates/bevy_mod_scripting_common",
"crates/bevy_mod_scripting_derive",
"crates/test_utils",
]
resolver = "2"
exclude = ["crates/bevy_api_gen", "crates/macro_tests"]
Expand All @@ -117,7 +108,6 @@ name = "console_integration_lua"
path = "examples/lua/console_integration.rs"
required-features = [
"lua54",
"lua_script_api",
"bevy/file_watcher",
"bevy/multi_threaded",
]
Expand All @@ -127,7 +117,6 @@ name = "console_integration_rhai"
path = "examples/rhai/console_integration.rs"
required-features = [
"rhai",
"rhai_script_api",
"bevy/file_watcher",
"bevy/multi_threaded",
]
Expand All @@ -140,32 +129,22 @@ required-features = ["lua54"]
[[example]]
name = "dynamic_queries_lua"
path = "examples/lua/dynamic_queries.rs"
required-features = ["lua54", "lua_script_api"]
required-features = ["lua54"]

[[example]]
name = "dynamic_queries_rhai"
path = "examples/rhai/dynamic_queries.rs"
required-features = ["rhai", "rhai_script_api"]
required-features = ["rhai"]

[[example]]
name = "game_of_life_lua"
path = "examples/lua/game_of_life.rs"
required-features = [
"lua54",
"lua_script_api",
"bevy/file_watcher",
"bevy/multi_threaded",
]
required-features = ["lua54", "bevy/file_watcher", "bevy/multi_threaded"]

[[example]]
required-features = ["rhai", "bevy/file_watcher", "bevy/multi_threaded"]
name = "game_of_life_rhai"
path = "examples/rhai/game_of_life.rs"
required-features = [
"rhai",
"rhai_script_api",
"bevy/file_watcher",
"bevy/multi_threaded",
]

[[example]]
name = "event_recipients_lua"
Expand All @@ -180,22 +159,22 @@ required-features = ["lua54"]
[[example]]
name = "documentation_gen_lua"
path = "examples/lua/documentation_gen.rs"
required-features = ["lua54", "teal", "lua_script_api"]
required-features = ["lua54", "teal"]

[[example]]
name = "bevy_api_lua"
path = "examples/lua/bevy_api.rs"
required-features = ["lua54", "lua_script_api"]
required-features = ["lua54"]

[[example]]
name = "bevy_api_rhai"
path = "examples/rhai/bevy_api.rs"
required-features = ["rhai", "rhai_script_api"]
required-features = ["rhai"]

[[example]]
name = "wrappers"
path = "examples/wrappers.rs"
required-features = ["lua54", "lua_script_api"]
required-features = ["lua54"]

[[example]]
name = "minimal_rune"
Expand Down
138 changes: 138 additions & 0 deletions assets/scripts/bevy_api.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
function table_to_string(t)
local result = "["
for k,v in pairs(t) do
result = result .. string.format("%s:%s,",k,v)
end
return result .. "]"
end


function on_event()

print(entity)
print(script)
print(world)


local my_component_type = world:get_type_by_name("MyComponent")

local comp = world:get_component(entity, my_component_type)
print("Before script: ", comp)

print("\noption")
print(comp.option_usize)
comp.option_usize = 69
print(comp.option_usize)
comp.option_usize = nil
print(comp.option_usize)

print("\nvec")
print(table_to_string(comp.vec_of_usize))
comp.vec_of_usize = {42,69,72}
comp.vec_of_usize[1] = 0
print(comp.vec_of_usize[2])
print(table_to_string(comp.vec_of_usize))
comp.vec_of_usize = {}
print(table_to_string(comp.vec_of_usize))
comp.vec_of_usize = comp.vec_of_usize2
print(table_to_string(comp.vec_of_usize))
comp.vec_of_usize = comp.vec_of_usize
print(table_to_string(comp.vec_of_usize))


print("============")

-- vec's and matrices have custom __index and __newindex overrides
print("comp.vec2 before: ", comp.vec2)
comp.vec2[1] = 69
print("comp.vec2 after: ", comp.vec2)

-- Option's get converted to nil or the value inside
print("comp.option_vec3 before: ", comp.option_vec3)
comp.option_vec3 = Vec3.new(2,1,3)
print("comp.option_vec3 after: ", comp.option_vec3)

-- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing
print("comp.option_vec3[1] before: ", comp.option_vec3[1])
comp.option_vec3[1] = 5
print("comp.option_vec3[1] after: ", comp.option_vec3[1])

print("============")

-- Vec<T> references get converted to a custom proxy `LuaVec<T>` which is
-- also assignable via lua tables

print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools))
comp.vec_of_option_bools = {true,false,true}
print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools))

print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1])
comp.vec_of_option_bools[1] = false
print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1])

-- there are some additional methods available on LuaVec proxies imitating the Vec<T> api
print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools))
comp.vec_of_option_bools:insert(1,nil)
print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools))

print("comp.vec_of_option_bools before push: ", table_to_string(comp.vec_of_option_bools))
comp.vec_of_option_bools:push(false)
print("comp.vec_of_option_bools after push: ", table_to_string(comp.vec_of_option_bools))

print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools)

print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools))
print(comp.vec_of_option_bools:pop())
print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools))

print("the pairs inside comp.vec_of_option_bools: ")
for k,v in pairs(comp.vec_of_option_bools) do
print(string.format(" - %s:%s",k,v))
end

comp.vec_of_option_bools:clear()
print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools))

print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools)
print("============")

print("comp.option_vec_of_bools before: ", table_to_string(comp.option_vec_of_bools))
print(comp.option_vec_of_bools:pop())
print("comp.option_vec_of_bools after pop: ", table_to_string(comp.option_vec_of_bools))


print("comp.option_vec_of_bools len after pop: ", #comp.option_vec_of_bools)

print("the pairs inside comp.option_vec_of_bools: ")
for k,v in pairs(comp.option_vec_of_bools) do
print(string.format(" - %s:%s",k,v))
end

print("============")

local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis
print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op)

local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1))
print("new_mat3 is:", new_mat3)

comp.vec2 = comp.vec2 + comp.vec2
comp.usize = comp.vec2:min_element()
comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element()
comp.vec2 = Vec2.new(2,1)
comp.quat = Quat.from_xyzw(3,2,1,4)
comp.mat3.x_axis = Vec3.new(69,69,69)

print("============")

-- this is an example of something impossible to achieve with plain bevy reflection under the hood
comp.mat3[1][1] = 42

-- now let's retrieve these again to see if we actually changed their values permanently
comp = world:get_component(entity,my_component_type)

print("After script:")
print(comp)

world:exit()
end
Loading
Loading