Skip to content

Commit

Permalink
Add Bevy 0.11 support (#63)
Browse files Browse the repository at this point in the history
* Begin bevy version migration

* WIP, correct api gen, TODO: examples

* Migrate complex_game_loop example

* tweak docs and public API

* fix some migration issues, migrate bevy_api, move all reflection indexing on lua side to 1-based

* Migrate examples, untested

* migrate rhai examples untested

* Fix examples

* Further improvements to examples

* fix wrappers.rs issue

* clippy fixes

* clippy fixes

* clippy fixes

* fix typos and doctests

* cargo fmt fixes
  • Loading branch information
makspll authored Aug 24, 2023
1 parent 11cbdd8 commit 8bf3796
Show file tree
Hide file tree
Showing 44 changed files with 2,241 additions and 1,170 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ rhai = ["bevy_mod_scripting_rhai"]
rhai_script_api=["bevy_script_api/rhai"]

[dependencies]
bevy = { version = "0.10.1", default-features = false}
bevy = { version = "0.11", default-features = false}
bevy_mod_scripting_core = { path = "bevy_mod_scripting_core", version = "0.3.0" }
bevy_mod_scripting_lua = { path = "languages/bevy_mod_scripting_lua", version = "0.3.0", optional = true }
bevy_mod_scripting_rhai = { path = "languages/bevy_mod_scripting_rhai", version = "0.3.0", optional = true}
bevy_script_api = { path = "bevy_script_api", version = "0.3.0", optional = true }

[dev-dependencies]
bevy = { version = "0.10.1"}
bevy = { version = "0.11"}
clap = { version = "4.1", features = ["derive"]}
rand = "0.8.5"
bevy_console = "0.7.0"
bevy_console = "0.8.0"
rhai-rand = "0.1"

[workspace]
Expand Down
88 changes: 42 additions & 46 deletions api_gen_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use {
tealr::mlu::mlua::MetaMethod,
docs::LuaDocFragment
},
crate::{common::bevy::GetWorld, lua::{RegisterForeignLuaType}},
crate::{common::bevy::GetWorld, lua::{RegisterForeignLuaType, util::LuaIndex}},
};
use std::ops::*;
use crate::{script_ref::{ReflectedValue,ValueIndex},
sub_reflect::ReflectPathElem,
error::ReflectionError
error::ReflectionError,
};
use std::sync::Mutex;
use bevy_mod_scripting_core::prelude::*;
Expand Down Expand Up @@ -145,10 +145,6 @@ source="bevy_ui"
type="CalculatedClip"
source="bevy_ui"

[[types]]
type="CalculatedSize"
source="bevy_ui"

[[types]]
type="Node"
source="bevy_ui"
Expand Down Expand Up @@ -493,26 +489,26 @@ source="bevy_asset"
type="Vec2"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,f32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::f32::Vec2"

[[types]]
type="Vec3"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,f32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::f32::Vec3"

[[types]]
type="Vec3A"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,f32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::f32::Vec3A"

Expand All @@ -521,8 +517,8 @@ import_path="glam::f32::Vec3A"
type="Vec4"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,f32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::f32::Vec4"

Expand Down Expand Up @@ -555,80 +551,80 @@ import_path="glam::bool::BVec4A"
type="DVec2"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,f64)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::f64::DVec2"

[[types]]
type="DVec3"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,f64)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::f64::DVec3"

[[types]]
type="DVec4"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,f64)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::f64::DVec4"

[[types]]
type="IVec2"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,i32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::i32::IVec2"

[[types]]
type="IVec3"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,i32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::i32::IVec3"

[[types]]
type="IVec4"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,i32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::i32::IVec4"

[[types]]
type="UVec2"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,u32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::u32::UVec2"

[[types]]
type="UVec3"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,u32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::u32::UVec3"

[[types]]
type="UVec4"
source="bevy_math"
lua_methods=[
"(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}"
"(MetaMethod::Index) => |_,s,idx: LuaIndex| {Ok(s.inner()?[*idx])}",
"mut (MetaMethod::NewIndex) => |_,s,(idx,val): (LuaIndex,u32)| {s.val_mut(|s| Ok(s[*idx] = val))?}"
]
import_path="glam::u32::UVec4"

Expand All @@ -637,11 +633,11 @@ type="Mat3"
source="bevy_math"
lua_methods=[
"""
mut (MetaMethod::Index) => |ctx,s,idx : usize| {
mut (MetaMethod::Index) => |ctx,s,idx : LuaIndex| {
Ok(LuaVec3::new_ref(
s.script_ref(ctx.get_world()?).sub_ref(ReflectPathElem::SubReflectionIndexed{
label:"col",
index: idx,
index: *idx,
get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{
path: "".to_owned(),
msg: "Cannot get column of matrix with immutable reference".to_owned()
Expand All @@ -668,11 +664,11 @@ type="Mat2"
source="bevy_math"
lua_methods=[
"""
mut (MetaMethod::Index) => |ctx,s,idx : usize| {
mut (MetaMethod::Index) => |ctx,s,idx : LuaIndex| {
Ok(LuaVec2::new_ref(
s.script_ref(ctx.get_world()?).sub_ref(ReflectPathElem::SubReflectionIndexed{
label:"col",
index: idx,
index: *idx,
get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{
path: "".to_owned(),
msg: "Cannot get column of matrix with immutable reference".to_owned()
Expand Down Expand Up @@ -700,11 +696,11 @@ type="Mat3A"
source="bevy_math"
lua_methods=[
"""
mut (MetaMethod::Index) => |ctx,s,idx : usize| {
mut (MetaMethod::Index) => |ctx,s,idx : LuaIndex| {
Ok(LuaVec3A::new_ref(
s.script_ref(ctx.get_world()?).sub_ref(ReflectPathElem::SubReflectionIndexed{
label:"col",
index: idx,
index: *idx,
get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{
path: "".to_owned(),
msg: "Cannot get column of matrix with immutable reference".to_owned()
Expand All @@ -731,11 +727,11 @@ type="Mat4"
source="bevy_math"
lua_methods=[
"""
mut (MetaMethod::Index) => |ctx,s,idx : usize| {
mut (MetaMethod::Index) => |ctx,s,idx : LuaIndex| {
Ok(LuaVec4::new_ref(
s.script_ref(ctx.get_world()?).sub_ref(ReflectPathElem::SubReflectionIndexed{
label:"col",
index: idx,
index: *idx,
get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{
path: "".to_owned(),
msg: "Cannot get column of matrix with immutable reference".to_owned()
Expand Down Expand Up @@ -763,11 +759,11 @@ type="DMat2"
source="bevy_math"
lua_methods=[
"""
mut (MetaMethod::Index) => |ctx,s,idx : usize| {
mut (MetaMethod::Index) => |ctx,s,idx : LuaIndex| {
Ok(LuaDVec2::new_ref(
s.script_ref(ctx.get_world()?).sub_ref(ReflectPathElem::SubReflectionIndexed{
label:"col",
index: idx,
index: *idx,
get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{
path: "".to_owned(),
msg: "Cannot get column of matrix with immutable reference".to_owned()
Expand All @@ -794,11 +790,11 @@ type="DMat3"
source="bevy_math"
lua_methods=[
"""
mut (MetaMethod::Index) => |ctx,s,idx : usize| {
mut (MetaMethod::Index) => |ctx,s,idx : LuaIndex| {
Ok(LuaDVec3::new_ref(
s.script_ref(ctx.get_world()?).sub_ref(ReflectPathElem::SubReflectionIndexed{
label:"col",
index: idx,
index: *idx,
get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{
path: "".to_owned(),
msg: "Cannot get column of matrix with immutable reference".to_owned()
Expand All @@ -825,11 +821,11 @@ type="DMat4"
source="bevy_math"
lua_methods=[
"""
mut (MetaMethod::Index) => |ctx,s,idx : usize| {
mut (MetaMethod::Index) => |ctx,s,idx : LuaIndex| {
Ok(LuaDVec4::new_ref(
s.script_ref(ctx.get_world()?).sub_ref(ReflectPathElem::SubReflectionIndexed{
label:"col",
index: idx,
index: *idx,
get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{
path: "".to_owned(),
msg: "Cannot get column of matrix with immutable reference".to_owned()
Expand Down
26 changes: 6 additions & 20 deletions assets/scripts/complex_game_loop.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@


function on_pre_physics_one(id)
print("on_pre_physics_one, Handling:")
function on_pre_physics(id)
print("on_pre_physics, Handling:")
print(string.format("\t-> id: %d",id))
end

function on_pre_physics_two(id)
print("on_pre_physics_two, Handling:")
print(string.format("\t-> id: %d",id))
end

function on_post_physics_one(id)
print("on_post_physics_one, Handling:")
function on_post_physics(id)
print("on_post_physics, Handling:")
print(string.format("\t-> id: %d",id))
end

function on_post_physics_two(id)
print("on_post_physics_two, Handling:")
print(string.format("\t-> id: %d",id))
end

function on_post_update_one(id)
print("on_post_update_one, Handling:")
function on_post_update(id)
print("on_post_update, Handling:")
print(string.format("\t-> id: %d",id))
end

function on_post_update_two(id)
print("on_post_update_two, Handling:")
print(string.format("\t-> id: %d",id))
end
14 changes: 7 additions & 7 deletions assets/scripts/game_of_life.tl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ global function on_update()
prev_state[k] = (not(v == 0)) and 1 or 0
end

for i=1,(dimensions[0] * dimensions[1]) do
local north = prev_state[i - dimensions[0]] or 1
local south = prev_state[i + dimensions[0]] or 1
for i=1,(dimensions[1] * dimensions[2]) do
local north = prev_state[i - dimensions[1]] or 1
local south = prev_state[i + dimensions[1]] or 1
local east = prev_state[i + 1] or 1
local west = prev_state[i - 1] or 1
local northeast = prev_state[i - dimensions[0] + 1] or 1
local southeast = prev_state[i + dimensions[0] + 1] or 1
local northwest = prev_state[i - dimensions[0] - 1] or 1
local southwest = prev_state[i + dimensions[0] - 1] or 1
local northeast = prev_state[i - dimensions[1] + 1] or 1
local southeast = prev_state[i + dimensions[1] + 1] or 1
local northwest = prev_state[i - dimensions[1] - 1] or 1
local southwest = prev_state[i + dimensions[1] - 1] or 1

local neighbours = north + south + east + west
+ northeast + southeast + northwest + southwest
Expand Down
2 changes: 1 addition & 1 deletion bevy_api_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ path = "src/main.rs"


[dependencies]
rustdoc-types = "0.19.0"
rustdoc-types = "0.22.0"
clap = { version = "3.2.6", features = ["derive"] }
serde_json = "1.0.81"
toml = "0.5.9"
Expand Down
2 changes: 0 additions & 2 deletions bevy_api_gen/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashSet;

use clap::Parser;
use indexmap::{IndexMap, IndexSet};
use rustdoc_types::{Crate, Item, ItemEnum, Visibility};
Expand Down
2 changes: 1 addition & 1 deletion bevy_event_priority/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ name = "bevy_event_priority"
path = "src/lib.rs"

[dependencies]
bevy = { version = "0.10.1", default-features = false}
bevy = { version = "0.11", default-features = false}

Loading

0 comments on commit 8bf3796

Please sign in to comment.