Skip to content

Commit 85e66a5

Browse files
authored
Bump tealr & mlua versions (#96)
* initial work * change readme * change readme * re-factor CI * spaces * remove goblins * change ci * change ci * change ci * forgot to save * add inherits * clippy * fmt * change profile
1 parent 48d8012 commit 85e66a5

File tree

15 files changed

+127
-132
lines changed

15 files changed

+127
-132
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ jobs:
3434
profile: minimal
3535
toolchain: stable
3636
override: true
37-
- uses: Swatinem/rust-cache@v2.7.0
37+
- name: Rust Cache
38+
uses: Swatinem/rust-cache@v2.7.3
3839
# for x86 builds
3940
- if: matrix.run_args.cross == null
4041
uses: actions-rs/cargo@v1
@@ -47,7 +48,7 @@ jobs:
4748
with:
4849
command: check
4950
target: ${{ matrix.run_args.cross }}
50-
args: --workspace --features=${{ matrix.run_args.lua }},rhai,teal,lua_script_api,rhai_script_api
51+
args: --workspace --features=${{ matrix.run_args.lua }},rhai,teal,lua_script_api,rhai_script_api --profile=ephemeral-build
5152

5253
fmt:
5354
name: Rustfmt
@@ -62,7 +63,8 @@ jobs:
6263
components: rustfmt
6364
toolchain: stable
6465
override: true
65-
- uses: Swatinem/rust-cache@v2.7.0
66+
- name: Rust Cache
67+
uses: Swatinem/rust-cache@v2.7.3
6668
- uses: actions-rs/cargo@v1
6769
with:
6870
command: fmt
@@ -80,11 +82,12 @@ jobs:
8082
toolchain: stable
8183
components: clippy
8284
override: true
83-
- uses: Swatinem/rust-cache@v2.7.0
85+
- name: Rust Cache
86+
uses: Swatinem/rust-cache@v2.7.3
8487
- uses: actions-rs/cargo@v1
8588
with:
8689
command: clippy
87-
args: --features=lua54,rhai,teal,lua_script_api,rhai_script_api -- -D warnings
90+
args: --features=lua54,rhai,teal,lua_script_api,rhai_script_api --profile=ephemeral-build -- -D warnings
8891
tests:
8992
name: Tests
9093
runs-on: ubuntu-latest
@@ -108,11 +111,12 @@ jobs:
108111
with:
109112
toolchain: stable
110113
override: true
111-
- uses: Swatinem/rust-cache@v2.7.0
114+
- name: Rust Cache
115+
uses: Swatinem/rust-cache@v2.7.3
112116
- uses: actions-rs/cargo@v1
113117
with:
114118
command: test
115-
args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api
119+
args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api --profile=ephemeral-build
116120
docs:
117121
name: Docs
118122
runs-on: ubuntu-latest
@@ -124,11 +128,12 @@ jobs:
124128
with:
125129
toolchain: stable
126130
override: true
127-
- uses: Swatinem/rust-cache@v2.7.0
131+
- name: Rust Cache
132+
uses: Swatinem/rust-cache@v2.7.3
128133
- name: Find docs.rs features
129134
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
130135
id: features
131136
- uses: actions-rs/cargo@v1
132137
with:
133138
command: doc
134-
args: --workspace --features=${{ steps.features.outputs.DOCS_FEATURES }}
139+
args: --workspace --features=${{ steps.features.outputs.DOCS_FEATURES }} --profile=ephemeral-build

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ opt-level = 1
9393
[profile.dev.package."*"]
9494
opt-level = 3
9595

96+
[profile.ephemeral-build]
97+
inherits = "dev"
98+
opt-level = 2
99+
codegen-units = 8
100+
96101

97102
[[example]]
98103
name = "console_integration_lua"

bevy_script_api/src/lua/bevy/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::common::bevy::{ScriptTypeRegistration, ScriptWorld};
2-
use crate::impl_tealr_type;
2+
use crate::{impl_from_lua_with_clone, impl_tealr_type};
33

44
use std::sync::Arc;
55

@@ -21,6 +21,7 @@ use super::util::LuaIndex;
2121

2222
pub type LuaTypeRegistration = ScriptTypeRegistration;
2323
impl_tealr_type!(LuaTypeRegistration);
24+
impl_from_lua_with_clone!(LuaTypeRegistration);
2425

2526
impl TealData for LuaTypeRegistration {
2627
fn add_methods<'lua, T: TealDataMethods<'lua, Self>>(methods: &mut T) {
@@ -66,6 +67,7 @@ impl TealData for LuaScriptData {
6667
pub type LuaWorld = ScriptWorld;
6768

6869
impl_tealr_type!(LuaWorld);
70+
impl_from_lua_with_clone!(LuaWorld);
6971

7072
impl TealData for LuaWorld {
7173
fn add_methods<'lua, T: TealDataMethods<'lua, Self>>(methods: &mut T) {

bevy_script_api/src/lua/mod.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ use ::std::any::TypeId;
22
use ::std::borrow::Cow;
33

44
use crate::common::bevy::GetWorld;
5-
use crate::impl_tealr_type;
5+
use crate::{impl_from_lua_with_clone, impl_tealr_type};
66
use ::bevy::prelude::{App, AppTypeRegistry};
77

88
use ::bevy::reflect::{FromType, GetTypeRegistration, Reflect};
99

1010
use bevy_mod_scripting_core::world::WorldPointer;
11-
use bevy_mod_scripting_lua::tealr;
11+
use bevy_mod_scripting_lua::tealr::{self, ToTypename};
1212

1313
use tealr::mlu::mlua::MetaMethod;
1414
use tealr::mlu::{
15-
mlua::{self, FromLua, Lua, ToLua, UserData, Value},
15+
mlua::{self, FromLua, IntoLua, Lua, UserData, Value},
1616
TealData, TealDataMethods,
1717
};
18-
use tealr::TypeName;
1918

2019
use crate::script_ref::{ReflectedValue, ScriptRef, ValueIndex};
2120

@@ -126,13 +125,13 @@ impl ApplyLua for ScriptRef {
126125
}
127126
}
128127

129-
impl<'lua> ToLua<'lua> for ScriptRef {
128+
impl<'lua> IntoLua<'lua> for ScriptRef {
130129
/// Converts the LuaRef to the most convenient representation
131130
/// checking conversions in this order:
132131
/// - A primitive or bevy type which has a reflect interface is converted to a custom UserData exposing its API to lua conveniently
133132
/// - A type implementing CustomUserData is converted with its `ref_to_lua` method
134133
/// - Finally the method is represented as a `ReflectedValue` which exposes the Reflect interface
135-
fn to_lua(self, ctx: &'lua Lua) -> mlua::Result<Value<'lua>> {
134+
fn into_lua(self, ctx: &'lua Lua) -> mlua::Result<Value<'lua>> {
136135
let world = self.world_ptr.clone();
137136
let world = world.read();
138137

@@ -143,26 +142,19 @@ impl<'lua> ToLua<'lua> for ScriptRef {
143142
if let Some(v) = g.get_type_data::<ReflectLuaProxyable>(type_id) {
144143
v.ref_to_lua(self, ctx)
145144
} else {
146-
ReflectedValue { ref_: self }.to_lua(ctx)
145+
ReflectedValue { ref_: self }.into_lua(ctx)
147146
}
148147
}
149148
}
150149

151-
impl TypeName for ScriptRef {
152-
/// ReflectedValue represents the "lowest common denominator" across the possible returned types
153-
/// people can always use 'as' to cast to the right type
154-
/// but the static analysis will be conservative, i.e. the compiler will assume the smallest set of functionality
155-
/// by default
156-
fn get_type_parts() -> Cow<'static, [tealr::NamePart]> {
157-
Cow::Borrowed(&[tealr::NamePart::Type(tealr::TealType {
158-
name: Cow::Borrowed("ReflectedValue"),
159-
generics: None,
160-
type_kind: tealr::KindOfType::Builtin,
161-
})])
150+
impl ToTypename for ScriptRef {
151+
fn to_typename() -> tealr::Type {
152+
tealr::Type::new_single("ReflectedValue", tealr::KindOfType::External)
162153
}
163154
}
164155

165156
impl_tealr_type!(ReflectedValue);
157+
impl_from_lua_with_clone!(ReflectedValue);
166158
impl TealData for ReflectedValue {
167159
fn add_methods<'lua, T: TealDataMethods<'lua, Self>>(methods: &mut T) {
168160
methods.document_type("This type represents a generic reflected value.");
@@ -266,7 +258,7 @@ pub trait ValueLuaType {}
266258

267259
impl<T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> LuaProxyable for T {
268260
fn ref_to_lua(self_: ScriptRef, lua: &Lua) -> mlua::Result<Value> {
269-
self_.get_typed(|s: &Self| s.clone().to_lua(lua))?
261+
self_.get_typed(|s: &Self| s.clone().into_lua(lua))?
270262
}
271263

272264
fn apply_lua<'lua>(
@@ -288,15 +280,17 @@ impl<T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> LuaProxyable
288280
}
289281
}
290282

291-
impl<'lua, T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> FromLuaProxy<'lua> for T {
283+
impl<'lua, T: Clone + UserData + FromLua<'lua> + Send + ValueLuaType + Reflect + 'static>
284+
FromLuaProxy<'lua> for T
285+
{
292286
fn from_lua_proxy(new_val: Value<'lua>, lua: &'lua Lua) -> mlua::Result<Self> {
293287
T::from_lua(new_val, lua)
294288
}
295289
}
296290

297291
impl<'lua, T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> ToLuaProxy<'lua> for T {
298292
fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result<Value<'lua>> {
299-
self.to_lua(lua)
293+
self.into_lua(lua)
300294
}
301295
}
302296

bevy_script_api/src/lua/std.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
use ::std::borrow::Cow;
2-
31
use bevy::reflect::FromReflect;
42
use bevy::reflect::Reflect;
53

64
use bevy::reflect::TypePath;
75
use bevy_mod_scripting_lua::tealr;
86

7+
use bevy_mod_scripting_lua::tealr::ToTypename;
98
use tealr::mlu::mlua::MetaMethod;
109
use tealr::mlu::TypedFunction;
1110
use tealr::mlu::{
12-
mlua::{self, FromLua, Lua, ToLua, UserData, Value},
11+
mlua::{self, FromLua, IntoLua, Lua, UserData, Value},
1312
TealData, TealDataMethods,
1413
};
1514
use tealr::TypeBody;
16-
use tealr::TypeName;
1715

1816
use paste::paste;
1917

@@ -38,7 +36,7 @@ macro_rules! impl_proxyable_by_copy(
3836
$(
3937
impl $crate::lua::LuaProxyable for $num_ty {
4038
fn ref_to_lua(self_: $crate::script_ref::ScriptRef,lua: & tealr::mlu::mlua::Lua) -> tealr::mlu::mlua::Result<tealr::mlu::mlua::Value< '_> > {
41-
self_.get_typed(|self_ : &Self| self_.to_lua(lua))?
39+
self_.get_typed(|self_ : &Self| self_.into_lua(lua))?
4240
}
4341

4442
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(
5755
impl <'lua>$crate::lua::ToLuaProxy<'lua> for $num_ty {
5856
#[inline(always)]
5957
fn to_lua_proxy(self, lua: &'lua Lua) -> tealr::mlu::mlua::Result<Value<'lua>> {
60-
self.to_lua(lua)
58+
self.into_lua(lua)
6159
}
6260
}
6361
)*
@@ -72,7 +70,7 @@ impl_proxyable_by_copy!(u8, u16, u32, u64, u128, usize);
7270

7371
impl LuaProxyable for String {
7472
fn ref_to_lua(self_: ScriptRef, lua: &Lua) -> mlua::Result<Value> {
75-
self_.get_typed(|self_: &String| self_.as_str().to_lua(lua))?
73+
self_.get_typed(|self_: &String| self_.as_str().into_lua(lua))?
7674
}
7775

7876
fn apply_lua<'lua>(
@@ -95,7 +93,7 @@ impl<'lua> FromLuaProxy<'lua> for String {
9593

9694
impl<'lua> ToLuaProxy<'lua> for String {
9795
fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result<Value<'lua>> {
98-
self.to_lua(lua)
96+
self.into_lua(lua)
9997
}
10098
}
10199

@@ -234,7 +232,7 @@ impl<'lua, T: for<'a> ToLuaProxy<'a>> ToLuaProxy<'lua> for Option<T> {
234232
pub type LuaVec<T> = ScriptVec<T>;
235233

236234
impl<
237-
T: TypeName
235+
T: ToTypename
238236
+ FromReflect
239237
+ TypePath
240238
+ LuaProxyable
@@ -253,24 +251,15 @@ impl<
253251
}
254252
}
255253

256-
impl<T: TypeName> TypeName for LuaVec<T> {
257-
fn get_type_parts() -> Cow<'static, [tealr::NamePart]> {
258-
let mut parts = vec![
259-
tealr::NamePart::Type(tealr::TealType {
260-
name: Cow::Borrowed("LuaVec"),
261-
type_kind: tealr::KindOfType::External,
262-
generics: None,
263-
}),
264-
tealr::NamePart::Symbol("<".into()),
265-
];
266-
parts.extend(T::get_type_parts().iter().cloned());
267-
parts.push(tealr::NamePart::Symbol(">".into()));
268-
parts.into()
254+
impl<T: ToTypename> ToTypename for LuaVec<T> {
255+
/// Before tealr deprecated TypeName, this used to incorporate generics here, but right now I don't think they're supported anymore
256+
fn to_typename() -> tealr::Type {
257+
tealr::Type::new_single("LuaVec", tealr::KindOfType::External)
269258
}
270259
}
271260

272261
impl<
273-
T: TypeName
262+
T: ToTypename
274263
+ FromReflect
275264
+ TypePath
276265
+ LuaProxyable
@@ -289,7 +278,7 @@ impl<
289278
}
290279

291280
impl<
292-
T: TypeName
281+
T: ToTypename
293282
+ FromReflect
294283
+ TypePath
295284
+ LuaProxyable
@@ -325,8 +314,8 @@ impl<
325314
move |ctx, ()| {
326315
let o = if curr_idx < len {
327316
(
328-
to_lua_idx(curr_idx).to_lua(ctx)?,
329-
ref_.index(curr_idx).to_lua(ctx)?,
317+
to_lua_idx(curr_idx).into_lua(ctx)?,
318+
ref_.index(curr_idx).into_lua(ctx)?,
330319
)
331320
} else {
332321
(Value::Nil, Value::Nil)
@@ -346,7 +335,7 @@ impl<
346335
let len = s.len()?;
347336

348337
for i in 0..len {
349-
table.raw_set(to_lua_idx(i), s.index(i).to_lua(ctx)?)?;
338+
table.raw_set(to_lua_idx(i), s.index(i).into_lua(ctx)?)?;
350339
}
351340

352341
Ok(table)
@@ -378,7 +367,7 @@ impl<
378367
}
379368

380369
impl<
381-
T: TypeName
370+
T: ToTypename
382371
+ FromReflect
383372
+ TypePath
384373
+ LuaProxyable
@@ -388,7 +377,7 @@ impl<
388377
> LuaProxyable for Vec<T>
389378
{
390379
fn ref_to_lua(self_: ScriptRef, lua: &Lua) -> mlua::Result<Value> {
391-
LuaVec::<T>::new_ref(self_).to_lua(lua)
380+
LuaVec::<T>::new_ref(self_).into_lua(lua)
392381
}
393382

394383
fn apply_lua<'lua>(
@@ -436,7 +425,7 @@ impl<
436425

437426
impl<
438427
'lua,
439-
T: TypeName
428+
T: ToTypename
440429
+ for<'a> FromLuaProxy<'a>
441430
+ for<'a> ToLuaProxy<'a>
442431
+ Clone
@@ -478,6 +467,6 @@ impl<'lua, T: for<'a> ToLuaProxy<'a> + Clone + FromReflect + LuaProxyable> ToLua
478467
proxies.raw_set(idx, elem.to_lua_proxy(lua)?)?;
479468
}
480469

481-
proxies.to_lua(lua)
470+
proxies.into_lua(lua)
482471
}
483472
}

0 commit comments

Comments
 (0)