Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Spoon' into fix/unsafe_entity_ac…
Browse files Browse the repository at this point in the history
…cess
  • Loading branch information
LaserWitch committed Sep 2, 2023
2 parents bb785b8 + 12eb62f commit 5fd50e0
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 30 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
2 changes: 1 addition & 1 deletion bevy_mod_scripting_core/src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub trait ScriptHost: Send + Sync + 'static + Default + Resource {
/// the main point of contact with the bevy world.
/// Scripts are called with appropriate events in the event order
fn handle_events<'a>(
&self,
&mut self,
world_ptr: &mut World,
events: &[Self::ScriptEvent],
ctxs: impl Iterator<Item = (ScriptData<'a>, &'a mut Self::ScriptContext)>,
Expand Down
2 changes: 1 addition & 1 deletion bevy_mod_scripting_core/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn script_event_handler<H: ScriptHost, const MAX: u32, const MIN: u32>(world

let mut ctxts: ScriptContexts<H::ScriptContext> = world.remove_resource().unwrap();

let host: H = world.remove_resource().unwrap();
let mut host: H = world.remove_resource().unwrap();
let mut providers: APIProviders<H> = world.remove_resource().unwrap();

// we need a resource scope to be able to simultaneously access the contexts as well
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
2 changes: 1 addition & 1 deletion languages/bevy_mod_scripting_lua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<A: LuaArg> ScriptHost for LuaScriptHost<A> {
}

fn handle_events<'a>(
&self,
&mut self,
world: &mut World,
events: &[Self::ScriptEvent],
ctxs: impl Iterator<Item = (ScriptData<'a>, &'a mut Self::ScriptContext)>,
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 )* ) => {};
}
2 changes: 1 addition & 1 deletion languages/bevy_mod_scripting_rhai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<A: FuncArgs + Send + Clone + Sync + 'static> ScriptHost for RhaiScriptHost<
}

fn handle_events<'a>(
&self,
&mut self,
world: &mut World,
events: &[Self::ScriptEvent],
ctxs: impl Iterator<Item = (ScriptData<'a>, &'a mut Self::ScriptContext)>,
Expand Down

0 comments on commit 5fd50e0

Please sign in to comment.