#![allow(clippy::all)]
#![allow(unused, deprecated, dead_code)]
#![cfg_attr(rustfmt, rustfmt_skip)]
use super::bevy_reflect::*;
extern crate self as bevy_script_api;
use bevy_script_api::{
lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld,
};
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(clone),
remote = "bevy::ecs::entity::Entity",
functions[r#"
#[lua(
as_trait = "std::cmp::PartialEq",
kind = "MetaFunction",
composite = "eq",
metamethod = "Eq",
)]
fn eq(&self, #[proxy] other: &entity::Entity) -> bool;
"#,
r#"
/// Creates a new entity ID with the specified `index` and a generation of 1.
/// # Note
/// Spawning a specific `entity` value is __rarely the right choice__. Most apps should favor
/// [`Commands::spawn`](crate::system::Commands::spawn). This method should generally
/// only be used for sharing entities across apps, and only when they have a scheme
/// worked out to share an index space (which doesn't happen by default).
/// In general, one should not try to synchronize the ECS by attempting to ensure that
/// `Entity` lines up between instances, but instead insert a secondary identifier as
/// a component.
#[lua(kind = "Function", output(proxy))]
fn from_raw(index: u32) -> bevy::ecs::entity::Entity;
"#,
r#"
/// Convert to a form convenient for passing outside of rust.
/// Only useful for identifying entities within the same instance of an application. Do not use
/// for serialization between runs.
/// No particular structure is guaranteed for the returned bits.
#[lua(kind = "Method")]
fn to_bits(self) -> u64;
"#,
r#"
/// Reconstruct an `Entity` previously destructured with [`Entity::to_bits`].
/// Only useful when applied to results from `to_bits` in the same instance of an application.
/// # Panics
/// This method will likely panic if given `u64` values that did not come from [`Entity::to_bits`].
#[lua(kind = "Function", output(proxy))]
fn from_bits(bits: u64) -> bevy::ecs::entity::Entity;
"#,
r#"
/// Return a transiently unique identifier.
/// No two simultaneously-live entities share the same index, but dead entities' indices may collide
/// with both live and dead entities. Useful for compactly representing entities within a
/// specific snapshot of the world, such as when serializing.
#[lua(kind = "Method")]
fn index(self) -> u32;
"#,
r#"
/// Returns the generation of this Entity's index. The generation is incremented each time an
/// entity with a given index is despawned. This serves as a "count" of the number of times a
/// given index has been reused (index, generation) pairs uniquely identify a given Entity.
#[lua(kind = "Method")]
fn generation(self) -> u32;
"#,
r#"
#[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))]
fn clone(&self) -> bevy::ecs::entity::Entity;
"#,
r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct Entity {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(),
remote = "bevy::ecs::world::OnAdd",
functions[r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct OnAdd {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(),
remote = "bevy::ecs::world::OnInsert",
functions[r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct OnInsert {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(),
remote = "bevy::ecs::world::OnRemove",
functions[r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct OnRemove {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(),
remote = "bevy::ecs::world::OnReplace",
functions[r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct OnReplace {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(clone),
remote = "bevy::ecs::component::ComponentId",
functions[r#"
/// Creates a new [`ComponentId`].
/// The `index` is a unique value associated with each type of component in a given world.
/// Usually, this value is taken from a counter incremented for each type of component registered with the world.
#[lua(kind = "Function", output(proxy))]
fn new(index: usize) -> bevy::ecs::component::ComponentId;
"#,
r#"
/// Returns the index of the current component.
#[lua(kind = "Method")]
fn index(self) -> usize;
"#,
r#"
#[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))]
fn clone(&self) -> bevy::ecs::component::ComponentId;
"#,
r#"
#[lua(
as_trait = "std::cmp::PartialEq",
kind = "MetaFunction",
composite = "eq",
metamethod = "Eq",
)]
fn eq(&self, #[proxy] other: &component::ComponentId) -> bool;
"#,
r#"
#[lua(as_trait = "std::cmp::Eq", kind = "Method")]
fn assert_receiver_is_total_eq(&self) -> ();
"#,
r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct ComponentId();
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(clone),
remote = "bevy::ecs::component::Tick",
functions[r#"
#[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))]
fn clone(&self) -> bevy::ecs::component::Tick;
"#,
r#"
#[lua(
as_trait = "std::cmp::PartialEq",
kind = "MetaFunction",
composite = "eq",
metamethod = "Eq",
)]
fn eq(&self, #[proxy] other: &component::Tick) -> bool;
"#,
r#"
#[lua(as_trait = "std::cmp::Eq", kind = "Method")]
fn assert_receiver_is_total_eq(&self) -> ();
"#,
r#"
/// Creates a new [`Tick`] wrapping the given value.
#[lua(kind = "Function", output(proxy))]
fn new(tick: u32) -> bevy::ecs::component::Tick;
"#,
r#"
/// Gets the value of this change tick.
#[lua(kind = "Method")]
fn get(self) -> u32;
"#,
r#"
/// Sets the value of this change tick.
#[lua(kind = "MutatingMethod")]
fn set(&mut self, tick: u32) -> ();
"#,
r#"
/// Returns `true` if this `Tick` occurred since the system's `last_run`.
/// `this_run` is the current tick of the system, used as a reference to help deal with wraparound.
#[lua(kind = "Method")]
fn is_newer_than(
self,
#[proxy]
last_run: bevy::ecs::component::Tick,
#[proxy]
this_run: bevy::ecs::component::Tick,
) -> bool;
"#,
r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct Tick {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(clone),
remote = "bevy::ecs::component::ComponentTicks",
functions[r#"
/// Returns `true` if the component or resource was added after the system last ran
/// (or the system is running for the first time).
#[lua(kind = "Method")]
fn is_added(
&self,
#[proxy]
last_run: bevy::ecs::component::Tick,
#[proxy]
this_run: bevy::ecs::component::Tick,
) -> bool;
"#,
r#"
/// Returns `true` if the component or resource was added or mutably dereferenced after the system last ran
/// (or the system is running for the first time).
#[lua(kind = "Method")]
fn is_changed(
&self,
#[proxy]
last_run: bevy::ecs::component::Tick,
#[proxy]
this_run: bevy::ecs::component::Tick,
) -> bool;
"#,
r#"
/// Creates a new instance with the same change tick for `added` and `changed`.
#[lua(kind = "Function", output(proxy))]
fn new(
#[proxy]
change_tick: bevy::ecs::component::Tick,
) -> bevy::ecs::component::ComponentTicks;
"#,
r#"
/// Manually sets the change tick.
/// This is normally done automatically via the [`DerefMut`](std::ops::DerefMut) implementation
/// on [`Mut<T>`](crate::change_detection::Mut), [`ResMut<T>`](crate::change_detection::ResMut), etc.
/// However, components and resources that make use of interior mutability might require manual updates.
/// # Example
/// ```no_run
/// # use bevy_ecs::{world::World, component::ComponentTicks};
/// let world: World = unimplemented!();
/// let component_ticks: ComponentTicks = unimplemented!();
/// component_ticks.set_changed(world.read_change_tick());
/// ```
#[lua(kind = "MutatingMethod")]
fn set_changed(&mut self, #[proxy] change_tick: bevy::ecs::component::Tick) -> ();
"#,
r#"
#[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))]
fn clone(&self) -> bevy::ecs::component::ComponentTicks;
"#,
r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct ComponentTicks {
#[lua(output(proxy))]
added: bevy::ecs::component::Tick,
#[lua(output(proxy))]
changed: bevy::ecs::component::Tick,
}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(clone),
remote = "bevy::ecs::identifier::Identifier",
functions[r#"
#[lua(
as_trait = "std::cmp::PartialEq",
kind = "MetaFunction",
composite = "eq",
metamethod = "Eq",
)]
fn eq(&self, #[proxy] other: &identifier::Identifier) -> bool;
"#,
r#"
/// Returns the value of the low segment of the [`Identifier`].
#[lua(kind = "Method")]
fn low(self) -> u32;
"#,
r#"
/// Returns the masked value of the high segment of the [`Identifier`].
/// Does not include the flag bits.
#[lua(kind = "Method")]
fn masked_high(self) -> u32;
"#,
r#"
/// Convert the [`Identifier`] into a `u64`.
#[lua(kind = "Method")]
fn to_bits(self) -> u64;
"#,
r#"
/// Convert a `u64` into an [`Identifier`].
/// # Panics
/// This method will likely panic if given `u64` values that did not come from [`Identifier::to_bits`].
#[lua(kind = "Function", output(proxy))]
fn from_bits(value: u64) -> bevy::ecs::identifier::Identifier;
"#,
r#"
#[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))]
fn clone(&self) -> bevy::ecs::identifier::Identifier;
"#,
r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct Identifier {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(clone),
remote = "bevy::ecs::entity::EntityHash",
functions[r#"
#[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))]
fn clone(&self) -> bevy::ecs::entity::EntityHash;
"#]
)]
struct EntityHash {}
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(
derive(clone),
remote = "bevy::ecs::removal_detection::RemovedComponentEntity",
functions[r#"
#[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))]
fn clone(&self) -> bevy::ecs::removal_detection::RemovedComponentEntity;
"#,
r#"
#[lua(kind="MetaMethod", metamethod="ToString")]
fn index(&self) -> String {
format!("{:?}", _self)
}
"#]
)]
struct RemovedComponentEntity();
#[derive(bevy_mod_scripting_lua_derive::LuaProxy)]
#[proxy(derive(), remote = "bevy::ecs::system::SystemIdMarker", functions[])]
struct SystemIdMarker {}
#[derive(Default)]
pub(crate) struct Globals;
impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals {
fn add_instances<
'lua,
T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>,
>(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> {
instances
.add_instance(
"Entity",
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::<LuaEntity>::new,
)?;
instances
.add_instance(
"ComponentId",
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::<LuaComponentId>::new,
)?;
instances
.add_instance(
"Tick",
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::<LuaTick>::new,
)?;
instances
.add_instance(
"ComponentTicks",
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::<
LuaComponentTicks,
>::new,
)?;
instances
.add_instance(
"Identifier",
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::<LuaIdentifier>::new,
)?;
Ok(())
}
}
pub struct BevyEcsAPIProvider;
impl bevy_mod_scripting_core::hosts::APIProvider for BevyEcsAPIProvider {
type APITarget = std::sync::Mutex<bevy_mod_scripting_lua::tealr::mlu::mlua::Lua>;
type ScriptContext = std::sync::Mutex<bevy_mod_scripting_lua::tealr::mlu::mlua::Lua>;
type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment;
fn attach_api(
&mut self,
ctx: &mut Self::APITarget,
) -> Result<(), bevy_mod_scripting_core::error::ScriptError> {
let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context");
bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx)
.map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other(
e.to_string(),
))
}
fn get_doc_fragment(&self) -> Option<Self::DocTarget> {
Some(
bevy_mod_scripting_lua::docs::LuaDocFragment::new(
"BevyEcsAPI",
|tw| {
tw.document_global_instance::<Globals>()
.expect("Something went wrong documenting globals")
.process_type::<LuaEntity>()
.process_type::<
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy<LuaEntity>,
>()
.process_type::<LuaOnAdd>()
.process_type::<LuaOnInsert>()
.process_type::<LuaOnRemove>()
.process_type::<LuaOnReplace>()
.process_type::<LuaComponentId>()
.process_type::<
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy<
LuaComponentId,
>,
>()
.process_type::<LuaTick>()
.process_type::<
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy<LuaTick>,
>()
.process_type::<LuaComponentTicks>()
.process_type::<
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy<
LuaComponentTicks,
>,
>()
.process_type::<LuaIdentifier>()
.process_type::<
bevy_mod_scripting_lua::tealr::mlu::UserDataProxy<
LuaIdentifier,
>,
>()
.process_type::<LuaEntityHash>()
.process_type::<LuaRemovedComponentEntity>()
.process_type::<LuaSystemIdMarker>()
},
),
)
}
fn setup_script(
&mut self,
script_data: &bevy_mod_scripting_core::hosts::ScriptData,
ctx: &mut Self::ScriptContext,
) -> Result<(), bevy_mod_scripting_core::error::ScriptError> {
Ok(())
}
fn setup_script_runtime(
&mut self,
world_ptr: bevy_mod_scripting_core::world::WorldPointer,
_script_data: &bevy_mod_scripting_core::hosts::ScriptData,
ctx: &mut Self::ScriptContext,
) -> Result<(), bevy_mod_scripting_core::error::ScriptError> {
Ok(())
}
fn register_with_app(&self, app: &mut bevy::app::App) {
app.register_foreign_lua_type::<bevy::ecs::entity::Entity>();
app.register_foreign_lua_type::<bevy::ecs::world::OnAdd>();
app.register_foreign_lua_type::<bevy::ecs::world::OnInsert>();
app.register_foreign_lua_type::<bevy::ecs::world::OnRemove>();
app.register_foreign_lua_type::<bevy::ecs::world::OnReplace>();
app.register_foreign_lua_type::<bevy::ecs::component::ComponentId>();
app.register_foreign_lua_type::<bevy::ecs::component::Tick>();
app.register_foreign_lua_type::<bevy::ecs::component::ComponentTicks>();
app.register_foreign_lua_type::<bevy::ecs::identifier::Identifier>();
app.register_foreign_lua_type::<bevy::ecs::entity::EntityHash>();
app.register_foreign_lua_type::<
bevy::ecs::removal_detection::RemovedComponentEntity,
>();
app.register_foreign_lua_type::<bevy::ecs::system::SystemIdMarker>();
}
}