Skip to content

Commit

Permalink
add lua feature matrix (#71)
Browse files Browse the repository at this point in the history
* add lua feature matrix

* fix typo

* clippy fixes

* more clippy fixes

* move lua feature matrix to check phase

* fix invalid configs appearing in ci

* Fix lua incompatibility when Pairs are missing

* fix typo
  • Loading branch information
makspll authored Sep 2, 2023
1 parent 8bf3796 commit 2296bb9
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 26 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ name: Check and Lint
jobs:
check:
name: Check
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os_and_lua.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macOS-latest]
os_and_lua: [
{os: windows-latest, lua: lua54},
{os: macOS-latest, lua: lua54},
{os: ubuntu-latest, lua: lua51},
{os: ubuntu-latest, lua: lua52},
{os: ubuntu-latest, lua: lua53},
{os: ubuntu-latest, lua: lua54},
{os: ubuntu-latest, lua: luajit},
{os: ubuntu-latest, lua: luajit52}
]
steps:
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
Expand All @@ -28,7 +37,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api
args: --workspace --features=${{ matrix.os_and_lua.lua }},rhai,teal,lua_script_api,rhai_script_api

fmt:
name: Rustfmt
Expand Down
2 changes: 1 addition & 1 deletion bevy_mod_scripting_common/src/derive_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl ProxyFlags {
}

pub fn merge(&mut self, o: Self) {
self.flags.extend(o.flags.into_iter())
self.flags.extend(o.flags)
}
}

Expand Down
3 changes: 2 additions & 1 deletion bevy_mod_scripting_core/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ impl WorldPointer {
/// Creates a new world pointer.
/// # Safety
/// satisfies world constancy, since it's impossible to change the underlying pointer
/// However you must ensure that the world does not go out of scope while this pointer is live
/// However you must ensure that the world does not go out of scope while this pointer is live
#[allow(clippy::arc_with_non_send_sync)]
pub unsafe fn new(world: &mut World) -> Self {
WorldPointer(Arc::new(RwLock::new(world)))
}
Expand Down
44 changes: 24 additions & 20 deletions bevy_script_api/src/lua/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,27 +314,31 @@ impl<
|ctx, s, (index, value): (LuaIndex, Value)| s.index(*index).apply_lua(ctx, value),
);

methods.add_meta_method(MetaMethod::Pairs, |ctx, s, _: ()| {
let len = s.len()?;
let mut curr_idx = 0;
let ref_: ScriptRef = s.clone().into();
TypedFunction::from_rust_mut(
move |ctx, ()| {
let o = if curr_idx < len {
(
to_lua_idx(curr_idx).to_lua(ctx)?,
ref_.index(curr_idx).to_lua(ctx)?,
)
} else {
(Value::Nil, Value::Nil)
};
curr_idx += 1;
Ok(o)
bevy_mod_scripting_lua::__cfg_feature_any_lua52_lua53_lua54_luajit52!(
methods.add_meta_method(
MetaMethod::Pairs,
|ctx, s, _: ()| {
let len = s.len()?;
let mut curr_idx = 0;
let ref_: ScriptRef = s.clone().into();
TypedFunction::from_rust_mut(
move |ctx, ()| {
let o = if curr_idx < len {
(
to_lua_idx(curr_idx).to_lua(ctx)?,
ref_.index(curr_idx).to_lua(ctx)?,
)
} else {
(Value::Nil, Value::Nil)
};
curr_idx += 1;
Ok(o)
},
ctx,
)
},
ctx,
)
});

);
);
methods.add_meta_method(MetaMethod::Len, |_, s, ()| Ok(s.len()?));

methods.add_method("to_table", |ctx, s, ()| {
Expand Down
2 changes: 1 addition & 1 deletion languages/bevy_mod_scripting_lua/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl DocFragment for LuaDocFragment {
}

fn merge(mut self, o: Self) -> Self {
self.walker.extend(o.walker.into_iter());
self.walker.extend(o.walker);
self
}

Expand Down
108 changes: 108 additions & 0 deletions languages/bevy_mod_scripting_lua/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,111 @@ macro_rules! lua_path {
concat!("scripts/build/", $v, ".lua")
};
}

#[cfg(feature = "lua51")]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua51 {
( $( $tok:tt )* ) => { $( $tok )* }
}

#[cfg(not(feature = "lua51"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua51 {
( $( $tok:tt )* ) => {};
}

#[cfg(feature = "lua52")]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua52 {
( $( $tok:tt )* ) => { $( $tok )* }
}

#[cfg(not(feature = "lua52"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua52 {
( $( $tok:tt )* ) => {};
}

#[cfg(feature = "lua53")]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua53 {
( $( $tok:tt )* ) => { $( $tok )* }
}

#[cfg(not(feature = "lua53"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua53 {
( $( $tok:tt )* ) => {};
}

#[cfg(feature = "lua54")]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua54 {
( $( $tok:tt )* ) => { $( $tok )* }
}

#[cfg(not(feature = "lua54"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_lua54 {
( $( $tok:tt )* ) => {};
}

#[cfg(feature = "luajit")]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_luajit {
( $( $tok:tt )* ) => { $( $tok )* }
}

#[cfg(not(feature = "luajit"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_luajit {
( $( $tok:tt )* ) => {};
}

#[cfg(feature = "luajit52")]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_luajit52 {
( $( $tok:tt )* ) => { $( $tok )* }
}

#[cfg(not(feature = "luajit52"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_luajit52 {
( $( $tok:tt )* ) => {};
}

#[cfg(any(
feature = "lua52",
feature = "lua53",
feature = "lua54",
feature = "luajit52"
))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_any_lua52_lua53_lua54_luajit52 {
( $( $tok:tt )* ) => { $( $tok )* }
}

#[cfg(not(any(
feature = "lua52",
feature = "lua53",
feature = "lua54",
feature = "luajit52"
)))]
#[doc(hidden)]
#[macro_export]
macro_rules! __cfg_feature_any_lua52_lua53_lua54_luajit52 {
( $( $tok:tt )* ) => {};
}

0 comments on commit 2296bb9

Please sign in to comment.