diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7844cf4c..3a8e60ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,8 @@ jobs: profile: minimal toolchain: stable override: true - - uses: Swatinem/rust-cache@v2.7.0 + - name: Rust Cache + uses: Swatinem/rust-cache@v2.7.3 # for x86 builds - if: matrix.run_args.cross == null uses: actions-rs/cargo@v1 @@ -47,7 +48,7 @@ jobs: with: command: check target: ${{ matrix.run_args.cross }} - args: --workspace --features=${{ matrix.run_args.lua }},rhai,teal,lua_script_api,rhai_script_api + args: --workspace --features=${{ matrix.run_args.lua }},rhai,teal,lua_script_api,rhai_script_api --profile=ephemeral-build fmt: name: Rustfmt @@ -62,7 +63,8 @@ jobs: components: rustfmt toolchain: stable override: true - - uses: Swatinem/rust-cache@v2.7.0 + - name: Rust Cache + uses: Swatinem/rust-cache@v2.7.3 - uses: actions-rs/cargo@v1 with: command: fmt @@ -80,11 +82,12 @@ jobs: toolchain: stable components: clippy override: true - - uses: Swatinem/rust-cache@v2.7.0 + - name: Rust Cache + uses: Swatinem/rust-cache@v2.7.3 - uses: actions-rs/cargo@v1 with: command: clippy - args: --features=lua54,rhai,teal,lua_script_api,rhai_script_api -- -D warnings + args: --features=lua54,rhai,teal,lua_script_api,rhai_script_api --profile=ephemeral-build -- -D warnings tests: name: Tests runs-on: ubuntu-latest @@ -108,11 +111,12 @@ jobs: with: toolchain: stable override: true - - uses: Swatinem/rust-cache@v2.7.0 + - name: Rust Cache + uses: Swatinem/rust-cache@v2.7.3 - uses: actions-rs/cargo@v1 with: command: test - args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api + args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api --profile=ephemeral-build docs: name: Docs runs-on: ubuntu-latest @@ -124,11 +128,12 @@ jobs: with: toolchain: stable override: true - - uses: Swatinem/rust-cache@v2.7.0 + - name: Rust Cache + uses: Swatinem/rust-cache@v2.7.3 - name: Find docs.rs features run: echo "DOCS_FEATURES=$(cargo metadata --no-deps | python -c "import sys,json; [print(','.join(x['metadata']['docs.rs']['features'])) for x in json.load(sys.stdin)['packages'] if x['name'] == 'bevy_mod_scripting']")" >> $GITHUB_OUTPUT id: features - uses: actions-rs/cargo@v1 with: command: doc - args: --workspace --features=${{ steps.features.outputs.DOCS_FEATURES }} + args: --workspace --features=${{ steps.features.outputs.DOCS_FEATURES }} --profile=ephemeral-build diff --git a/Cargo.toml b/Cargo.toml index 948a4ef5..e60d3228 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,6 +93,11 @@ opt-level = 1 [profile.dev.package."*"] opt-level = 3 +[profile.ephemeral-build] +inherits = "dev" +opt-level = 2 +codegen-units = 8 + [[example]] name = "console_integration_lua" diff --git a/bevy_script_api/src/lua/bevy/mod.rs b/bevy_script_api/src/lua/bevy/mod.rs index 32d29d70..d9fc339a 100644 --- a/bevy_script_api/src/lua/bevy/mod.rs +++ b/bevy_script_api/src/lua/bevy/mod.rs @@ -1,5 +1,5 @@ use crate::common::bevy::{ScriptTypeRegistration, ScriptWorld}; -use crate::impl_tealr_type; +use crate::{impl_from_lua_with_clone, impl_tealr_type}; use std::sync::Arc; @@ -21,6 +21,7 @@ use super::util::LuaIndex; pub type LuaTypeRegistration = ScriptTypeRegistration; impl_tealr_type!(LuaTypeRegistration); +impl_from_lua_with_clone!(LuaTypeRegistration); impl TealData for LuaTypeRegistration { fn add_methods<'lua, T: TealDataMethods<'lua, Self>>(methods: &mut T) { @@ -66,6 +67,7 @@ impl TealData for LuaScriptData { pub type LuaWorld = ScriptWorld; impl_tealr_type!(LuaWorld); +impl_from_lua_with_clone!(LuaWorld); impl TealData for LuaWorld { fn add_methods<'lua, T: TealDataMethods<'lua, Self>>(methods: &mut T) { diff --git a/bevy_script_api/src/lua/mod.rs b/bevy_script_api/src/lua/mod.rs index c3fc0fa8..5114e93c 100644 --- a/bevy_script_api/src/lua/mod.rs +++ b/bevy_script_api/src/lua/mod.rs @@ -2,20 +2,19 @@ use ::std::any::TypeId; use ::std::borrow::Cow; use crate::common::bevy::GetWorld; -use crate::impl_tealr_type; +use crate::{impl_from_lua_with_clone, impl_tealr_type}; use ::bevy::prelude::{App, AppTypeRegistry}; use ::bevy::reflect::{FromType, GetTypeRegistration, Reflect}; use bevy_mod_scripting_core::world::WorldPointer; -use bevy_mod_scripting_lua::tealr; +use bevy_mod_scripting_lua::tealr::{self, ToTypename}; use tealr::mlu::mlua::MetaMethod; use tealr::mlu::{ - mlua::{self, FromLua, Lua, ToLua, UserData, Value}, + mlua::{self, FromLua, IntoLua, Lua, UserData, Value}, TealData, TealDataMethods, }; -use tealr::TypeName; use crate::script_ref::{ReflectedValue, ScriptRef, ValueIndex}; @@ -126,13 +125,13 @@ impl ApplyLua for ScriptRef { } } -impl<'lua> ToLua<'lua> for ScriptRef { +impl<'lua> IntoLua<'lua> for ScriptRef { /// Converts the LuaRef to the most convenient representation /// checking conversions in this order: /// - A primitive or bevy type which has a reflect interface is converted to a custom UserData exposing its API to lua conveniently /// - A type implementing CustomUserData is converted with its `ref_to_lua` method /// - Finally the method is represented as a `ReflectedValue` which exposes the Reflect interface - fn to_lua(self, ctx: &'lua Lua) -> mlua::Result> { + fn into_lua(self, ctx: &'lua Lua) -> mlua::Result> { let world = self.world_ptr.clone(); let world = world.read(); @@ -143,26 +142,19 @@ impl<'lua> ToLua<'lua> for ScriptRef { if let Some(v) = g.get_type_data::(type_id) { v.ref_to_lua(self, ctx) } else { - ReflectedValue { ref_: self }.to_lua(ctx) + ReflectedValue { ref_: self }.into_lua(ctx) } } } -impl TypeName for ScriptRef { - /// ReflectedValue represents the "lowest common denominator" across the possible returned types - /// people can always use 'as' to cast to the right type - /// but the static analysis will be conservative, i.e. the compiler will assume the smallest set of functionality - /// by default - fn get_type_parts() -> Cow<'static, [tealr::NamePart]> { - Cow::Borrowed(&[tealr::NamePart::Type(tealr::TealType { - name: Cow::Borrowed("ReflectedValue"), - generics: None, - type_kind: tealr::KindOfType::Builtin, - })]) +impl ToTypename for ScriptRef { + fn to_typename() -> tealr::Type { + tealr::Type::new_single("ReflectedValue", tealr::KindOfType::External) } } impl_tealr_type!(ReflectedValue); +impl_from_lua_with_clone!(ReflectedValue); impl TealData for ReflectedValue { fn add_methods<'lua, T: TealDataMethods<'lua, Self>>(methods: &mut T) { methods.document_type("This type represents a generic reflected value."); @@ -266,7 +258,7 @@ pub trait ValueLuaType {} impl LuaProxyable for T { fn ref_to_lua(self_: ScriptRef, lua: &Lua) -> mlua::Result { - self_.get_typed(|s: &Self| s.clone().to_lua(lua))? + self_.get_typed(|s: &Self| s.clone().into_lua(lua))? } fn apply_lua<'lua>( @@ -288,7 +280,9 @@ impl LuaProxyable } } -impl<'lua, T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> FromLuaProxy<'lua> for T { +impl<'lua, T: Clone + UserData + FromLua<'lua> + Send + ValueLuaType + Reflect + 'static> + FromLuaProxy<'lua> for T +{ fn from_lua_proxy(new_val: Value<'lua>, lua: &'lua Lua) -> mlua::Result { T::from_lua(new_val, lua) } @@ -296,7 +290,7 @@ impl<'lua, T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> FromLu impl<'lua, T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> ToLuaProxy<'lua> for T { fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result> { - self.to_lua(lua) + self.into_lua(lua) } } diff --git a/bevy_script_api/src/lua/std.rs b/bevy_script_api/src/lua/std.rs index b9df2e66..9d6dbd76 100644 --- a/bevy_script_api/src/lua/std.rs +++ b/bevy_script_api/src/lua/std.rs @@ -1,19 +1,17 @@ -use ::std::borrow::Cow; - use bevy::reflect::FromReflect; use bevy::reflect::Reflect; use bevy::reflect::TypePath; use bevy_mod_scripting_lua::tealr; +use bevy_mod_scripting_lua::tealr::ToTypename; use tealr::mlu::mlua::MetaMethod; use tealr::mlu::TypedFunction; use tealr::mlu::{ - mlua::{self, FromLua, Lua, ToLua, UserData, Value}, + mlua::{self, FromLua, IntoLua, Lua, UserData, Value}, TealData, TealDataMethods, }; use tealr::TypeBody; -use tealr::TypeName; use paste::paste; @@ -38,7 +36,7 @@ macro_rules! impl_proxyable_by_copy( $( impl $crate::lua::LuaProxyable for $num_ty { fn ref_to_lua(self_: $crate::script_ref::ScriptRef,lua: & tealr::mlu::mlua::Lua) -> tealr::mlu::mlua::Result > { - self_.get_typed(|self_ : &Self| self_.to_lua(lua))? + self_.get_typed(|self_ : &Self| self_.into_lua(lua))? } fn apply_lua< 'lua>(self_: &mut $crate::script_ref::ScriptRef,lua: & 'lua tealr::mlu::mlua::Lua,new_val:tealr::mlu::mlua::Value< 'lua>) -> tealr::mlu::mlua::Result<()> { @@ -57,7 +55,7 @@ macro_rules! impl_proxyable_by_copy( impl <'lua>$crate::lua::ToLuaProxy<'lua> for $num_ty { #[inline(always)] fn to_lua_proxy(self, lua: &'lua Lua) -> tealr::mlu::mlua::Result> { - self.to_lua(lua) + self.into_lua(lua) } } )* @@ -72,7 +70,7 @@ impl_proxyable_by_copy!(u8, u16, u32, u64, u128, usize); impl LuaProxyable for String { fn ref_to_lua(self_: ScriptRef, lua: &Lua) -> mlua::Result { - self_.get_typed(|self_: &String| self_.as_str().to_lua(lua))? + self_.get_typed(|self_: &String| self_.as_str().into_lua(lua))? } fn apply_lua<'lua>( @@ -95,7 +93,7 @@ impl<'lua> FromLuaProxy<'lua> for String { impl<'lua> ToLuaProxy<'lua> for String { fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result> { - self.to_lua(lua) + self.into_lua(lua) } } @@ -234,7 +232,7 @@ impl<'lua, T: for<'a> ToLuaProxy<'a>> ToLuaProxy<'lua> for Option { pub type LuaVec = ScriptVec; impl< - T: TypeName + T: ToTypename + FromReflect + TypePath + LuaProxyable @@ -253,24 +251,15 @@ impl< } } -impl TypeName for LuaVec { - fn get_type_parts() -> Cow<'static, [tealr::NamePart]> { - let mut parts = vec![ - tealr::NamePart::Type(tealr::TealType { - name: Cow::Borrowed("LuaVec"), - type_kind: tealr::KindOfType::External, - generics: None, - }), - tealr::NamePart::Symbol("<".into()), - ]; - parts.extend(T::get_type_parts().iter().cloned()); - parts.push(tealr::NamePart::Symbol(">".into())); - parts.into() +impl ToTypename for LuaVec { + /// Before tealr deprecated TypeName, this used to incorporate generics here, but right now I don't think they're supported anymore + fn to_typename() -> tealr::Type { + tealr::Type::new_single("LuaVec", tealr::KindOfType::External) } } impl< - T: TypeName + T: ToTypename + FromReflect + TypePath + LuaProxyable @@ -289,7 +278,7 @@ impl< } impl< - T: TypeName + T: ToTypename + FromReflect + TypePath + LuaProxyable @@ -325,8 +314,8 @@ impl< move |ctx, ()| { let o = if curr_idx < len { ( - to_lua_idx(curr_idx).to_lua(ctx)?, - ref_.index(curr_idx).to_lua(ctx)?, + to_lua_idx(curr_idx).into_lua(ctx)?, + ref_.index(curr_idx).into_lua(ctx)?, ) } else { (Value::Nil, Value::Nil) @@ -346,7 +335,7 @@ impl< let len = s.len()?; for i in 0..len { - table.raw_set(to_lua_idx(i), s.index(i).to_lua(ctx)?)?; + table.raw_set(to_lua_idx(i), s.index(i).into_lua(ctx)?)?; } Ok(table) @@ -378,7 +367,7 @@ impl< } impl< - T: TypeName + T: ToTypename + FromReflect + TypePath + LuaProxyable @@ -388,7 +377,7 @@ impl< > LuaProxyable for Vec { fn ref_to_lua(self_: ScriptRef, lua: &Lua) -> mlua::Result { - LuaVec::::new_ref(self_).to_lua(lua) + LuaVec::::new_ref(self_).into_lua(lua) } fn apply_lua<'lua>( @@ -436,7 +425,7 @@ impl< impl< 'lua, - T: TypeName + T: ToTypename + for<'a> FromLuaProxy<'a> + for<'a> ToLuaProxy<'a> + Clone @@ -478,6 +467,6 @@ impl<'lua, T: for<'a> ToLuaProxy<'a> + Clone + FromReflect + LuaProxyable> ToLua proxies.raw_set(idx, elem.to_lua_proxy(lua)?)?; } - proxies.to_lua(lua) + proxies.into_lua(lua) } } diff --git a/bevy_script_api/src/lua/util.rs b/bevy_script_api/src/lua/util.rs index 9b1d4166..d7f2fc98 100644 --- a/bevy_script_api/src/lua/util.rs +++ b/bevy_script_api/src/lua/util.rs @@ -1,22 +1,20 @@ use bevy_mod_scripting_lua::{ - prelude::{FromLua, Lua, LuaError, LuaValue, ToLua}, - tealr, + prelude::{FromLua, IntoLua, Lua, LuaError, LuaValue}, + tealr::{self, ToTypename}, }; use std::{ marker::PhantomData, ops::{Deref, DerefMut}, }; -use tealr::TypeName; - /// Newtype abstraction of usize to represent a lua integer indexing things. /// Lua is 1 based, host is 0 based, and this type performs this conversion automatically via ToLua and FromLua traits. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct LuaIndex(usize); -impl TypeName for LuaIndex { - fn get_type_parts() -> std::borrow::Cow<'static, [tealr::NamePart]> { - usize::get_type_parts() +impl ToTypename for LuaIndex { + fn to_typename() -> tealr::Type { + ::to_typename() } } @@ -34,9 +32,9 @@ impl DerefMut for LuaIndex { } } -impl ToLua<'_> for LuaIndex { - fn to_lua(self, lua: &Lua) -> Result { - to_lua_idx(self.0).to_lua(lua) +impl IntoLua<'_> for LuaIndex { + fn into_lua(self, lua: &Lua) -> Result { + to_lua_idx(self.0).into_lua(lua) } } @@ -71,8 +69,8 @@ impl DummyTypeName { } } -impl<'lua, T> bevy_mod_scripting_lua::tealr::mlu::mlua::ToLua<'lua> for DummyTypeName { - fn to_lua( +impl<'lua, T> bevy_mod_scripting_lua::tealr::mlu::mlua::IntoLua<'lua> for DummyTypeName { + fn into_lua( self, _: &'lua bevy_mod_scripting_lua::tealr::mlu::mlua::Lua, ) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result< @@ -82,23 +80,45 @@ impl<'lua, T> bevy_mod_scripting_lua::tealr::mlu::mlua::ToLua<'lua> for DummyTyp } } -impl bevy_mod_scripting_lua::tealr::TypeName for DummyTypeName { - fn get_type_parts() -> std::borrow::Cow<'static, [bevy_mod_scripting_lua::tealr::NamePart]> { - T::get_type_parts() +impl ToTypename for DummyTypeName { + fn to_typename() -> bevy_mod_scripting_lua::tealr::Type { + T::to_typename() } } +#[macro_export] +macro_rules! impl_from_lua_with_clone { + ($v:ty) => { + impl<'lua> bevy_mod_scripting_lua::tealr::mlu::mlua::FromLua<'lua> for $v { + #[inline] + fn from_lua( + value: bevy_mod_scripting_lua::tealr::mlu::mlua::Value<'lua>, + _: &'lua bevy_mod_scripting_lua::tealr::mlu::mlua::Lua, + ) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<$v> { + match value { + bevy_mod_scripting_lua::tealr::mlu::mlua::Value::UserData(ud) => { + Ok(ud.borrow::<$v>()?.clone()) + } + _ => Err( + bevy_mod_scripting_lua::tealr::mlu::mlua::Error::FromLuaConversionError { + from: value.type_name(), + to: "userdata", + message: None, + }, + ), + } + } + } + }; +} + /// Implements :tealr::TypeName, tealr::TypeBody and mlua::Userdata based on non-generic single token type name implementing TealData #[macro_export] macro_rules! impl_tealr_type { ($v:ty) => { - impl bevy_mod_scripting_lua::tealr::TypeName for $v { - fn get_type_parts() -> ::std::borrow::Cow<'static, [bevy_mod_scripting_lua::tealr::NamePart]> { - ::std::borrow::Cow::Borrowed(&[bevy_mod_scripting_lua::tealr::NamePart::Type(bevy_mod_scripting_lua::tealr::TealType { - name: ::std::borrow::Cow::Borrowed(stringify!($v)), - generics: None, - type_kind: bevy_mod_scripting_lua::tealr::KindOfType::External, - })]) + impl bevy_mod_scripting_lua::tealr::ToTypename for $v { + fn to_typename() -> bevy_mod_scripting_lua::tealr::Type { + bevy_mod_scripting_lua::tealr::Type::new_single(stringify!($v), bevy_mod_scripting_lua::tealr::KindOfType::External) } } @@ -138,10 +158,10 @@ macro_rules! impl_tealr_any_union { $visibility enum $type_name { $($sub_types($sub_types) ,)* } - impl<'lua> ::bevy_mod_scripting_lua::tealr::mlu::mlua::ToLua<'lua> for $type_name { - fn to_lua(self, lua: &'lua ::bevy_mod_scripting_lua::tealr::mlu::mlua::Lua) -> ::std::result::Result<::bevy_mod_scripting_lua::tealr::mlu::mlua::Value<'lua>, ::bevy_mod_scripting_lua::tealr::mlu::mlua::Error> { + impl<'lua> ::bevy_mod_scripting_lua::tealr::mlu::mlua::IntoLua<'lua> for $type_name { + fn into_lua(self, lua: &'lua ::bevy_mod_scripting_lua::tealr::mlu::mlua::Lua) -> ::std::result::Result<::bevy_mod_scripting_lua::tealr::mlu::mlua::Value<'lua>, ::bevy_mod_scripting_lua::tealr::mlu::mlua::Error> { match self { - $($type_name::$sub_types(x) => x.to_lua(lua),)* + $($type_name::$sub_types(x) => x.into_lua(lua),)* } } } @@ -159,17 +179,9 @@ macro_rules! impl_tealr_any_union { }) } } - impl ::bevy_mod_scripting_lua::tealr::TypeName for $type_name { - fn get_type_parts() -> ::std::borrow::Cow<'static,[::bevy_mod_scripting_lua::tealr::NamePart]> { - ::std::borrow::Cow::Borrowed(&[::bevy_mod_scripting_lua::tealr::NamePart::Type(::bevy_mod_scripting_lua::tealr::TealType { - name: ::std::borrow::Cow::Borrowed("any"), - generics: None, - type_kind: ::bevy_mod_scripting_lua::tealr::KindOfType::Builtin, - })]) - } - - fn get_type_kind() -> ::bevy_mod_scripting_lua::tealr::KindOfType { - ::bevy_mod_scripting_lua::tealr::KindOfType::Builtin + impl ::bevy_mod_scripting_lua::tealr::ToTypename for $type_name { + fn to_typename() -> bevy_mod_scripting_lua::tealr::Type { + bevy_mod_scripting_lua::tealr::Type::new_single("any", bevy_mod_scripting_lua::tealr::KindOfType::Builtin) } } }; @@ -264,6 +276,7 @@ macro_rules! impl_tealr_generic{ } $crate::impl_tealr_type!($name); + $crate::impl_from_lua_with_clone!($name); } } diff --git a/examples/lua/complex_game_loop.rs b/examples/lua/complex_game_loop.rs index 6d46a925..08e47d45 100644 --- a/examples/lua/complex_game_loop.rs +++ b/examples/lua/complex_game_loop.rs @@ -10,9 +10,9 @@ use std::sync::atomic::Ordering::Relaxed; /// The type we will be using to send data to Lua pub struct MyLuaArg(usize); -impl<'lua> ToLua<'lua> for MyLuaArg { - fn to_lua(self, lua: &'lua Lua) -> mlua::Result> { - self.0.to_lua(lua) +impl<'lua> IntoLua<'lua> for MyLuaArg { + fn into_lua(self, lua: &'lua Lua) -> mlua::Result> { + self.0.into_lua(lua) } } diff --git a/examples/lua/documentation_gen.rs b/examples/lua/documentation_gen.rs index bbf4d9dc..84e9021d 100644 --- a/examples/lua/documentation_gen.rs +++ b/examples/lua/documentation_gen.rs @@ -10,8 +10,8 @@ use std::{sync::Mutex, time::Duration}; #[derive(Clone)] pub struct MyLuaArg; -impl<'lua> ToLua<'lua> for MyLuaArg { - fn to_lua(self, _lua: &'lua Lua) -> mlua::Result> { +impl<'lua> IntoLua<'lua> for MyLuaArg { + fn into_lua(self, _lua: &'lua Lua) -> mlua::Result> { Ok(Value::Nil) } } diff --git a/examples/lua/event_recipients.rs b/examples/lua/event_recipients.rs index 1c65e47a..07cac41c 100644 --- a/examples/lua/event_recipients.rs +++ b/examples/lua/event_recipients.rs @@ -9,9 +9,9 @@ use std::time::Duration; #[derive(Clone)] pub struct MyLuaArg(usize); -impl<'lua> ToLua<'lua> for MyLuaArg { - fn to_lua(self, lua: &'lua Lua) -> mlua::Result> { - self.0.to_lua(lua) +impl<'lua> IntoLua<'lua> for MyLuaArg { + fn into_lua(self, lua: &'lua Lua) -> mlua::Result> { + self.0.into_lua(lua) } } diff --git a/languages/bevy_mod_scripting_lua/Cargo.toml b/languages/bevy_mod_scripting_lua/Cargo.toml index 4950abbb..d247b38a 100644 --- a/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/languages/bevy_mod_scripting_lua/Cargo.toml @@ -45,13 +45,11 @@ path = "src/lib.rs" [dependencies] bevy = { version = "0.11", default-features = false } bevy_mod_scripting_core = { path = "../../bevy_mod_scripting_core", version = "0.3.0" } -#Git pin required for v0.9.0-alpha4 dependancy, without it 0.9.1 is pulled -tealr = { git = "https://github.com/lenscas/tealr.git", rev = "05c9cdbace8abb6c12fc200e03a7ffcc5afff308", features = [ +tealr = { version = "0.9", features = [ "mlua_vendored", "mlua_send", + "mlua_macros", ] } -tealr_derive = { git = "https://github.com/lenscas/tealr.git", rev = "05c9cdbace8abb6c12fc200e03a7ffcc5afff308" } - -parking_lot = "0.12.1" +parking_lot = "0.12.1" #Git pin required for v0.9.0-alpha4 dependancy, without it 0.9.1 is pulled serde_json = "1.0.81" serde = { version = "1", features = ["derive"] } diff --git a/languages/bevy_mod_scripting_lua/src/docs.rs b/languages/bevy_mod_scripting_lua/src/docs.rs index 0c700962..807ae1a9 100644 --- a/languages/bevy_mod_scripting_lua/src/docs.rs +++ b/languages/bevy_mod_scripting_lua/src/docs.rs @@ -20,6 +20,7 @@ static DEFAULT_DOC_CONFIG: fn(&str) -> String = |s| { "page_root": "", "store_in": "{s}", "name": "{s}", + "is_global": true, "type_def_files": {{ "runner": "Builtin", "templates": {{ diff --git a/languages/bevy_mod_scripting_lua/src/lib.rs b/languages/bevy_mod_scripting_lua/src/lib.rs index 060f87e4..250b6c5b 100644 --- a/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/languages/bevy_mod_scripting_lua/src/lib.rs @@ -29,9 +29,9 @@ pub mod prelude { }; } -pub trait LuaArg: for<'lua> ToLuaMulti<'lua> + Clone + Sync + Send + 'static {} +pub trait LuaArg: for<'lua> IntoLuaMulti<'lua> + Clone + Sync + Send + 'static {} -impl ToLuaMulti<'lua> + Clone + Sync + Send + 'static> LuaArg for T {} +impl IntoLuaMulti<'lua> + Clone + Sync + Send + 'static> LuaArg for T {} #[derive(Clone, Event)] /// A Lua Hook. The result of creating this event will be @@ -115,7 +115,7 @@ impl ScriptHost for LuaScriptHost { lua.load(script) .set_name(script_data.name) - .and_then(|c| c.exec()) + .exec() .map_err(|e| ScriptError::FailedToLoad { script: script_data.name.to_owned(), msg: e.to_string(), diff --git a/languages/bevy_mod_scripting_lua_derive/src/implementor.rs b/languages/bevy_mod_scripting_lua_derive/src/implementor.rs index 7ebd8ece..bbb36534 100644 --- a/languages/bevy_mod_scripting_lua_derive/src/implementor.rs +++ b/languages/bevy_mod_scripting_lua_derive/src/implementor.rs @@ -73,6 +73,7 @@ impl WrapperImplementor for LuaImplementor { definition = quote_spanned! {newtype.span()=> #definition bevy_script_api::make_script_wrapper!(#base_type as #newtype_name with Clone); + bevy_script_api::impl_from_lua_with_clone!(#newtype_name); }; } else { definition = quote_spanned! {newtype.span()=> @@ -144,7 +145,7 @@ impl WrapperImplementor for LuaImplementor { impl bevy_script_api::lua::LuaProxyable for #wrapped_type { fn ref_to_lua<'lua>(self_ : bevy_script_api::script_ref::ScriptRef, lua: &'lua #tealr::mlu::mlua::Lua) -> #tealr::mlu::mlua::Result<#tealr::mlu::mlua::Value<'lua>> { - <#wrapper_type as #tealr::mlu::mlua::ToLua>::to_lua(#wrapper_type::new_ref(self_),lua) + <#wrapper_type as #tealr::mlu::mlua::IntoLua>::into_lua(#wrapper_type::new_ref(self_),lua) } fn apply_lua<'lua>(self_ : &mut bevy_script_api::script_ref::ScriptRef, lua: &'lua #tealr::mlu::mlua::Lua, new_val: #tealr::mlu::mlua::Value<'lua>) -> #tealr::mlu::mlua::Result<()> { @@ -164,7 +165,7 @@ impl WrapperImplementor for LuaImplementor { impl bevy_script_api::lua::ToLuaProxy<'_> for #wrapped_type { fn to_lua_proxy<'lua>(self, lua: &'lua #tealr::mlu::mlua::Lua) -> #tealr::mlu::mlua::Result<#tealr::mlu::mlua::Value<'lua>>{ - <#wrapper_type as #tealr::mlu::mlua::ToLua>::to_lua(#wrapper_type::new(self),lua) + <#wrapper_type as #tealr::mlu::mlua::IntoLua>::into_lua(#wrapper_type::new(self),lua) } } }; diff --git a/readme.md b/readme.md index bafcf517..1c79c961 100644 --- a/readme.md +++ b/readme.md @@ -295,7 +295,9 @@ It is probably a wise idea to set up a separate executable whose only purpose is Lua documentation is provided by `tealr`, a wrapper around the `mlua` lua API which decorates their standard types. On top of providing documentation generation, it's also capable of generating `d.tl` files which can be used to introduce static typing to lua via the `teal` project (you do not need to use teal to generate documentation). -This can all be seen at work in [this example](bevy_mod_scripting/examples/lua/documentation_gen.rs). +This can all be seen at work in [this example](bevy_mod_scripting/examples/lua/documentation_gen.rs). + +The docs for the bevy API provided in this crate are generated automatically each release onto this repo [here](https://github.com/makspll/bevy_mod_scripting_lua) and deployed [here](https://makspll.github.io/bevy_mod_scripting_lua/v0.3.0/). You might need to set the `page_root` to the path to something like: `assets/doc/YourAPI` in the automatically generated config file over at: `assets/doc/tealr_doc_gen_config.json` ##### Teal - Lua static typing diff --git a/tealr_doc_gen_config.json b/tealr_doc_gen_config.json deleted file mode 100644 index 564e55e1..00000000 --- a/tealr_doc_gen_config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "doc_template": "Builtin", - "page_root": "", - "store_in": "BevyAPI", - "name": "BevyAPI", - "type_def_files": { - "runner": "Builtin", - "templates": { - "teal": { - "extension": ".d.tl", - "template": "Teal" - } - } - } -} \ No newline at end of file