diff --git a/.vscode/launch.json b/.vscode/launch.json index a6483eca..76016f0b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,61 +5,33 @@ "version": "0.2.0", "configurations": [ { - "type": "lldb", - "request": "launch", - "name": "Debug specific unit test", - "preLaunchTask": "Build specific package's unit tests", - "program": "${workspaceFolder}/target/debug/test_binary", - "env": { - "CARGO_MANIFEST_DIR": "${workspaceFolder}/bevy_mod_scripting", - "LD_LIBRARY_PATH": "${workspaceFolder}/target/debug/deps:${env:HOME}/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib" - }, - "cwd": "${workspaceFolder}", - }, - { - "name": "Debug example 'game_of_life_lua'", + "name": "Debug a test in bevy_mod_scripting_lua", "type": "lldb", "request": "launch", "cargo": { "args": [ - "build", - "--example=game_of_life_lua", - "--package=bevy_mod_scripting", - "--features=lua54,teal,lua_script_api", + "test", + "--no-run", + "--features", + "lua54", + "--package", + "bevy_mod_scripting_lua", + "--lib", + "--", + "${input:test_name}", + "--show-output" ], "filter": { - "name": "game_of_life_lua", - "kind": "example" + "kind": "lib", + "name": "bevy_mod_scripting_lua" } }, - "args": [], - "cwd": "${workspaceFolder}", + "cwd": "${workspaceFolder}/crates/languages/bevy_mod_scripting_lua", "env": { - "CARGO_MANIFEST_DIR": "${workspaceFolder}", + "CARGO_MANIFEST_DIR": "${workspaceFolder}/crates/languages/bevy_mod_scripting_lua", "LD_LIBRARY_PATH": "${workspaceFolder}/target/debug/deps:${env:HOME}/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib" } }, - { - "name": "Debug example 'game_of_life_rhai'", - "type": "lldb", - "request": "launch", - "cargo": { - "args": [ - "build", - "--example=game_of_life_rhai", - "--package=bevy_mod_scripting", - "--features=rhai,rhai_script_api", - ], - "filter": { - "name": "game_of_life_rhai", - "kind": "example" - } - }, - "args": [], - "cwd": "${workspaceFolder}", - "env": { - "CARGO_MANIFEST_DIR": "${workspaceFolder}" - } - } - ] + ], + "inputs": [] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 14262c18..8a6c3e70 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,29 +1,29 @@ { "version": "2.0.0", "inputs": [ + // used for launch.json as well due to bug https://github.com/microsoft/vscode/issues/212384 { "id": "test_name", "type": "promptString", - "description": "Run only tests including this string in their name", - "default": "" + "description": "Run tests with given path", + "default": "bindings::reference::test::test_index_lua_value_field" }, { "id": "package", "type": "promptString", "description": "The crate location of this unit test", "default": "bevy_mod_scripting" - } - ], - "tasks": [ + }, + { + "id": "features", + "type": "promptString", + "description": "Features to activate for the build", + }, { - "label": "Build specific package's unit tests", - "type": "process", - "command": "make", - "args": [ - "build_test_in_package", - "PACKAGE=${input:package}", - "TEST_NAME=${input:test_name}" - ] - } + "id": "pwd", + "type": "promptString", + "description": "The working directory for the test", + "default": "${workspaceFolder}" + }, ] } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b1ae0117..1c462138 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ luajit = ["bevy_mod_scripting_lua/luajit", "lua"] luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"] # optional -lua_script_api = ["bevy_script_api/lua"] +# lua_script_api = ["bevy_script_api/lua"] unsafe_lua_modules = ["bevy_mod_scripting_lua/unsafe_lua_modules"] teal = ["bevy_mod_scripting_lua/teal"] mlua_serialize = ["bevy_mod_scripting_lua/mlua_serialize"] @@ -55,7 +55,7 @@ mlua_async = ["bevy_mod_scripting_lua/mlua_async"] ## rhai rhai = ["bevy_mod_scripting_rhai"] -rhai_script_api = ["bevy_script_api/rhai"] +# rhai_script_api = ["bevy_script_api/rhai"] ## rune rune = ["bevy_mod_scripting_rune"] @@ -66,13 +66,12 @@ bevy_mod_scripting_core = { workspace = true } bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.6.0", optional = true } bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.6.0", optional = true } bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.6.0", optional = true } -bevy_script_api = { path = "crates/bevy_script_api", version = "0.6.0", optional = true } +# bevy_script_api = { path = "crates/bevy_script_api", version = "0.6.0", optional = true } [workspace.dependencies] bevy = { version = "=0.13.1", default-features = false } bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.6.0" } -bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.6.0" } [dev-dependencies] bevy = { workspace = true, default-features = true } @@ -84,14 +83,10 @@ rhai-rand = "0.1" [workspace] members = [ "crates/bevy_mod_scripting_core", - "crates/bevy_event_priority", - "crates/bevy_script_api", + "crates/bevy_mod_scripting_derive", "crates/languages/bevy_mod_scripting_lua", - "crates/languages/bevy_mod_scripting_lua_derive", "crates/languages/bevy_mod_scripting_rhai", - "crates/languages/bevy_mod_scripting_rhai_derive", "crates/languages/bevy_mod_scripting_rune", - "crates/bevy_mod_scripting_common", ] resolver = "2" exclude = ["crates/bevy_api_gen", "crates/macro_tests"] diff --git a/assets/scripts/event_recipients.lua b/assets/scripts/event_recipients.lua index 2aa50e25..c4679656 100644 --- a/assets/scripts/event_recipients.lua +++ b/assets/scripts/event_recipients.lua @@ -1,4 +1,3 @@ function on_event(id) - print(string.format("on_event, script_id: %d, Handling:", script_id)) - print(string.format("\t-> id: %d", id)) + print(string.format("LUA: event_recipients::on_event(%d) called on entity: %s", id, entity)) end diff --git a/check.sh b/check.sh index b7f544a8..130fa7f3 100755 --- a/check.sh +++ b/check.sh @@ -2,9 +2,10 @@ unset RUSTUP_TOOLCHAIN CURRENT_DIR=$(basename "$PWD") - if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then cargo clippy --all-targets --message-format=json +elif [[ "$CURRENT_DIR" == "macro_tests" ]]; then + cargo clippy --all-targets --message-format=json else - cargo clippy --workspace --all-targets --message-format=json --features="lua54 lua_script_api rhai rhai_script_api teal rune bevy/file_watcher bevy/multi-threaded" + cargo clippy --all-targets --workspace --message-format=json --features="lua54 rhai teal rune bevy/file_watcher bevy/multi-threaded" fi \ No newline at end of file diff --git a/crates/bevy_api_gen/src/args.rs b/crates/bevy_api_gen/src/args.rs index 15e0d3f8..6582e949 100644 --- a/crates/bevy_api_gen/src/args.rs +++ b/crates/bevy_api_gen/src/args.rs @@ -188,7 +188,12 @@ pub enum Command { /// The name of the API, this will be passed to the `collect.rs` template, which by default will be used as the APIProvider name and the /// title of the documentation. - #[arg(short, long, value_name = "NAME", default_value = "LuaBevyAPIProvider")] + #[arg( + short, + long, + value_name = "NAME", + default_value = "LuaBevyScriptingPlugin" + )] api_name: String, }, } diff --git a/crates/bevy_api_gen/src/bin/main.rs b/crates/bevy_api_gen/src/bin/main.rs index 81ae80b7..0f5fee32 100644 --- a/crates/bevy_api_gen/src/bin/main.rs +++ b/crates/bevy_api_gen/src/bin/main.rs @@ -39,7 +39,10 @@ fn main() { (Some(root), true) => { let feature_graph = FeatureGraph::from_metadata(&metadata, root); let dependencies = feature_graph - .dependencies_for_features(args.features.as_ref(), !args.no_default_features) + .workspace_dependencies_for_features( + args.features.as_ref(), + !args.no_default_features, + ) .into_iter() .map(|s| s.to_owned()) .collect::>(); @@ -134,12 +137,13 @@ fn main() { let temp_dir = tempdir::TempDir::new("bevy_api_gen_bootstrap") .expect("Error occured when trying to acquire temp file"); + let path = temp_dir.path().to_owned(); - debug!("Temporary directory: {}", &temp_dir.path().display()); + debug!("Temporary directory: {}", &path.display()); - write_bootstrap_files(temp_dir.path()); + write_bootstrap_files(&path); - let bootstrap_rlibs = build_bootstrap(temp_dir.path(), &plugin_target_dir.join("bootstrap")); + let bootstrap_rlibs = build_bootstrap(&path, &plugin_target_dir.join("bootstrap")); if bootstrap_rlibs.len() == BOOTSTRAP_DEPS.len() { let extern_args = bootstrap_rlibs @@ -169,7 +173,13 @@ fn main() { rustc_plugin::cli_main(BevyAnalyzer); // just making sure the temp dir lives until everything is done - drop(temp_dir); + if let Err(err) = std::fs::remove_dir_all(&path) { + log::error!( + "Error occured when trying to delete temporary directory: `{}`. {}", + path.to_string_lossy(), + err + ) + } } /// Build bootstrap files if they don't exist diff --git a/crates/bevy_api_gen/src/callback.rs b/crates/bevy_api_gen/src/callback.rs index 6174de20..a48503ae 100644 --- a/crates/bevy_api_gen/src/callback.rs +++ b/crates/bevy_api_gen/src/callback.rs @@ -87,6 +87,7 @@ impl rustc_driver::Callbacks for BevyAnalyzerCallbacks { if !continue_ { break; } + trace!("Finished pass, continuing"); } }); rustc_driver::Compilation::Continue diff --git a/crates/bevy_api_gen/src/context.rs b/crates/bevy_api_gen/src/context.rs index dd18021d..83ed871b 100644 --- a/crates/bevy_api_gen/src/context.rs +++ b/crates/bevy_api_gen/src/context.rs @@ -152,7 +152,7 @@ pub(crate) struct FunctionContext { pub(crate) def_id: DefId, pub(crate) has_self: bool, pub(crate) is_unsafe: bool, - pub(crate) trait_did: Option, + pub(crate) trait_and_impl_did: Option<(DefId, DefId)>, /// strategies for input and output (last element is the output) pub(crate) reflection_strategies: Vec, } diff --git a/crates/bevy_api_gen/src/feature_graph.rs b/crates/bevy_api_gen/src/feature_graph.rs index 33b491ee..feddbd0d 100644 --- a/crates/bevy_api_gen/src/feature_graph.rs +++ b/crates/bevy_api_gen/src/feature_graph.rs @@ -58,9 +58,9 @@ pub struct FeatureGraph { } impl FeatureGraph { - /// Works out which dependencies are enabled by the given feature, including transitive relations between crates + /// Works out which dependencies are enabled (in the workspace) are enabled by the given feature, including transitive relations between crates /// includes normal dependencies as well - pub fn dependencies_for_features( + pub fn workspace_dependencies_for_features( &self, features: &[String], include_default: bool, @@ -70,14 +70,24 @@ impl FeatureGraph { .crates .iter() .find(|c| c.name == self.workspace_root) - .unwrap(); + .unwrap_or_else(|| { + panic!( + "Failed to find workspace root `{}`, in crates in this workspace.", + self.workspace_root + ) + }); let mut buffer = Default::default(); - self.dependencies_for_features_on_crate(root, features, include_default, &mut buffer); + self.workspace_dependencies_for_features_on_crate( + root, + features, + include_default, + &mut buffer, + ); buffer.iter().map(|c| c.name.as_str()).collect() } - fn dependencies_for_features_on_crate<'a>( + fn workspace_dependencies_for_features_on_crate<'a>( &'a self, crate_: &'a Crate, features: &[String], @@ -107,15 +117,19 @@ impl FeatureGraph { enable_optional, } => { if *enable_optional { - deps.entry(self.crates.iter().find(|c| c.name == *dependency).unwrap()) - .or_default() - .push(feature.to_owned()); + if let Some(workspace_dep) = + self.crates.iter().find(|c| c.name == *dependency) + { + deps.entry(workspace_dep) + .or_default() + .push(feature.to_owned()); + } } } FeatureEffect::EnableOptionalDep(d) => { - _ = deps - .entry(self.crates.iter().find(|c| c.name == *d).unwrap()) - .or_default() + if let Some(workspace_dep) = self.crates.iter().find(|c| c.name == *d) { + deps.entry(workspace_dep).or_default(); + } } _ => unreachable!(), }; @@ -131,7 +145,12 @@ impl FeatureGraph { // repeat for all dependencies recursively for (dep, features) in deps.iter() { buffer.insert(dep); - self.dependencies_for_features_on_crate(dep, features, include_default, buffer); + self.workspace_dependencies_for_features_on_crate( + dep, + features, + include_default, + buffer, + ); } } diff --git a/crates/bevy_api_gen/src/import_path.rs b/crates/bevy_api_gen/src/import_path.rs index 2f26fd12..c8f55226 100644 --- a/crates/bevy_api_gen/src/import_path.rs +++ b/crates/bevy_api_gen/src/import_path.rs @@ -27,7 +27,7 @@ impl std::fmt::Debug for ImportPathElement { /// Because we do not need ALL the items in the crate, we start searching from the item itself and traverse up the tree. /// Caches results for already found items. pub(crate) struct ImportPathFinder<'tcx> { - tcx: TyCtxt<'tcx>, + pub(crate) tcx: TyCtxt<'tcx>, pub(crate) cache: IndexMap>>, pub(crate) include_private_paths: bool, pub(crate) import_path_processor: Option String>>, diff --git a/crates/bevy_api_gen/src/meta.rs b/crates/bevy_api_gen/src/meta.rs index 3f85dd30..029c438c 100644 --- a/crates/bevy_api_gen/src/meta.rs +++ b/crates/bevy_api_gen/src/meta.rs @@ -66,6 +66,28 @@ impl MetaLoader { self.meta_for_retry(crate_name, 3) } + /// Searches the given meta sources in order for the provided DefPathHash, once a meta file containing this hash is found + /// the search stops and returns true, if no meta file is found containing the hash, false is returned + /// + /// if a curr_source argument is provided, the search will skip this source as it is assumed that the current crate is still being compiled and not meta file for it exists yet + pub fn one_of_meta_files_contains( + &self, + meta_sources: &[&str], + curr_source: Option<&str>, + target_def_path_hash: DefPathHash, + ) -> bool { + let meta = match meta_sources + .iter() + .filter(|s| curr_source.is_none() || curr_source.is_some_and(|cs| cs == **s)) + .find_map(|s| self.meta_for(s)) + { + Some(meta) => meta, + None => return false, // TODO: is it possible we get false negatives here ? perhaps due to parallel compilation ? or possibly because of dependency order + }; + + meta.contains_def_path_hash(target_def_path_hash) + } + fn meta_for_retry(&self, crate_name: &str, _try_attempts: usize) -> Option { let meta = self .meta_dirs diff --git a/crates/bevy_api_gen/src/passes/codegen.rs b/crates/bevy_api_gen/src/passes/codegen.rs index 6a2a1a68..cd2e9ccd 100644 --- a/crates/bevy_api_gen/src/passes/codegen.rs +++ b/crates/bevy_api_gen/src/passes/codegen.rs @@ -37,6 +37,7 @@ pub(crate) fn codegen(ctxt: &mut BevyCtxt<'_>, args: &Args) -> bool { .expect("Failed to render crate artifact"); file.flush().unwrap(); + log::trace!("Written files"); true } diff --git a/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs b/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs index 9046dadd..5224ae4e 100644 --- a/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs +++ b/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs @@ -205,7 +205,7 @@ pub(crate) fn find_methods_and_fields(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> is_unsafe, def_id: fn_did, has_self, - trait_did, + trait_and_impl_did: trait_did.map(|td| (td, *impl_did)), reflection_strategies, }) }) @@ -331,6 +331,7 @@ fn type_is_adt_and_reflectable<'tcx>( ty.ty_adt_def().is_some_and(|adt_def| { let did = adt_def.did(); + // even though our meta might already be written at this point, we use this as a quick out if reflect_types.contains_key(&did) { // local types are easy to check return true; @@ -343,24 +344,18 @@ fn type_is_adt_and_reflectable<'tcx>( // so search for these metas! let crate_name = tcx.crate_name(did.krate).to_ident_string(); - let meta_sources = if tcx.crate_name(LOCAL_CRATE).as_str() == "bevy_reflect" { - // otherwise meta loader might expect the meta to exist - vec![crate_name] - } else { - vec![crate_name, "bevy_reflect".to_string()] - }; - - let meta = match meta_sources.iter().find_map(|s| meta_loader.meta_for(s)) { - Some(meta) => meta, - None => return false, // TODO: is it possible we get false negatives here ? perhaps due to parallel compilation ? or possibly because of dependency order - }; + let contains_hash = meta_loader.one_of_meta_files_contains( + &[&crate_name, "bevy_reflect"], + Some(&tcx.crate_name(LOCAL_CRATE).to_ident_string()), + tcx.def_path_hash(did), + ); - let contains_hash = meta.contains_def_path_hash(tcx.def_path_hash(did)); log::trace!( "Meta for type: `{}`, contained in meta `{}`", tcx.item_name(did), contains_hash ); + contains_hash }) } diff --git a/crates/bevy_api_gen/src/passes/find_trait_impls.rs b/crates/bevy_api_gen/src/passes/find_trait_impls.rs index 65f65e31..1232fb84 100644 --- a/crates/bevy_api_gen/src/passes/find_trait_impls.rs +++ b/crates/bevy_api_gen/src/passes/find_trait_impls.rs @@ -136,6 +136,7 @@ fn impl_matches<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>, impl_def_id: DefId) let ocx = ObligationCtxt::new(infcx); let param_env = tcx.param_env_reveal_all_normalized(impl_def_id); let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id); + let impl_trait_ref = tcx .impl_trait_ref(impl_def_id) .expect("Expected defid to be an impl for a trait") diff --git a/crates/bevy_api_gen/src/passes/populate_template_data.rs b/crates/bevy_api_gen/src/passes/populate_template_data.rs index e5aff8e6..a5a64a77 100644 --- a/crates/bevy_api_gen/src/passes/populate_template_data.rs +++ b/crates/bevy_api_gen/src/passes/populate_template_data.rs @@ -1,9 +1,11 @@ -use std::fmt::Write; +use std::{any::Any, borrow::Cow, convert::identity}; -use log::trace; +use log::{trace, warn}; use rustc_ast::Attribute; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; -use rustc_middle::ty::{FieldDef, ParamTy, Ty, TyKind, TypeFoldable}; +use rustc_middle::ty::{ + AdtDef, FieldDef, GenericArg, GenericParamDefKind, ParamTy, TraitRef, Ty, TyKind, TypeFoldable, +}; use rustc_span::Symbol; use crate::{ @@ -126,7 +128,7 @@ pub(crate) fn process_fields<'f, I: Iterator>( .map(|field| Field { docstrings: docstrings(ctxt.tcx.get_attrs_unchecked(field.did)), ident: field.name.to_ident_string(), - ty: ty_to_string(ctxt, ctxt.tcx.type_of(field.did).skip_binder()), + ty: ty_to_string(ctxt, ctxt.tcx.type_of(field.did).skip_binder(), false), reflection_strategy: *ty_ctxt .get_field_reflection_strat(field.did) .unwrap_or_else(|| panic!("{ty_ctxt:#?}")), @@ -145,52 +147,25 @@ pub(crate) fn process_functions(ctxt: &BevyCtxt, fns: &[FunctionContext]) -> Vec .zip(fn_sig.inputs()) .enumerate() .map(|(idx, (ident, ty))| { - let (ident, ty) = if fn_ctxt.has_self && idx == 0 { - // self argument, we want to map to something like `&self` instead of `&Component` - // we do that by renaming every adt inside to "self" - // this is a bit hacky but it works, might not work if we decide to support generics in the future - // TODO: fix to work with generics - let ty = ty.fold_with(&mut rustc_middle::ty::fold::BottomUpFolder { - tcx: ctxt.tcx, - ty_op: |ty| { - if ty.is_adt() { - ctxt.tcx.mk_ty_from_kind(TyKind::Param(ParamTy::new( - 0, - Symbol::intern("self"), - ))) - } else { - ty - } - }, - lt_op: |lt| lt, - ct_op: |ct| ct, - }); - (None, ty) - } else { - (ident.to_string().into(), *ty) - }; - // remove projections like `::AssocType` - let ty = ty_to_string( - ctxt, - ctxt.tcx - .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), ty), - ); + let normalized_ty = ctxt + .tcx + .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), *ty); Arg { - ident, - ty, + ident: ident.to_string(), + ty: ty_to_string(ctxt, normalized_ty, false), + proxy_ty: ty_to_string(ctxt, normalized_ty, true), reflection_strategy: fn_ctxt.reflection_strategies[idx], } }) .collect(); - let ty = ty_to_string( - ctxt, - ctxt.tcx - .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), fn_sig.output()), - ); + let out_ty = ctxt + .tcx + .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), fn_sig.output()); let output = Output { - ty, + ty: ty_to_string(ctxt, out_ty, false), + proxy_ty: ty_to_string(ctxt, out_ty, true), reflection_strategy: *fn_ctxt.reflection_strategies.last().unwrap(), }; @@ -203,9 +178,11 @@ pub(crate) fn process_functions(ctxt: &BevyCtxt, fns: &[FunctionContext]) -> Vec output, has_self: fn_ctxt.has_self, docstrings: docstrings(ctxt.tcx.get_attrs_unchecked(fn_ctxt.def_id)), - from_trait_path: fn_ctxt - .trait_did - .map(|trait_did| import_path(ctxt, trait_did)), + from_trait_path: fn_ctxt.trait_and_impl_did.map(|(_, impl_did)| { + let trait_ref = ctxt.tcx.impl_trait_ref(impl_did).unwrap().skip_binder(); + + trait_ref_to_string(ctxt, trait_ref) + }), } }) .collect() @@ -236,51 +213,271 @@ pub(crate) fn import_path(ctxt: &BevyCtxt, def_id: DefId) -> String { } /// Normalizes type import paths in types before printing them -fn ty_to_string<'tcx>(ctxt: &BevyCtxt<'tcx>, ty: Ty<'tcx>) -> String { +fn ty_to_string<'tcx>(ctxt: &BevyCtxt<'tcx>, ty: Ty<'tcx>, proxy_types: bool) -> String { // walk through the type and replace all paths with their standardised import paths - TyPrinter::new().print(&ctxt.path_finder, ty) + TyPrinter::new( + Box::new(|ty| { + ty.ty_adt_def() + .map(|def| { + let def_id = def.did(); + let def_path_hash = ctxt.tcx.def_path_hash(def_id); + let meta_sources = [ + &ctxt.tcx.crate_name(def_id.krate).to_ident_string(), + "bevy_reflect", + ]; + + ctxt.meta_loader.one_of_meta_files_contains( + &meta_sources, + Some(&ctxt.tcx.crate_name(LOCAL_CRATE).to_ident_string()), + def_path_hash, + ) + }) + .is_some_and(identity) + }), + Box::new(|did| Cow::Owned(import_path(ctxt, did))), + proxy_types, + ) + .print(ty) } -struct TyPrinter { +/// Converts a specific trait instantiation (in the context of an impl) into a string taking into account correctly the +/// import transformations and generics +/// TODO: this doesn't explicitly print out associated types, because I don't think it's necessary yet and annoying to do (idk how to do it) +fn trait_ref_to_string<'tcx>(ctxt: &BevyCtxt<'tcx>, trait_ref: TraitRef<'tcx>) -> String { + let generics_def = ctxt.tcx.generics_of(trait_ref.def_id); + + let generic_args = trait_ref + .args + .iter() + .enumerate() + .skip(if generics_def.has_self { 1 } else { 0 }) + .map(|(idx, a)| (a, generics_def.param_at(idx, ctxt.tcx))) + // filter out non const | type generics and the compiler generated ones + .filter(|(_, arg_def)| match arg_def.kind { + GenericParamDefKind::Lifetime => false, + GenericParamDefKind::Const { is_host_effect, .. } => !is_host_effect, + _ => true, + }) + .map(|(arg, arg_def)| { + log::trace!("Printing for trait: `{trait_ref}` arg: `{arg}`, with def: `{arg_def:#?}`"); + + let arg_ty = if let Some(ty) = arg.as_type() { + ty + } else if let Some(const_) = arg.as_const() { + const_.ty() + } else { + unreachable!("should be filtered") + }; + + ty_to_string(ctxt, arg_ty, false) + }) + .collect::>(); + + let trait_path = import_path(ctxt, trait_ref.def_id); + + if generic_args.is_empty() { + trait_path + } else { + format!("{trait_path}::<{}>", generic_args.join(", ")) + } +} + +#[derive(Clone, Copy)] +pub(crate) enum ProxyType { + Ref, + RefMut, + Val, + NonReflectVal, +} + +impl ProxyType { + pub fn to_ident_str(self) -> &'static str { + match self { + ProxyType::Ref => "LuaReflectRefProxy", + ProxyType::RefMut => "LuaReflectRefMutProxy", + ProxyType::Val => "LuaReflectValProxy", + ProxyType::NonReflectVal => "LuaValProxy", + } + } +} +/// Pretty prints types fully using the given import path finder or ADT's +struct TyPrinter<'a> { buffer: String, + path_finder: Box Cow<'static, str> + 'a>, + is_proxied_check: Box) -> bool + 'a>, + /// If true will wrap types in appropriate proxies instead of directly pringting the type + proxy_types: bool, } -impl TyPrinter { - pub fn new() -> Self { +impl<'a> TyPrinter<'a> { + pub fn new( + is_proxied_check: Box) -> bool + 'a>, + path_finder: Box Cow<'static, str> + 'a>, + proxy_types: bool, + ) -> Self { TyPrinter { buffer: String::new(), + is_proxied_check, + proxy_types, + path_finder, } } - pub fn print(mut self, path_finder: &ImportPathFinder, ty: Ty<'_>) -> String { - self.build_str(path_finder, ty); + + pub fn print(mut self, ty: Ty<'_>) -> String { + log::trace!("Printing type: {:#?}", ty); + self.print_ty(ty); self.buffer } - fn build_str(&mut self, path_finder: &ImportPathFinder, ty: Ty<'_>) { + fn print_args<'tcx, I: Iterator>>(&mut self, mut args: I) { + let mut next = args.next(); + if next.is_some() { + self.buffer.push('<'); + while let Some(arg) = next { + let ty = if let Some(ty) = arg.as_type() { + ty + } else if let Some(const_) = arg.as_const() { + const_.ty() + } else { + next = args.next(); + continue; + }; + self.print_ty(ty); + + next = args.next(); + if next.is_some() { + self.buffer.push_str(", "); + } + } + + self.buffer.push('>'); + } + } + + fn print_adt<'tcx, I: Iterator>>(&mut self, ty: AdtDef<'tcx>, args: I) { + log::trace!("Printing ADT: {:#?}", ty); + let did = ty.did(); + let import_path = (self.path_finder)(did); + self.buffer.push_str(&import_path); + self.print_args(args); + } + + fn print_ty(&mut self, ty: Ty<'_>) { + log::trace!("Printing type: {:#?}", ty); + match ty.kind() { - TyKind::Adt(adt_def, args) => { - let did = adt_def.did(); - let import_path = path_finder - .find_import_paths(did) - .first() - .unwrap() - .to_owned(); - self.buffer.push_str(&import_path); - if args.len() > 0 { - self.buffer.push('<'); - for (idx, a) in args.iter().enumerate() { - match a.as_type() { - Some(ty) => self.build_str(path_finder, ty), - None => _ = self.buffer.write_str(&a.to_string()), - } - if idx != args.len() - 1 { - self.buffer.push_str(", "); - } + TyKind::Bool => self.print_literal("bool"), + TyKind::Char => self.print_literal("char"), + TyKind::Str => self.print_literal("str"), + TyKind::Int(ty) => self.print_literal(ty.name_str()), + TyKind::Uint(ty) => self.print_literal(ty.name_str()), + TyKind::Float(ty) => self.print_literal(ty.name_str()), + TyKind::Adt(adt_ty, args) => { + if self.proxy_types { + self.print_proxied_ty(ty, ProxyType::Val); + } else { + self.print_adt(*adt_ty, args.iter()); + } + } + TyKind::Array(ty, const_) => { + self.buffer.push('['); + self.print_ty(*ty); + self.buffer.push(';'); + // shortcut, we won't encounter ADT's here just use native printer + self.buffer.push_str(&const_.to_string()); + self.buffer.push(']'); + } + TyKind::Slice(ty) => { + self.buffer.push('['); + self.print_ty(*ty); + self.buffer.push(']'); + } + TyKind::RawPtr(ptr) => { + self.buffer.push('*'); + if ptr.mutbl.is_mut() { + self.buffer.push_str("mut "); + } + self.print_ty(ptr.ty); + } + TyKind::Ref(_, ty, mut_) => { + if self.proxy_types { + let proxy_type = if mut_.is_mut() { + ProxyType::RefMut + } else { + ProxyType::Ref + }; + self.print_proxied_ty(*ty, proxy_type); + } else { + self.buffer.push('&'); + if mut_.is_mut() { + self.buffer.push_str("mut "); + } + self.print_ty(*ty); + } + } + TyKind::Tuple(tys) => { + self.buffer.push('('); + for (idx, ty) in tys.iter().enumerate() { + self.print_ty(ty); + if idx != tys.len() - 1 { + self.buffer.push(','); } - self.buffer.push('>'); } + self.buffer.push(')'); + } + TyKind::Alias(_, ty) => { + self.buffer.push_str(&(self.path_finder)(ty.def_id)); + self.print_args(ty.args.iter()); + } + // self is one I think + TyKind::Param(param) => self.print_literal(param.name.as_str()), + _ => { + warn!( + "Type outside the scope of the TyPrinter being printed: pretty=`{}` kind=`{:?}`", + ty, ty.kind() + ); + self.buffer.push_str(&ty.to_string()) } - _ => self.buffer.push_str(&ty.to_string()), } } + + /// prints a type but without making further proxies at this level + /// i.e. a &T will be printed as RefProxy instead of RefProxy> since the T will not be printed via print_ty but directly here + /// But only for ADT's, other types are printed as normal + fn print_proxied_ty(&mut self, ty: Ty<'_>, proxy_type: ProxyType) { + match ty.kind() { + TyKind::Adt(adt_ty, args) => { + if (self.is_proxied_check)(ty) { + self.print_literal_surround_content( + proxy_type.to_ident_str(), + '<', + '>', + |self_| { + self_.print_adt(*adt_ty, args.iter()); + }, + ); + } else { + self.print_adt(*adt_ty, args.iter()) + } + } + _ => self.print_ty(ty), + } + } + + fn print_literal_surround_content( + &mut self, + literal: &str, + start: char, + end: char, + f: F, + ) { + self.buffer.push_str(literal); + self.buffer.push(start); + f(self); + self.buffer.push(end); + } + + fn print_literal(&mut self, literal: &str) { + self.buffer.push_str(literal); + } } diff --git a/crates/bevy_api_gen/src/plugin.rs b/crates/bevy_api_gen/src/plugin.rs index b365458e..1e0d73a2 100644 --- a/crates/bevy_api_gen/src/plugin.rs +++ b/crates/bevy_api_gen/src/plugin.rs @@ -53,7 +53,9 @@ impl RustcPlugin for BevyAnalyzer { let mut callbacks = BevyAnalyzerCallbacks::new(plugin_args); let mut compiler = rustc_driver::RunCompiler::new(&compiler_args, &mut callbacks); compiler.set_file_loader(Some(Box::new(ModifyingFileLoader))); - compiler.run() + let out = compiler.run(); + log::trace!("Finished compiling with plugin"); + out } fn modify_cargo(&self, cmd: &mut std::process::Command, args: &Self::Args) { diff --git a/crates/bevy_api_gen/src/template.rs b/crates/bevy_api_gen/src/template.rs index ce8774e1..ddb9d029 100644 --- a/crates/bevy_api_gen/src/template.rs +++ b/crates/bevy_api_gen/src/template.rs @@ -111,17 +111,21 @@ pub(crate) struct Function { pub(crate) struct Arg { /// the name of the argument as in source code /// None if this is a receiver, in which case ty contains the ident - pub(crate) ident: Option, + pub(crate) ident: String, /// the type of argument /// i.e. `&Vec` pub(crate) ty: String, + /// The proxied type of argument for use in Unproxy and Proxy targetted code + /// i.e. AppropriateRefProxy instead of &MyTy for a reference + pub(crate) proxy_ty: String, pub(crate) reflection_strategy: ReflectionStrategy, } #[derive(Serialize)] pub(crate) struct Output { pub(crate) ty: String, + pub(crate) proxy_ty: String, pub(crate) reflection_strategy: ReflectionStrategy, } diff --git a/crates/bevy_api_gen/templates/field.tera b/crates/bevy_api_gen/templates/field.tera index bf9baae5..ea5fb145 100644 --- a/crates/bevy_api_gen/templates/field.tera +++ b/crates/bevy_api_gen/templates/field.tera @@ -1,6 +1,4 @@ -{%- if field.reflection_strategy == "Proxy" -%} - #[lua(output(proxy))] -{%- elif field.reflection_strategy == "Filtered" -%} +{%- if field.reflection_strategy == "Filtered" -%} #[lua(skip)] {%- endif -%} @@ -10,6 +8,6 @@ {% if field.reflection_strategy != "Reflection" -%} {{- field.ty -}} {%- else -%} -ReflectedValue +ReflectReference {%- endif -%} , diff --git a/crates/bevy_api_gen/templates/footer.tera b/crates/bevy_api_gen/templates/footer.tera index b14a4794..87a76308 100644 --- a/crates/bevy_api_gen/templates/footer.tera +++ b/crates/bevy_api_gen/templates/footer.tera @@ -1,70 +1,53 @@ +{% if args.self_is_bms_lua %} +{% set bms_lua_path="crate" %} +{% else %} +{% set bms_lua_path="bevy_mod_scripting::lua"%} +{% endif %} + #[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>>( +impl {{bms_lua_path}}::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: {{bms_lua_path}}::tealr::mlu::InstanceCollector<'lua>>( self, instances: &mut T, - ) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + ) -> {{bms_lua_path}}::tealr::mlu::mlua::Result<()> { {% for item in items %} {% if item.has_static_methods %} instances.add_instance("{{ item.ident }}", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::<{{item.ident | prefix_lua}}>::new)?; + {{bms_lua_path}}::tealr::mlu::UserDataProxy::<{{item.ident | prefix_lua}}>::new)?; {% endif %} {% endfor %} Ok(()) } } -pub struct {{ "A P I Provider" | prefix_cratename | convert_case(case="upper_camel")}}; - -impl bevy_mod_scripting_core::hosts::APIProvider for {{ "A P I Provider" | prefix_cratename | convert_case(case="upper_camel") }} { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some(bevy_mod_scripting_lua::docs::LuaDocFragment::new("{{ "A P I" | prefix_cratename | convert_case(case="upper_camel") }}", |tw| { - tw - .document_global_instance::().expect("Something went wrong documenting globals") - {% for item in items %} - .process_type::<{{ item.ident | prefix_lua }}>() - {% if item.has_static_methods %} - .process_type::>() - {% endif %} - {% endfor %} - } - )) - } - 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 {{ "ContextInitializer" | prefix_cratename | convert_case(case="snake") }} (_: &bevy_mod_scripting_core::script::ScriptId, ctx: &mut {{bms_lua_path}}::prelude::Lua) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + {{bms_lua_path}}::tealr::mlu::set_global_env(Globals, ctx)?; + 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(()) - } +pub struct {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}}; - fn register_with_app(&self, app: &mut bevy::app::App) { +impl bevy::app::Plugin for {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}} { + fn build(&self, app: &mut bevy::prelude::App) { {% for item in items %} - app.register_foreign_lua_type::<{{ item.import_path }}>(); + app.register_proxy::<{{ item.import_path }}>(); {% endfor %} + app.add_context_initializer::<()>({{ "ContextInitializer" | prefix_cratename | convert_case(case="snake") }}); + app.add_documentation_fragment( + {{bms_lua_path}}::docs::LuaDocumentationFragment::new("{{ "A P I" | prefix_cratename | convert_case(case="upper_camel") }}", |tw| { + tw + .document_global_instance::().expect("Something went wrong documenting globals") + {% for item in items %} + .process_type::<{{ item.ident | prefix_lua }}>() + {% if item.has_static_methods %} + .process_type::<{{bms_lua_path}}::tealr::mlu::UserDataProxy<{{ item.ident | prefix_lua }}>>() + {% endif %} + {% endfor %} + } + ) + ); } } \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/function.tera b/crates/bevy_api_gen/templates/function.tera index a525af9b..970eebdf 100644 --- a/crates/bevy_api_gen/templates/function.tera +++ b/crates/bevy_api_gen/templates/function.tera @@ -13,6 +13,11 @@ r#" as_trait="{{ function.from_trait_path }}", {%- endif -%} +{% if is_op %} +composite="{{ function.ident }}", +{% endif %} + +{# {% if function.has_self and not is_op %} kind="{% if function.args.0.ty is starting_with("&mut") %}Mutating{% endif %}Method", {% elif is_op %} @@ -25,9 +30,7 @@ kind="Function", output(proxy), {%- endif -%} -{% if is_op %} -composite="{{ function.ident }}", -{% endif %} + {% if function.from_trait_path == "std::ops::Neg" %} metamethod="Unm", @@ -44,23 +47,22 @@ metamethod="Mod", {% elif function.from_trait_path == "std::cmp::PartialEq" %} metamethod="Eq", {% endif %} - +#} )] {% if function.is_unsafe %}unsafe {% endif -%}fn {{ function.ident }} ( {%- filter separated(delimeter=", ", split_at="---", ignore_first=true) -%} {%- for arg in function.args -%} --- - {%- if arg.ident and arg.reflection_strategy == "Proxy" -%} - #[proxy] - {%- endif -%} - {%- if arg.ident -%} - {{- arg.ident }} : {# -#} + {%- if arg.ident != "self" -%} + {{- arg.ident -}} + {%- else -%} + _{{- arg.ident -}} {%- endif -%} - {{- arg.ty -}} + : {{- arg.proxy_ty -}} {%- endfor -%} {%- endfilter -%} -) -> {{ function.output.ty -}}; +) -> {{ function.output.proxy_ty -}}; {%- endfilter %} "# \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/header.tera b/crates/bevy_api_gen/templates/header.tera index e40a725a..2cdbb574 100644 --- a/crates/bevy_api_gen/templates/header.tera +++ b/crates/bevy_api_gen/templates/header.tera @@ -8,8 +8,11 @@ use super::{{crate}}::*; {% endif %} {% endfor %} -{% if args.self_is_bevy_script_api %} -extern crate self as bevy_script_api; -{% endif %} -use bevy_script_api::{lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld}; \ No newline at end of file +use bevy_mod_scripting_core::{AddContextInitializer, StoreDocumentation, bindings::ReflectReference}; + +{% if args.self_is_bms_lua %} +use crate::{bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,IdentityProxy},RegisterLuaProxy, tealr::mlu::mlua::IntoLua}; +{% else %} +use bevy_mod_scripting::{lua::bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,IdentityProxy}, RegisterLuaProxy, tealr::mlu::mlua::IntoLua}; +{% endif %} \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/item.tera b/crates/bevy_api_gen/templates/item.tera index f40dfaac..43bb345e 100644 --- a/crates/bevy_api_gen/templates/item.tera +++ b/crates/bevy_api_gen/templates/item.tera @@ -3,14 +3,20 @@ {# for now #} {% endfor %} +{% if args.self_is_bms_lua %} +{% set bms_core_path="bevy_mod_scripting_core" %} +{% set bms_lua_path="crate" %} +{% else %} +{% set bms_core_path="bevy_mod_scripting::core" %} +{% set bms_lua_path="bevy_mod_scripting::lua" %} +{% endif %} + #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( -derive( - {%- if item.impls_clone -%} - clone, - {%- endif -%} -), remote="{{ item.import_path }}", +bms_core_path="{{bms_core_path}}", +bms_lua_path="{{bms_lua_path}}", + functions[ {%- filter separated(delimeter=",\n\t\t\t", split_at="---", ignore_first=true) -%} {%- for function in item.functions -%} @@ -61,7 +67,7 @@ functions[ r#" {%- set mat_type = item.import_path | split(pat="::") | last -%} {%- set col_type = mat_type | replace(from="Mat", to="Vec")-%} - {{- macros::matrix_index(col_type=col_type,mat_type=mat_type)-}} + {{- macros::matrix_index(col_type=col_type,mat_type=mat_type,bms_core_path=bms_core_path)-}} "# {% endif %} {%- endfilter -%} diff --git a/crates/bevy_api_gen/templates/macros.tera b/crates/bevy_api_gen/templates/macros.tera index 4e75fc50..ef5b5783 100644 --- a/crates/bevy_api_gen/templates/macros.tera +++ b/crates/bevy_api_gen/templates/macros.tera @@ -1,51 +1,47 @@ {% macro vector_index(num_type) %} -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result<{{ num_type }},_> { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy<{{ num_type }}> { + _self[idx - 1] } {% endmacro vector_index %} {% macro vector_newindex(num_type) %} -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: {{ num_type }}) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: {{ num_type }}) -> () { + _self[idx - 1] = val } {% endmacro vector_newindex %} -{% macro matrix_index(col_type, mat_type) %} -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result<{{ col_type | prefix_lua }},_> { - Ok({{ col_type | prefix_lua }}::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +{% macro matrix_index(col_type, mat_type, bms_core_path) %} +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy<{{ col_type | prefix_lua }}> { + let mut curr_ref = _self.0.clone(); + let def_ref = {{bms_core_path}}::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push({{bms_core_path}}::bindings::ReflectionPathElem::new_deferred(def_ref)); + {{ col_type | prefix_lua }}(curr_ref) } {% endmacro matrix_index %} {% macro debug_as_to_string() %} -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } {% endmacro debug_as_to_string %} {% macro display_as_to_string() %} -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{}", _self) } diff --git a/crates/bevy_api_gen/templates/mod.tera b/crates/bevy_api_gen/templates/mod.tera index 95dd89ce..44530bb5 100644 --- a/crates/bevy_api_gen/templates/mod.tera +++ b/crates/bevy_api_gen/templates/mod.tera @@ -7,66 +7,14 @@ pub(crate) mod {{ crate.name }}; {% endfor -%} -{% if args.self_is_bevy_script_api %} -extern crate self as bevy_script_api; -{% endif %} - -use bevy_mod_scripting_core::docs::DocFragment; - - pub struct {{ api_name }}; -impl bevy_mod_scripting_core::hosts::APIProvider for {{ api_name }} { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - - fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { +impl bevy::app::Plugin for {{ api_name }} { + fn build(&self, app: &mut bevy::prelude::App) { {% for crate in crates %} - {% set crate_name = crate.name %} - {{ crate_name }}::{{ "A P I Provider" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.attach_api(ctx)?; - {% endfor %} - Ok(()) - } - - fn get_doc_fragment(&self) -> Option { - [ - {% for crate in crates %} - {% set crate_name = crate.name %} - {{ crate_name }}::{{ "A P I Provider" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.get_doc_fragment(), - {% endfor %} - ] - .into_iter() - .filter_map(|a: Option<_>| a) - .fold(None, |a, b| match a { - Some(a) => Some(a.merge(b)), - None => Some(b), - }) - } - - 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) { - {% for crate in crates %} - {% set crate_name = crate.name %} - {{ crate_name }}::{{ "A P I Provider" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.register_with_app(app); + {% set crate_name = crate.name %} + {{ crate_name }}::{{ "ScriptingPlugin" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.build(app); {% endfor %} } } - {% endfilter %} \ No newline at end of file diff --git a/crates/bevy_event_priority/Cargo.toml b/crates/bevy_event_priority/Cargo.toml deleted file mode 100644 index b6f3594f..00000000 --- a/crates/bevy_event_priority/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "bevy_event_priority" -version = "0.6.0" -authors = ["Maksymilian Mozolewski "] -edition = "2021" -license = "MIT OR Apache-2.0" -description = "Bevy plugin providing priority based event handling" -repository = "https://github.com/makspll/bevy_mod_scripting" -homepage = "https://github.com/makspll/bevy_mod_scripting" -keywords = ["bevy", "gamedev", "scripting", "lua"] -categories = ["game-development"] -readme = "readme.md" - - -[lib] -name = "bevy_event_priority" -path = "src/lib.rs" - -[dependencies] -bevy = { workspace = true, default-features = false } diff --git a/crates/bevy_event_priority/readme.md b/crates/bevy_event_priority/readme.md deleted file mode 100644 index d29e4756..00000000 --- a/crates/bevy_event_priority/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# bevy_event_priority - -This crate is a part of the ["bevy_mod_scripting" workspace](https://github.com/makspll/bevy_mod_scripting). \ No newline at end of file diff --git a/crates/bevy_event_priority/src/lib.rs b/crates/bevy_event_priority/src/lib.rs deleted file mode 100644 index 98e7546e..00000000 --- a/crates/bevy_event_priority/src/lib.rs +++ /dev/null @@ -1,412 +0,0 @@ -use bevy::ecs::system::SystemParam; -use bevy::prelude::*; -use std::marker::PhantomData; -use std::sync::atomic::Ordering::Relaxed; -use std::{collections::BinaryHeap, sync::atomic::AtomicU32}; - -pub trait PriorityEvent: Send + Sync + 'static {} -impl PriorityEvent for E {} - -#[derive(Debug)] -struct EventInstance { - prio: u32, - event_id: u32, - event: E, -} - -impl EventInstance { - fn new(event: E, prio: u32) -> Self { - static COUNTER: AtomicU32 = AtomicU32::new(0); - - Self { - prio, - event_id: COUNTER.fetch_add(1, Relaxed), - event, - } - } -} - -impl PartialEq for EventInstance { - fn eq(&self, other: &Self) -> bool { - self.prio == other.prio && self.event_id == other.event_id - } -} -impl Eq for EventInstance {} - -impl Ord for EventInstance { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - match self.prio.cmp(&other.prio) { - std::cmp::Ordering::Equal => self.event_id.cmp(&other.event_id), - v => v, - } - .reverse() - } -} -impl PartialOrd for EventInstance { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Clone for EventInstance { - fn clone(&self) -> Self { - Self { - prio: self.prio, - event_id: self.event_id, - event: self.event.clone(), - } - } -} - -/// An event priority queue. -/// Used when the ordering of events should be influenced by other factors. -/// This implementation does NOT provide double buffering. -/// Writers and readers are expected to remove events as soon as they are read, -/// this implies a one to one mapping between events and event handlers. -#[derive(Debug, Resource)] -pub struct PriorityEvents { - events: BinaryHeap>, -} - -impl Default for PriorityEvents { - fn default() -> Self { - Self { - events: BinaryHeap::new(), - } - } -} - -#[derive(SystemParam)] -pub struct PriorityEventReader<'w, 's, E: PriorityEvent> { - events: ResMut<'w, PriorityEvents>, - #[system_param(ignore)] - marker: PhantomData<&'s usize>, -} - -pub struct PriorityIterator<'w, E: PriorityEvent> { - min: u32, - max: u32, - events: &'w mut PriorityEvents, -} - -impl<'w, E: PriorityEvent> Iterator for PriorityIterator<'w, E> { - type Item = E; - - fn next(&mut self) -> Option { - while let Some(e) = self.events.events.peek() { - if e.prio > self.min { - return None; - } else if e.prio < self.max { - // discard events which should have already run - self.events.events.pop(); - } else { - break; - }; - } - - self.events.events.pop().map(|e| e.event) - } -} - -impl<'s, E: PriorityEvent> PriorityEventReader<'_, 's, E> { - /// Iterates over events this reader has not seen yet, while also clearing them. - /// Will not remove any events of priority lower than min (0 is highest, inf is lowest) - /// but will discard events of higher priority - /// i.e. will handle events in the priority range [min,max] (inclusive) - pub fn iter_prio_range(&mut self, max: u32, min: u32) -> impl Iterator + '_ { - PriorityIterator { - min, - max, - events: self.events.as_mut(), - } - } - - /// Determines the number of events available to be read, without consuming any - pub fn len(&self) -> usize { - self.events.events.len() - } - - /// Determines if there are any events to be read, without consuming any. - pub fn is_empty(&self) -> bool { - self.len() == 0 - } -} - -#[derive(SystemParam)] -pub struct PriorityEventWriter<'w, 's, E: PriorityEvent> { - events: ResMut<'w, PriorityEvents>, - - #[system_param(ignore)] - marker: PhantomData<&'s usize>, -} - -impl<'w, 's, E: PriorityEvent> PriorityEventWriter<'w, 's, E> { - pub fn send(&mut self, event: E, prio: u32) { - self.events.events.push(EventInstance::new(event, prio)); - } - - pub fn send_batch(&mut self, events: impl Iterator, prio: u32) { - self.events - .events - .extend(events.map(|v| EventInstance::new(v, prio))) - } - - pub fn send_default(&mut self, prio: u32) - where - E: Default, - { - self.events - .events - .push(EventInstance::new(E::default(), prio)) - } -} - -/// a convenience for initialising prioritised event types -pub trait AddPriorityEvent { - fn add_priority_event(&mut self) -> &mut Self; -} - -impl AddPriorityEvent for App { - fn add_priority_event(&mut self) -> &mut Self { - self.init_resource::>(); - - self - } -} - -#[cfg(test)] -mod tests { - use bevy::{ecs::system::SystemState, prelude::World}; - - use super::*; - - #[derive(Copy, Clone, PartialEq, Eq, Debug)] - struct TestEvent(usize); - - fn collect_events(events: BinaryHeap>) -> Vec { - events - .into_sorted_vec() - .iter() - .map(|e| e.event) - .rev() - .collect() - } - - #[test] - fn test_events() { - let mut world = World::new(); - let mut state_writer: SystemState> = - SystemState::new(&mut world); - let mut state_reader: SystemState> = - SystemState::new(&mut world); - - world.init_resource::>(); - - // stage 1 - - { - let mut w = state_writer.get_mut(&mut world); - - // system writes three events, out of order - w.send(TestEvent(0), 5); - w.send(TestEvent(1), 1); - w.send(TestEvent(2), 0); - } - - // events are send and ordered in decreasing priority order - assert_eq!( - collect_events(world.resource::>().events.clone()), - vec![TestEvent(2), TestEvent(1), TestEvent(0)] - ); - - // stage 2 - - { - let mut w = state_reader.get_mut(&mut world); - - // system reads only top event - w.iter_prio_range(0, 0).for_each(drop); - } - - // first event is consumed immediately - assert_eq!( - collect_events(world.resource::>().events.clone()), - vec![TestEvent(1), TestEvent(0)] - ); - - // stage 3 - - { - let mut w = state_reader.get_mut(&mut world); - - // system reads all events - w.iter_prio_range(1, 5).for_each(drop); - } - - // first event is consumed immediately - assert_eq!( - collect_events(world.resource::>().events.clone()), - Vec::default() - ); - } - - #[test] - fn test_not_cleared_events() { - let mut world = World::new(); - let mut state_writer: SystemState> = - SystemState::new(&mut world); - let mut state_reader: SystemState> = - SystemState::new(&mut world); - - world.init_resource::>(); - - // two systems run at different frequencies, both serve non-overlapping priorities - - // stage 1 - // system sends events of lower priority than it serves - { - let mut w = state_writer.get_mut(&mut world); - - w.send(TestEvent(0), 1); - } - { - let mut w = state_reader.get_mut(&mut world); - - w.iter_prio_range(0, 0).for_each(drop); - } - - assert_eq!( - collect_events(world.resource::>().events.clone()), - vec![TestEvent(0)] - ); - - // stage 2 - // same system runs writes another of the same event - - { - let mut w = state_writer.get_mut(&mut world); - - w.send(TestEvent(0), 1); - } - { - let mut w = state_reader.get_mut(&mut world); - - w.iter_prio_range(0, 0).for_each(drop); - } - - assert_eq!( - collect_events(world.resource::>().events.clone()), - vec![TestEvent(0), TestEvent(0)] - ); - - // stage 3 - // this time another system runs clearing those events - { - let mut w = state_reader.get_mut(&mut world); - - w.iter_prio_range(1, 1).for_each(drop); - } - assert_eq!( - collect_events(world.resource::>().events.clone()), - Vec::default() - ); - } - - #[test] - fn test_higher_prio_destroyed() { - let mut world = World::new(); - let mut state_writer: SystemState> = - SystemState::new(&mut world); - let mut state_reader: SystemState> = - SystemState::new(&mut world); - - world.init_resource::>(); - - // two systems run at different frequencies, both serve non-overlapping priorities - - // stage 1 - // system sends events of higher priority than another serves - { - let mut w = state_writer.get_mut(&mut world); - - w.send(TestEvent(0), 0); - } - - // stage 2 - // system receives event of higher priority than it serves - { - let mut w = state_reader.get_mut(&mut world); - - // event is not read but discarded - assert_eq!( - w.iter_prio_range(1, 1).collect::>(), - Vec::default() - ); - } - - // the event is cleared - assert_eq!( - collect_events(world.resource::>().events.clone()), - vec![] - ); - } - - #[test] - fn test_prio_range() { - let mut world = World::new(); - let mut state_writer: SystemState> = - SystemState::new(&mut world); - let mut state_reader: SystemState> = - SystemState::new(&mut world); - - world.init_resource::>(); - - // two systems run at different frequencies, both serve non-overlapping priorities - - // stage 1 - // system sends events of various priorities - { - let mut w = state_writer.get_mut(&mut world); - - w.send(TestEvent(0), 0); - w.send(TestEvent(1), 1); - w.send(TestEvent(2), 2); - w.send(TestEvent(3), 3); - w.send(TestEvent(4), 4); - w.send(TestEvent(5), 5); - } - - // stage 2 - // multiple systems in order of priority remove them one by one - { - let mut w = state_reader.get_mut(&mut world); - - assert_eq!( - w.iter_prio_range(0, 1).collect::>(), - vec![TestEvent(0), TestEvent(1)] - ); - - assert_eq!( - w.iter_prio_range(2, 2).collect::>(), - vec![TestEvent(2)] - ); - - assert_eq!( - w.iter_prio_range(3, 3).collect::>(), - vec![TestEvent(3)] - ); - - // 4 is discarded - assert_eq!( - w.iter_prio_range(5, 5).collect::>(), - vec![TestEvent(5)] - ); - } - - // the events are all cleared - assert_eq!( - collect_events(world.resource::>().events.clone()), - vec![] - ); - } -} diff --git a/crates/bevy_mod_scripting_common/Cargo.toml b/crates/bevy_mod_scripting_common/Cargo.toml deleted file mode 100644 index 3bd15938..00000000 --- a/crates/bevy_mod_scripting_common/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -name = "bevy_mod_scripting_common" -version = "0.6.0" -authors = ["Maksymilian Mozolewski "] -edition = "2021" -license = "MIT OR Apache-2.0" -description = "Traits and syn structures for language implementors" -repository = "https://github.com/makspll/bevy_mod_scripting" -homepage = "https://github.com/makspll/bevy_mod_scripting" -keywords = ["bevy", "gamedev", "scripting", "lua"] -categories = ["game-development"] -readme = "readme.md" - -[lib] -name = "bevy_mod_scripting_common" -path = "src/lib.rs" - -[dependencies] -darling = "0.20.3" -paste = "1.0.7" -syn = { version = "2.0.38", features = [ - "full", - "fold", - "extra-traits", - "visit-mut", -] } -quote = "1.0.8" -proc-macro2 = "1.0" -convert_case = "0.5.0" -serde = { version = "1.0", features = ["derive"] } -serde_derive = "1.0.137" -indexmap = { version = "1.9.1", features = ["serde"] } -strum = { version = "0.24.1", features = ["derive"] } diff --git a/crates/bevy_mod_scripting_common/readme.md b/crates/bevy_mod_scripting_common/readme.md deleted file mode 100644 index 674bf81c..00000000 --- a/crates/bevy_mod_scripting_common/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# bevy_mod_scripting_common - -This crate is a part of the ["bevy_mod_scripting" workspace](https://github.com/makspll/bevy_mod_scripting). \ No newline at end of file diff --git a/crates/bevy_mod_scripting_common/src/input.rs b/crates/bevy_mod_scripting_common/src/input.rs deleted file mode 100644 index 57aaac37..00000000 --- a/crates/bevy_mod_scripting_common/src/input.rs +++ /dev/null @@ -1,675 +0,0 @@ -use darling::{util::Flag, FromDeriveInput, FromMeta}; -use proc_macro2::Ident; -use quote::format_ident; -use std::{ - collections::HashMap, - ops::{Deref, DerefMut}, - str::FromStr, -}; -use strum::{Display, EnumString}; -use syn::{ - punctuated::Punctuated, - spanned::Spanned, - token::{And, Gt, Lt, Mut, PathSep}, - visit_mut::VisitMut, - AngleBracketedGenericArguments, Attribute, Error, Field, Fields, GenericArgument, PatType, - Path, PathArguments, PathSegment, Receiver, TraitItemFn, Type, TypePath, TypeReference, - TypeTuple, Variant, -}; - -use crate::utils::ident_to_type_path; - -/// Flags which detail required functionality or additional derivation requirements -#[derive(Debug, FromMeta, Default)] -pub struct ProxyFlags { - pub clone: Flag, -} - -/// Enumeration of commonly encountered Rust standard library type identifiers which can be effectively proxied in Lua, -/// These types are `container` types, which wrap other types rather than standalone and literal types. -#[derive(EnumString, Debug, Clone, Copy, Display, PartialEq, Eq)] -pub enum StdTypeIdent { - Option, - Result, - Vec, - Box, - Rc, - Arc, - Cow, - Cell, - RefCell, - Mutex, - RwLock, - Pin, -} - -/// Detailed information about the proxy, here we can access fields/variants etc. -#[derive(Debug)] -pub enum ProxyData { - Struct { fields: Fields }, -} - -/// For types of the form `Option` i.e. an outer identifier with a nested type inside angle brackets. -/// This type helps us destructure these patterns and unwrap/wrap proxies fully without dealing with the complicated full syn::Type enum -#[derive(Debug, Clone)] -pub struct UnitPath { - pub std_type_ident: Option, - pub ident: Ident, - pub colon2_token: Option, - pub lt_token: Lt, - pub gt_token: Gt, - pub inner: Box, -} - -/// For types of the form `Result` i.e. an outer identifier with two nested types inside angle brackets. -#[derive(Debug, Clone)] -pub struct DuoPath { - pub std_type_ident: Option, - pub ident: Ident, - pub colon2_token: Option, - pub lt_token: Lt, - pub gt_token: Gt, - pub left: Box, - pub right: Box, -} - -/// Represents a type prefixed with an outer reference, e.g. `&T` or `&mut T` -#[derive(Debug, Clone)] -pub struct Reference { - pub and_token: And, - pub mutability: Option, - pub inner: Box, -} - -/// Represents the identifier part of a type which doubles as a proxy type, e.g. `T` in `Option` -/// Stores both the proxied and proxy identifier i.e. `T` and `LuaT` -#[derive(Debug, Clone)] -pub struct ProxyType { - pub proxied_path: Path, - pub proxy_ident: Ident, -} - -/// Proxies can also be returned in "container" types, such as: -/// - Option -/// - Result -/// - Vec -/// - Tuple -/// This type helps us destructure these patterns and unwrap/wrap proxies fully without dealing with the full syn::Type enum -#[derive(Debug, Clone)] -pub enum SimpleType { - /// The unit type `()` - Unit, - /// A type of the form `Option` - UnitPath(UnitPath), - /// A type of the form `Result` a list containing two elements is referred to as a - DuoPath(DuoPath), - - /// A type with an outer reference, e.g. `&T` or `&mut T` - Reference(Reference), - /// A type which doubles as a proxy type, e.g. `T` in `Option` - ProxyType(ProxyType), - /// A type which is not a proxy type, e.g. `i32`, required for composite types which can contain both proxy and non-proxy types - /// like tuples: `(i32, T)` - Type(syn::Type), -} - -impl SimpleType { - /// Constructs a new SimpleProxyType from a `syn::FnArg` using contextual resolution for receivers such as `Self` and `self` with the proxied type identifier given. - pub fn new_from_fn_arg( - proxy_prefix: &'static str, - arg: &syn::FnArg, - proxied_type_path: &Path, - proxied_to_proxy_ident_map: &HashMap>, - ) -> Result { - match arg { - syn::FnArg::Receiver(Receiver { - reference, - mutability, - .. - }) => match reference { - Some((and, ..)) => { - let mutability = mutability.as_ref().copied(); - let inner = Box::new(SimpleType::new_from_contextual_type( - proxy_prefix, - &Type::Path(TypePath { - qself: None, - path: proxied_type_path.clone(), - }), - proxied_type_path, - proxied_to_proxy_ident_map, - )?); - Ok(Self::Reference(Reference { - and_token: *and, - mutability, - inner, - })) - } - None => Self::new_from_contextual_type( - proxy_prefix, - &Type::Path(TypePath { - qself: None, - path: proxied_type_path.clone(), - }), - proxied_type_path, - proxied_to_proxy_ident_map, - ), - }, - syn::FnArg::Typed(PatType { ty, .. }) => Self::new_from_contextual_type( - proxy_prefix, - ty.as_ref(), - proxied_type_path, - proxied_to_proxy_ident_map, - ), - } - } - - /// Constructs a new SimpleProxyType from a `syn::Type`, contextual receivers such as `Self` and `self` will cause an error - /// to be returned. - pub fn new_from_fully_specified_type( - proxy_prefix: &'static str, - proxied_type: &Type, - proxied_to_proxy_ident_map: &HashMap>, - ) -> Result { - Self::new_from_type( - proxy_prefix, - proxied_type, - None, - proxied_to_proxy_ident_map, - false, - ) - } - - pub fn new_from_fully_specified_type_proxy_all( - proxy_prefix: &'static str, - proxied_type: &Type, - ) -> Result { - Self::new_from_type(proxy_prefix, proxied_type, None, &Default::default(), true) - } - - /// Constructs a new SimpleProxyType from a `syn::Type`, contextual receivers such as `Self` and `self` will be replaced - /// with the given identifier prefixed with the proxy_prefix - pub fn new_from_contextual_type( - proxy_prefix: &'static str, - proxied_type: &Type, - proxied_type_path: &Path, - proxied_to_proxy_ident_map: &HashMap>, - ) -> Result { - Self::new_from_type( - proxy_prefix, - proxied_type, - Some(proxied_type_path), - proxied_to_proxy_ident_map, - false, - ) - } - - /// Constructs a new SimpleProxyType from a `syn::Type`, contextual receivers such as `Self` and `self` will be replaced - /// with the given identifier prefixed with the proxy_prefix - /// All types will be proxied with the given proxy prefix - pub fn new_from_contextual_type_proxy_all( - proxy_prefix: &'static str, - proxied_type: &Type, - proxied_type_path: &Path, - ) -> Result { - Self::new_from_type( - proxy_prefix, - proxied_type, - Some(proxied_type_path), - &Default::default(), - true, - ) - } - - /// Builds a SimpleType::ProxyType or SimpleType::Type depending on the passed data, - /// - if the proxied type identifier has a Some value in the proxied_to_proxy_ident_map map then the proxy_ident will be set to the value in the map, - /// - if it has a None value it will be set to the proxied type identifier prefixed with the proxy_prefix, - /// - If it's not in the map it's built as a SimpleType::Type - fn new_proxied_type_or_type( - proxy_prefix: &'static str, - proxied_path: Path, - proxied_to_proxy_ident_map: &HashMap>, - proxy_prefix_all: bool, - ) -> SimpleType { - let last_segment = &proxied_path.segments.last().unwrap().ident; - let replacement_ident = proxied_to_proxy_ident_map.get(last_segment); - - if proxy_prefix_all || replacement_ident.is_some() { - let proxy_ident = replacement_ident - .cloned() - .flatten() - .unwrap_or_else(|| format_ident!("{proxy_prefix}{}", last_segment)); - - SimpleType::ProxyType(ProxyType { - proxied_path, - proxy_ident, - }) - } else { - Self::Type(syn::Type::Path(TypePath { - qself: None, - path: proxied_path.clone(), - })) - } - } - - /// Constructs a new SimpleProxyType from a `syn::Type`, if `proxied_type_identifier` is given then contextual - /// receivers such as `Self` and `self` will be replaced with the given identifier prefixed with the proxy_prefix, otherwise an error will be returned. - /// types with base identifiers not in the proxied_to_proxy_ident_map list are treated as non-proxy types and will be wrapped in a SimpleProxyType::Type. - /// If the proxy_prefix_all option is passed, the ident map will be ignored and EVERY type inside will be treated as a default proxy (prefixed with the proxy prefix as well) - fn new_from_type( - proxy_prefix: &'static str, - proxied_type: &Type, - proxied_type_path: Option<&Path>, - proxied_to_proxy_ident_map: &HashMap>, - proxy_prefix_all: bool, - ) -> Result { - match proxied_type { - Type::Path(p) if p.path.is_ident("self") || p.path.is_ident("Self") => { - let proxied_path: &Path = proxied_type_path.ok_or_else(|| { - Error::new_spanned( - proxied_type, - "Did not expect contextual receiver in constructing simple proxy type" - .to_owned(), - ) - })?; - Ok(Self::new_proxied_type_or_type( - proxy_prefix, - proxied_path.clone(), - proxied_to_proxy_ident_map, - proxy_prefix_all, - )) - } - Type::Path(p) if !p.path.segments.is_empty() => { - let last_segment = p.path.segments.last().unwrap(); - if last_segment.arguments.is_empty() { - return Ok(Self::new_proxied_type_or_type( - proxy_prefix, - p.path.clone(), - proxied_to_proxy_ident_map, - proxy_prefix_all, - )); - } else if let PathArguments::AngleBracketed(args) = &last_segment.arguments { - if args.args.len() == 1 { - if let GenericArgument::Type(arg_type) = args.args.first().unwrap() { - let inner = Box::new(Self::new_from_type( - proxy_prefix, - arg_type, - proxied_type_path, - proxied_to_proxy_ident_map, - proxy_prefix_all, - )?); - return Ok(SimpleType::UnitPath(UnitPath { - std_type_ident: StdTypeIdent::from_str( - &last_segment.ident.to_string(), - ) - .ok(), - ident: last_segment.ident.clone(), - colon2_token: args.colon2_token, - lt_token: args.lt_token, - gt_token: args.gt_token, - inner, - })); - } - } else if args.args.len() == 2 { - let mut args_iter = args.args.iter(); - if let (GenericArgument::Type(left), GenericArgument::Type(right)) = - (args_iter.next().unwrap(), args_iter.next().unwrap()) - { - let left = Box::new(Self::new_from_type( - proxy_prefix, - left, - proxied_type_path, - proxied_to_proxy_ident_map, - proxy_prefix_all, - )?); - let right = Box::new(Self::new_from_type( - proxy_prefix, - right, - proxied_type_path, - proxied_to_proxy_ident_map, - proxy_prefix_all, - )?); - return Ok(SimpleType::DuoPath(DuoPath { - std_type_ident: StdTypeIdent::from_str( - &last_segment.ident.to_string(), - ) - .ok(), - ident: last_segment.ident.clone(), - colon2_token: args.colon2_token, - lt_token: args.lt_token, - gt_token: args.gt_token, - left, - right, - })); - } - } - } - Err(Error::new_spanned( - proxied_type, - "Unsupported type".to_owned(), - )) - } - Type::Reference(tr) => Ok(SimpleType::Reference(Reference { - and_token: tr.and_token, - mutability: tr.mutability, - inner: Box::new(Self::new_from_type( - proxy_prefix, - &tr.elem, - proxied_type_path, - proxied_to_proxy_ident_map, - proxy_prefix_all, - )?), - })), - Type::Infer(_) => Ok(SimpleType::Type(proxied_type.clone())), - Type::Tuple(TypeTuple { elems, .. }) if elems.is_empty() => Ok(SimpleType::Unit), - t => Ok(SimpleType::Type(t.clone())), - } - } - - /// Returns true if the type has an outer reference, (e.g. `&Type`) - pub fn has_outer_ref(&self) -> bool { - matches!(self, SimpleType::Reference { .. }) - } - - pub fn has_outer_mut_ref(&self) -> bool { - matches!(self, SimpleType::Reference (Reference{ mutability, .. }) if mutability.is_some()) - } - - /// Returns true if the type has an inner reference, (e.g. `Type<&T>`) - pub fn has_ref(&self) -> bool { - match self { - SimpleType::Unit => false, - SimpleType::UnitPath(UnitPath { inner, .. }) => inner.has_ref(), - SimpleType::DuoPath(DuoPath { left, right, .. }) => left.has_ref() || right.has_ref(), - SimpleType::Reference(_) => true, - SimpleType::ProxyType(ProxyType { .. }) => false, - SimpleType::Type(_) => false, - } - } - - /// Returns true if the type has an inner proxy type - pub fn contains_proxy_type(&self) -> bool { - match self { - SimpleType::Unit => false, - SimpleType::UnitPath(UnitPath { inner, .. }) => inner.contains_proxy_type(), - SimpleType::DuoPath(DuoPath { left, right, .. }) => { - left.contains_proxy_type() || right.contains_proxy_type() - } - SimpleType::Reference(Reference { inner, .. }) => inner.contains_proxy_type(), - SimpleType::ProxyType(_) => true, - SimpleType::Type(_) => false, - } - } -} - -pub trait VisitSimpleType -where - T: std::fmt::Debug, -{ - fn visit(&mut self, simple_type: &SimpleType) -> T { - self.visit_simple_type(simple_type, false) - } - - fn visit_simple_type(&mut self, simple_type: &SimpleType, is_child_of_reference: bool) -> T { - match simple_type { - SimpleType::Unit => self.visit_unit(is_child_of_reference), - SimpleType::UnitPath(unit_path) => { - self.visit_unit_path(unit_path, is_child_of_reference) - } - SimpleType::DuoPath(duo_path) => self.visit_duo_path(duo_path, is_child_of_reference), - SimpleType::Reference(reference) => { - self.visit_reference(reference, is_child_of_reference) - } - SimpleType::ProxyType(proxy_type) => { - self.visit_proxy_type(proxy_type, is_child_of_reference) - } - SimpleType::Type(_type) => self.visit_type(_type, is_child_of_reference), - } - } - fn visit_unit_path(&mut self, unit_path: &UnitPath, _is_child_of_reference: bool) -> T { - self.visit_simple_type(&unit_path.inner, false) - } - - fn visit_duo_path(&mut self, duo_path: &DuoPath, _is_child_of_reference: bool) -> T { - self.visit_simple_type(&duo_path.left, false); - self.visit_simple_type(&duo_path.right, false) - } - - fn visit_reference(&mut self, reference: &Reference, _is_child_of_reference: bool) -> T { - self.visit_simple_type(&reference.inner, true) - } - fn visit_unit(&mut self, is_child_of_reference: bool) -> T; - fn visit_proxy_type(&mut self, proxy_type: &ProxyType, is_child_of_reference: bool) -> T; - fn visit_type(&mut self, _type: &Type, is_child_of_reference: bool) -> T; -} - -pub struct TypeConstructorVisitor { - /// if true then leaf proxies will be converted to their proxy type, otherwise they will be converted to their proxied type - pub generate_proxy_type: bool, - pub strip_outer_ref: bool, -} - -impl TypeConstructorVisitor { - pub fn new(generate_proxy_type: bool, strip_outer_ref: bool) -> Self { - Self { - generate_proxy_type, - strip_outer_ref, - } - } -} - -impl VisitSimpleType for TypeConstructorVisitor { - fn visit_unit(&mut self, _: bool) -> Type { - Type::Tuple(TypeTuple { - paren_token: Default::default(), - elems: Default::default(), - }) - } - - fn visit_unit_path(&mut self, unit_path: &UnitPath, _: bool) -> Type { - Type::Path(TypePath { - qself: None, - path: PathSegment { - ident: unit_path.ident.clone(), - arguments: PathArguments::AngleBracketed(AngleBracketedGenericArguments { - colon2_token: unit_path.colon2_token, - lt_token: unit_path.lt_token, - args: Punctuated::from_iter([GenericArgument::Type( - self.visit_simple_type(&unit_path.inner, false), - )]), - gt_token: unit_path.gt_token, - }), - } - .into(), - }) - } - - fn visit_duo_path(&mut self, duo_path: &DuoPath, _: bool) -> Type { - let left = self.visit_simple_type(&duo_path.left, false); - let right = self.visit_simple_type(&duo_path.right, false); - - Type::Path(TypePath { - qself: None, - path: PathSegment { - ident: duo_path.ident.clone(), - arguments: PathArguments::AngleBracketed(AngleBracketedGenericArguments { - colon2_token: duo_path.colon2_token, - lt_token: duo_path.lt_token, - args: Punctuated::from_iter([ - GenericArgument::Type(left), - GenericArgument::Type(right), - ]), - gt_token: duo_path.gt_token, - }), - } - .into(), - }) - } - - fn visit_proxy_type(&mut self, proxy_type: &ProxyType, _: bool) -> Type { - if self.generate_proxy_type { - Type::Path(ident_to_type_path(proxy_type.proxy_ident.clone())) - } else { - Type::Path(TypePath { - qself: None, - path: proxy_type.proxied_path.clone(), - }) - } - } - - fn visit_type(&mut self, _type: &Type, _: bool) -> Type { - _type.clone() - } - - fn visit_reference(&mut self, reference: &Reference, _: bool) -> Type { - if self.strip_outer_ref { - self.visit_simple_type(&reference.inner, false) - } else { - self.strip_outer_ref = false; - Type::Reference(TypeReference { - and_token: reference.and_token, - lifetime: None, - mutability: reference.mutability, - elem: Box::new(self.visit_simple_type(&reference.inner, true)), - }) - } - } -} - -#[derive(FromDeriveInput)] -#[darling(attributes(proxy), forward_attrs(allow, doc, cfg))] -pub struct ProxyInput { - /// The name of the type for which we are generating a proxy - pub ident: syn::Ident, - pub attrs: Vec, - - pub remote: Option, - /// The name to use for the proxy type, if not provided the language derive macro - /// will generate one using a standard prefix. - #[darling(rename = "name")] - pub proxy_name: Option, - - /// The body of the type for which we are generating a proxy - pub data: darling::ast::Data, - - /// Flags signifying which additional trait implementation should be generated on the proxy type - #[darling(default)] - pub derive: ProxyFlags, - - /// A list of multi-lang function definitions to be generated on the proxy type - #[darling(default)] - pub functions: TraitItemFnsWrapper, -} - -#[derive(Default)] -pub struct TraitItemFnsWrapper(pub Vec); - -impl FromMeta for TraitItemFnsWrapper { - fn from_string(value: &str) -> darling::Result { - let token_stream: proc_macro2::TokenStream = value.parse().map_err(syn::Error::from)?; - let trait_items_vec = vec![syn::parse2(token_stream)?]; - Ok(TraitItemFnsWrapper(trait_items_vec)) - } - - fn from_list(items: &[darling::ast::NestedMeta]) -> darling::Result { - Ok(TraitItemFnsWrapper( - items - .iter() - .map(Self::from_nested_meta) - .collect::, _>>()? - .into_iter() - .flat_map(|v| v.0.into_iter()) - .collect::>(), - )) - } -} - -impl Deref for TraitItemFnsWrapper { - type Target = Vec; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} -impl DerefMut for TraitItemFnsWrapper { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -/// Replaces every occurence of an identifier with -/// the given string while preserving the original span -pub struct IdentifierRenamingVisitor<'a> { - pub target: &'a str, - pub replacement: &'a str, -} - -impl VisitMut for IdentifierRenamingVisitor<'_> { - fn visit_ident_mut(&mut self, i: &mut Ident) { - if *i == self.target { - *i = Ident::new(self.replacement, i.span()); - } - } -} - -#[cfg(test)] -mod test { - use super::VisitSimpleType; - - struct TestVisitor; - impl VisitSimpleType for TestVisitor { - fn visit_unit(&mut self, is_child_of_reference: bool) -> bool { - is_child_of_reference - } - fn visit_proxy_type(&mut self, _: &super::ProxyType, is_child_of_reference: bool) -> bool { - is_child_of_reference - } - fn visit_type(&mut self, _: &syn::Type, is_child_of_reference: bool) -> bool { - is_child_of_reference - } - } - - #[test] - pub fn test_child_of_reference() { - let mut visitor = TestVisitor; - assert!(!visitor.visit(&super::SimpleType::Unit)); - assert!( - !visitor.visit(&super::SimpleType::ProxyType(super::ProxyType { - proxied_path: syn::Ident::new("T", proc_macro2::Span::call_site()).into(), - proxy_ident: syn::Ident::new("LuaT", proc_macro2::Span::call_site()), - })) - ); - assert!( - !visitor.visit(&super::SimpleType::Type(syn::Type::Path(syn::TypePath { - qself: None, - path: syn::Path::from(syn::Ident::new("T", proc_macro2::Span::call_site())), - }))) - ); - assert!( - visitor.visit(&super::SimpleType::Reference(super::Reference { - and_token: syn::Token![&](proc_macro2::Span::call_site()), - mutability: None, - inner: Box::new(super::SimpleType::Unit), - })) - ); - assert!( - visitor.visit(&super::SimpleType::Reference(super::Reference { - and_token: syn::Token![&](proc_macro2::Span::call_site()), - mutability: None, - inner: Box::new(super::SimpleType::ProxyType(super::ProxyType { - proxied_path: syn::Ident::new("T", proc_macro2::Span::call_site()).into(), - proxy_ident: syn::Ident::new("LuaT", proc_macro2::Span::call_site()), - })), - })) - ); - assert!( - visitor.visit(&super::SimpleType::Reference(super::Reference { - and_token: syn::Token![&](proc_macro2::Span::call_site()), - mutability: None, - inner: Box::new(super::SimpleType::Type(syn::Type::Path(syn::TypePath { - qself: None, - path: syn::Path::from(syn::Ident::new("T", proc_macro2::Span::call_site())), - }))), - })) - ); - } -} diff --git a/crates/bevy_mod_scripting_common/src/lib.rs b/crates/bevy_mod_scripting_common/src/lib.rs deleted file mode 100644 index 5d7b01f9..00000000 --- a/crates/bevy_mod_scripting_common/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod input; -pub mod utils; diff --git a/crates/bevy_mod_scripting_core/Cargo.toml b/crates/bevy_mod_scripting_core/Cargo.toml index b09b6df8..12297108 100644 --- a/crates/bevy_mod_scripting_core/Cargo.toml +++ b/crates/bevy_mod_scripting_core/Cargo.toml @@ -21,19 +21,8 @@ doc_always = [] [dependencies] -bevy = { workspace = true, default-features = false, features = [ - "bevy_asset", - "bevy_gltf", - "bevy_animation", - "bevy_core_pipeline", - "bevy_ui", - "bevy_pbr", - "bevy_render", - "bevy_text", - "bevy_sprite", -] } -bevy_event_priority = { path = "../bevy_event_priority", version = "0.6.0" } +bevy = { workspace = true, default-features = false, features = ["bevy_asset"] } thiserror = "1.0.31" paste = "1.0.7" parking_lot = "0.12.1" -anyhow = "1.0.75" +lockable = "0.0.8" diff --git a/crates/bevy_mod_scripting_core/src/asset.rs b/crates/bevy_mod_scripting_core/src/asset.rs index 1dc86bb2..f72d1e7f 100644 --- a/crates/bevy_mod_scripting_core/src/asset.rs +++ b/crates/bevy_mod_scripting_core/src/asset.rs @@ -1,8 +1,87 @@ -use bevy::asset::Asset; +use std::{ + borrow::Cow, + path::{Path, PathBuf}, +}; -/// All code assets share this common interface. -/// When adding a new code asset don't forget to implement asset loading -/// and inserting appropriate systems when registering with the app -pub trait CodeAsset: Asset { - fn bytes(&self) -> &[u8]; +use bevy::{ + asset::{Asset, AssetLoader, AsyncReadExt}, + ecs::system::Resource, + reflect::TypePath, + utils::BoxedFuture, +}; + +use crate::{prelude::ScriptError, script::ScriptId}; + +/// Represents a script loaded into memory as an asset +#[derive(Asset, TypePath)] +pub struct ScriptAsset { + pub content: Box<[u8]>, + /// The virtual filesystem path of the asset, used to map to the script Id for asset backed scripts + pub asset_path: PathBuf, + pub language: Cow<'static, str>, +} + +pub struct ScriptAssetLoader { + /// Used to set the language of the script + pub language: Cow<'static, str>, + /// The file extensions this loader should handle + pub extensions: &'static [&'static str], + /// preprocessor to run on the script before saving the content to an asset + pub preprocessor: Option Result<(), ScriptError> + Send + Sync>>, +} + +impl AssetLoader for ScriptAssetLoader { + type Asset = ScriptAsset; + + type Settings = (); + + type Error = ScriptError; + + fn load<'a>( + &'a self, + reader: &'a mut bevy::asset::io::Reader<'_>, + _settings: &'a Self::Settings, + load_context: &'a mut bevy::asset::LoadContext<'_>, + ) -> BoxedFuture<'a, Result> { + Box::pin(async move { + let mut content = Vec::new(); + reader.read_to_end(&mut content).await.map_err(|e| { + ScriptError::new_lifecycle_error(e).with_context(load_context.asset_path()) + })?; + if let Some(processor) = &self.preprocessor { + processor(&mut content)?; + } + let asset = ScriptAsset { + content: content.into_boxed_slice(), + asset_path: load_context.path().to_owned(), + language: self.language.clone(), + }; + Ok(asset) + }) + } + + fn extensions(&self) -> &[&str] { + self.extensions + } +} + +#[derive(Clone, Copy, Resource)] +pub struct ScriptAssetSettings { + pub script_id_mapper: AssetPathToScriptIdMapper, +} + +impl Default for ScriptAssetSettings { + fn default() -> Self { + Self { + script_id_mapper: AssetPathToScriptIdMapper { + map: (|path: &Path| path.to_string_lossy().into_owned().into()), + }, + } + } +} + +/// Strategy for mapping asset paths to script ids, by default this is the identity function +#[derive(Clone, Copy)] +pub struct AssetPathToScriptIdMapper { + pub map: fn(&Path) -> ScriptId, } diff --git a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs new file mode 100644 index 00000000..fe2d2734 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs @@ -0,0 +1,94 @@ +use bevy::ecs::system::Resource; +use bevy::reflect::Reflect; +use std::any::TypeId; +use std::cell::UnsafeCell; +use std::collections::HashMap; +use std::fmt::{Display, Formatter}; +use std::sync::Arc; + +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct ReflectAllocationId(pub(crate) usize); +impl ReflectAllocationId { + pub fn id(&self) -> usize { + self.0 + } +} + +#[derive(Clone, Debug)] +pub struct ReflectAllocation(pub(self) Arc>); + +unsafe impl Send for ReflectAllocation {} +unsafe impl Sync for ReflectAllocation {} + +impl ReflectAllocation { + pub fn get_ptr(&self) -> *mut dyn Reflect { + self.0.get() + } + pub fn new(value: Arc>) -> Self { + Self(value) + } +} + +impl Display for ReflectAllocationId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +/// Allocator used to allocate and deallocate `dyn Reflect` values +/// Used to be able to ensure we have a "common root" for values allocated outside the world. +#[derive(Resource, Default)] +pub struct ReflectAllocator { + // TODO: experiment with object pools, sparse set etc. + allocations: HashMap, + types: HashMap, +} + +impl ReflectAllocator { + /// Allocates a new [`Reflect`] value and returns an [`AllocationId`] which can be used to access it later + pub fn allocate(&mut self, value: T) -> (ReflectAllocationId, ReflectAllocation) { + let id = ReflectAllocationId(self.allocations.len()); + let value = ReflectAllocation::new(Arc::new(UnsafeCell::new(value))); + self.allocations.insert(id, value.clone()); + self.types.insert(id, TypeId::of::()); + (id, value) + } + + pub fn get(&self, id: ReflectAllocationId) -> Option { + self.allocations.get(&id).cloned() + } + + pub fn get_type_id(&self, id: ReflectAllocationId) -> Option { + self.types.get(&id).cloned() + } + + pub fn get_mut(&self, id: ReflectAllocationId) -> Option { + self.allocations.get(&id).cloned() + } + + /// Deallocates the [`Reflect`] value with the given [`AllocationId`] + pub fn deallocate(&mut self, id: ReflectAllocationId) { + self.allocations.remove(&id); + } + + /// Runs a garbage collection pass on the allocations, removing any allocations which have no more strong references + /// Needs to be run periodically to prevent memory leaks + pub fn clean_garbage_allocations(&mut self) { + self.allocations.retain(|_, v| Arc::strong_count(&v.0) > 1); + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_reflect_allocator() { + let mut allocator = ReflectAllocator::default(); + let (id, val) = allocator.allocate(0); + assert_eq!(allocator.allocations.len(), 1); + drop(val); + allocator.clean_garbage_allocations(); + assert_eq!(allocator.allocations.len(), 0); + } +} diff --git a/crates/bevy_mod_scripting_core/src/bindings/mod.rs b/crates/bevy_mod_scripting_core/src/bindings/mod.rs new file mode 100644 index 00000000..24f8ddf4 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/mod.rs @@ -0,0 +1,7 @@ +pub mod allocator; +pub mod proxy; +pub mod query; +pub mod reference; +pub mod world; + +pub use {allocator::*, proxy::*, query::*, reference::*, world::*}; diff --git a/crates/bevy_mod_scripting_core/src/bindings/proxy.rs b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs new file mode 100644 index 00000000..31d5793a --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs @@ -0,0 +1,1119 @@ +//! Set of traits used to define how types are turned into and from proxies in Lua. +//! Proxies can either be logical "copies" or owned "direct representations" of the instance, or references to one via the [`bevy_mod_scripting_core::bindings::ReflectReference`] construct. +use std::{ + cell::UnsafeCell, + marker::PhantomData, + num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}, + sync::Arc, +}; + +use bevy::{ + reflect::{FromReflect, Reflect, TypeRegistry}, + utils::smallvec::SmallVec, +}; + +use crate::{ + bindings::ReflectAllocation, + error::ScriptResult, + prelude::{ReflectAllocator, ScriptError}, +}; + +use super::{ + world::{WorldAccessGuard, WorldAccessUnit, WorldAccessWrite}, + ReflectReference, DEFAULT_INTERVAL, DEFAULT_TIMEOUT, +}; + +/// Inverse to [`Unproxy`], packages up a type into a proxy type. +pub trait Proxy: Sized { + type Input<'a>; + + /// Proxies a type without access to the allocator, types which require access to the allocator will throw an error here + fn proxy<'a>(input: Self::Input<'a>) -> ScriptResult { + Err(ScriptError::new_reflection_error(format!( + "Cannot unproxy type: `{}` without allocator access. Use proxy_with_allocator instead.", + std::any::type_name::(), + ))) + } + + /// Proxies a type with access to the allocator + fn proxy_with_allocator<'a>( + input: Self::Input<'a>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + Self::proxy(input) + } +} + +/// A mechanism for converting proxy types into their represented types. +/// Note this can be implemented by 'meta-proxy' types which themselves aren't proxies, but wrap other proxies and provide a specific unproxying mechanism. +/// `RefProxy` and `RefMutProxy` are such 'meta-proxy' types. +/// +/// the [`Unproxy::Output`] type parameter is the type that this `proxy` will be converted to after unwrapping. +/// +pub trait Unproxy { + type Output<'o> + where + Self: 'o; + + fn collect_accesses<'w>( + &self, + _guard: &WorldAccessGuard<'w>, + _accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + Ok(()) + } + + fn accesses_len(&self) -> usize { + 0 + } + + /// Unproxies a proxy type into the represented type without world access + /// This will fail on proxies which require world access to unproxy (for example those whose proxies are glorified [`ReflectReference`]'s ) + fn unproxy<'o>(&'o mut self) -> ScriptResult> { + Err(ScriptError::new_reflection_error(format!( + "Cannot unproxy type: `{}` without world access. Use unproxy_with_world instead", + std::any::type_name::(), + ))) + } + + /// Unproxies a proxy type into the represented type with world access + /// # Safety + /// - The caller must not use the accesses in the accesses list after the unproxy call at all, as implementors assume they have unique access to the accesses. + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + _guard: &WorldAccessGuard<'w>, + _accesses: &'o [WorldAccessUnit<'w>], + _type_registry: &TypeRegistry, + _allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + self.unproxy() + } +} + +/// A wrapper type which when unproxied will return a `T` value. +/// Requires the type to be constructible from a reference to the proxy type. +#[derive(Debug, PartialEq, Eq)] +pub struct ValProxy(pub P, PhantomData); + +impl ValProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +/// A wrapper type which when unproxied will return a `T` value. +/// Assumes that the proxy type contains a [`ReflectReference`] via [`AsRef`] +#[derive(PartialEq, Eq, Debug)] +pub struct ReflectValProxy(pub P, PhantomData); + +impl ReflectValProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +/// A proxy type which when unproxied will return a reference to a `T` value. +/// Assumes that the proxy type contains a [`ReflectReference`] via [`AsRef`] +pub struct ReflectRefProxy(pub P, PhantomData); + +impl ReflectRefProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +/// A proxy type which when unproxied will return a mutable reference to a `T` value. +/// Assumes that the proxy type contains a [`ReflectReference`] via [`AsRef`] +#[derive(Debug)] +pub struct ReflectRefMutProxy(pub P, PhantomData); + +impl ReflectRefMutProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +impl Unproxy for ValProxy +where + T: for<'l> From<&'l P>, +{ + type Output<'o> = T where Self: 'o; + + fn unproxy<'o>(&'o mut self) -> ScriptResult> { + Ok(T::from(&self.0)) + } +} + +impl Proxy for ValProxy +where + T: Into

, +{ + type Input<'a> = T; + + fn proxy<'a>(input: Self::Input<'a>) -> ScriptResult { + Ok(ValProxy::new(input.into())) + } +} + +impl Proxy for ReflectValProxy +where + T: Reflect, + P: From, +{ + type Input<'a> = T; + + fn proxy_with_allocator<'a>( + input: Self::Input<'a>, + allocator: &mut ReflectAllocator, + ) -> ScriptResult { + Ok(Self::new( + ReflectReference::new_allocated(input, allocator).into(), + )) + } +} + +impl Unproxy for ReflectValProxy +where + P: AsRef, + T: FromReflect, +{ + type Output<'o> = T where Self: 'o; + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + _accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = reflect_ref.base.base_id.get_reflect_access_id(); + let access = guard + .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not unproxy type: `{}`. Aliasing access.", + std::any::type_name::() + )) + })?; + let out = reflect_ref.reflect( + guard.as_unsafe_world_cell(), + &access, + type_registry, + Some(allocator), + )?; + let out = T::from_reflect(out).ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "FromReflect failed for `{}`.", + std::any::type_name::() + )) + })?; + guard.release_access(access); + Ok(out) + } +} + +impl Proxy for ReflectRefProxy +where + T: FromReflect, + P: From, +{ + type Input<'a> = &'a T; + + fn proxy_with_allocator<'a>( + input: Self::Input<'a>, + allocator: &mut ReflectAllocator, + ) -> ScriptResult { + let inner = T::from_reflect(input).ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "FromReflect failed for `{}`.", + std::any::type_name::() + )) + })?; + Ok(Self::new( + ReflectReference::new_allocated(inner, allocator).into(), + )) + } +} + +impl Unproxy for ReflectRefProxy +where + P: AsRef, + T: Reflect, +{ + type Output<'o> = &'o T where Self: 'o; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessUnit<'w>; 1]>, + ) -> ScriptResult<()> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = reflect_ref.base.base_id.get_reflect_access_id(); + let access = guard + .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not unproxy type: `{}`. Aliasing access.", + std::any::type_name::() + )) + })?; + accesses.push(access); + Ok(()) + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = accesses.last().ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "No required access collected when unproxying type: `{}`.", + std::any::type_name::() + )) + })?; + + let out = reflect_ref.reflect( + guard.as_unsafe_world_cell(), + access, + type_registry, + Some(allocator), + )?; + let out = out.downcast_ref().ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not downcast value from reflect reference to type: `{}`.", + std::any::type_name::() + )) + })?; + Ok(out) + } + + fn accesses_len(&self) -> usize { + 1 + } +} + +impl Unproxy for ReflectRefMutProxy +where + P: AsRef, + T: Reflect, +{ + type Output<'o> = &'o mut T where Self: 'o; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessUnit<'w>; 1]>, + ) -> ScriptResult<()> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = reflect_ref.base.base_id.get_reflect_access_id(); + let access = guard + .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not unproxy type: `{}`. Aliasing access.", + std::any::type_name::() + )) + })?; + accesses.push(access); + Ok(()) + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + accesses + .last() + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "No required access collected when unproxying type: `{}`.", + std::any::type_name::() + )) + }) + .and_then(|access| { + reflect_ref.expect_write_access( + access, + type_registry, + Some(allocator), + guard.as_unsafe_world_cell(), + ) + })?; + + // Safety: + // - we verified and we have the right access + // - the caller promises not to alias it from the root access + let out = unsafe { + reflect_ref.reflect_mut_unsafe( + guard.as_unsafe_world_cell(), + type_registry, + Some(allocator), + )? + }; + let out = out.downcast_mut().ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not downcast value from reflect reference to type: `{}`.", + std::any::type_name::() + )) + })?; + Ok(out) + } + + fn accesses_len(&self) -> usize { + 1 + } +} + +macro_rules! impl_unproxy_via_vec { + ($type:ty, $out_type:ty, ($($generics:tt)*)) => { + impl<'c, $($generics)*> Unproxy for $type { + type Output<'o> = $out_type where Self: 'o; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessUnit<'w>; 1]>, + ) -> ScriptResult<()> { + for item in self { + item.collect_accesses(guard, accesses)?; + } + Ok(()) + } + + fn accesses_len(&self) -> usize { + self.iter().map(|item| item.accesses_len()).sum() + } + + fn unproxy(&mut self) -> ScriptResult> { + let mut out = Vec::with_capacity(self.len()); + for item in self { + let unproxied = item.unproxy()?; + out.push(unproxied); + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let mut out = Vec::with_capacity(self.len()); + let mut offset = 0; + for item in self.iter_mut() { + let width = item.accesses_len(); + let unproxied = item.unproxy_with_world( + guard, + &accesses[offset..offset + width], + type_registry, + allocator, + )?; + out.push(unproxied); + offset += width; + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + } + }; +} + +macro_rules! impl_proxy_via_vec { + ($type:ty, $item_type:ty, $in_type:ty, ($($generics:tt)*)) => { + impl<$($generics)*> Proxy for $type { + type Input<'i> = $in_type; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + let mut out = Vec::with_capacity(input.len()); + for item in input { + out.push(<$item_type as Proxy>::proxy(item)?); + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + + fn proxy_with_allocator( + input: Self::Input<'_>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + let mut out = Vec::with_capacity(input.len()); + for item in input { + out.push(<$item_type as Proxy>::proxy_with_allocator(item, _allocator)?); + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + } + }; +} + +impl_unproxy_via_vec!(Vec, Vec>, (T: Unproxy)); +impl_proxy_via_vec!(Vec, T, Vec>, (T: Proxy)); +impl_unproxy_via_vec!([T; C], [T::Output<'o>; C], (T: Unproxy, const C: usize)); +impl_proxy_via_vec!([T; C],T,[T::Input<'i>; C], (T: Proxy, const C: usize)); +impl_unproxy_via_vec!(SmallVec<[T; C]>, SmallVec<[T::Output<'o>; C]>, (T: Unproxy, const C: usize)); +impl_proxy_via_vec!(SmallVec<[T; C]>, T, SmallVec<[T::Input<'i>; C]>, (T: Proxy, const C: usize)); + +// impl_proxy_unproxy_via_vec!(T, SmallVec, SmallVec<[T; C]>); +// impl<'c, T: 'c> Unproxy for &'c T { +// type Output<'o> = &'c T where Self: 'o; + +// fn unproxy(&mut self) -> ScriptResult> { +// Ok(self) +// } +// } + +// impl<'s, T> Proxy for &'s T { +// type Input<'b> = &'s T; + +// fn proxy(input: Self::Input<'_>) -> ScriptResult { +// Ok(input) +// } + +// fn proxy_with_allocator( +// input: Self::Input<'_>, +// _allocator: &mut ReflectAllocator, +// ) -> ScriptResult { +// Ok(input) +// } +// } + +// impl Unproxy for &mut T { +// type Output<'o> = &'o mut T where Self: 'o; + +// fn unproxy(&mut self) -> ScriptResult> { +// Ok(self) +// } +// } + +// impl<'s, T> Proxy for &'s mut T { +// type Input<'a> = &'s mut T; + +// fn proxy(input: Self::Input<'_>) -> ScriptResult { +// Ok(input) +// } + +// fn proxy_with_allocator( +// input: Self::Input<'_>, +// _allocator: &mut ReflectAllocator, +// ) -> ScriptResult { +// Ok(input) +// } +// } + +impl Unproxy for Option { + type Output<'o> = Option> where Self: 'o; + + fn unproxy(&mut self) -> ScriptResult> { + if let Some(s) = self { + let inner = s.unproxy()?; + Ok(Some(inner)) + } else { + Ok(None) + } + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + if let Some(s) = self { + let inner = s.unproxy_with_world(guard, accesses, type_registry, allocator)?; + Ok(Some(inner)) + } else { + Ok(None) + } + } + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + self.as_ref() + .map(|s| s.collect_accesses(guard, accesses)) + .unwrap_or_else(|| Ok(())) + } + + fn accesses_len(&self) -> usize { + self.as_ref().map_or(0, |s| s.accesses_len()) + } +} + +impl Proxy for Option { + type Input<'a> = Option>; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + input.map(T::proxy).transpose() + } + + fn proxy_with_allocator( + input: Self::Input<'_>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + input + .map(|i| T::proxy_with_allocator(i, _allocator)) + .transpose() + } +} + +impl Proxy for Result { + type Input<'a> = Result, E>; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + match input { + Ok(i) => Ok(Ok(T::proxy(i)?)), + Err(e) => Ok(Err(e)), + } + } + + fn proxy_with_allocator( + input: Self::Input<'_>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + match input { + Ok(i) => Ok(Ok(T::proxy_with_allocator(i, _allocator)?)), + Err(e) => Ok(Err(e)), + } + } +} + +impl Unproxy for Result { + type Output<'o> = Result, E::Output<'o>> where Self: 'o; + + fn unproxy(&mut self) -> ScriptResult> { + match self { + Ok(s) => Ok(Ok(s.unproxy()?)), + Err(e) => Ok(Err(e.unproxy()?)), + } + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + match self { + Ok(s) => Ok(Ok(s.unproxy_with_world( + guard, + accesses, + type_registry, + allocator, + )?)), + Err(e) => Ok(Err(e.unproxy()?)), + } + } + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + match self { + Ok(s) => s.collect_accesses(guard, accesses), + Err(_) => Ok(()), + } + } + + fn accesses_len(&self) -> usize { + match self { + Ok(s) => s.accesses_len(), + Err(_) => 0, + } + } +} + +macro_rules! impl_unproxy_by_move { + ($($ty:ty),*) => { + $( + impl Unproxy for $ty { + type Output<'o> = $ty; + + fn unproxy( + &mut self + ) -> ScriptResult> { + Ok(*self) + } + } + + impl Unproxy for &$ty { + type Output<'o> = &'o $ty where Self : 'o; + + fn unproxy( + &mut self + ) -> ScriptResult> { + Ok(self) + } + } + + impl Unproxy for &mut $ty { + type Output<'o> = &'o mut $ty where Self : 'o; + + fn unproxy( + &mut self + ) -> ScriptResult> { + Ok(self) + } + } + )* + }; +} + +macro_rules! impl_proxy_by_move { + ($($ty:ident),*) => { + $( + impl Proxy for $ty { + type Input<'a> = Self; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + Ok(input) + } + } + + impl <'l>Proxy for &'l $ty { + type Input<'a> = Self; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + Ok(input) + } + } + + impl <'l>Proxy for &'l mut $ty { + type Input<'a> = Self; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + Ok(input) + } + } + )* + } +} + +impl_proxy_by_move!( + usize, + u8, + u16, + u32, + u64, + u128, + isize, + i8, + i16, + i32, + i64, + i128, + f32, + f64, + bool, + NonZeroUsize, + NonZeroU8, + NonZeroU16, + NonZeroU32, + NonZeroU64, + NonZeroU128 +); + +impl_unproxy_by_move!( + usize, + u8, + u16, + u32, + u64, + u128, + isize, + i8, + i16, + i32, + i64, + i128, + f32, + f64, + bool, + NonZeroUsize, + NonZeroU8, + NonZeroU16, + NonZeroU32, + NonZeroU64, + NonZeroU128 +); + +macro_rules! impl_unproxy_by_clone { + ($($ty:ty),*) => { + $(impl Unproxy for $ty { + type Output<'o> = $ty; + + fn unproxy(&mut self) -> ScriptResult> { + Ok(self.clone()) + } + })* + }; +} + +impl_unproxy_by_clone!(String); +impl_proxy_by_move!(String); + +macro_rules! impl_tuple_unproxy_proxy { + ($(($ty:ident, $idx:tt)),*) => { + impl <$($ty : Proxy,)*> Proxy for ($($ty,)*) + { + type Input<'a> = ($($ty::Input<'a>,)*); + + #[allow(clippy::unused_unit)] + fn proxy(_input: Self::Input<'_>) -> ScriptResult { + Ok(($($ty::proxy(_input.$idx)?,)*)) + } + + fn proxy_with_allocator(_input: Self::Input<'_>, _allocator: &mut ReflectAllocator) -> ScriptResult { + Ok(($($ty::proxy_with_allocator(_input.$idx, _allocator)?,)*)) + } + } + + impl<$($ty: Unproxy),*> Unproxy for ($($ty,)*) { + type Output<'o> = ($($ty::Output<'o>,)*) where Self: 'o; + + fn collect_accesses<'w>( + &self, + _guard: &WorldAccessGuard<'w>, + _accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + $(self.$idx.collect_accesses(_guard, _accesses)?;)* + Ok(()) + } + + fn accesses_len(&self) -> usize { + let mut _len = 0; + $(_len += self.$idx.accesses_len();)* + _len + } + + fn unproxy(&mut self) -> ScriptResult> { + Ok(($( + self.$idx.unproxy()? + ,)*)) + } + + #[allow(unused_assignments)] + unsafe fn unproxy_with_world<'w,'o>( + &'o mut self, + _guard: &WorldAccessGuard<'w>, + _accesses: &'o [WorldAccessUnit<'w>], + _type_registry: &TypeRegistry, + _allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let mut _offset = 0; + + Ok(($( + { + let width = self.$idx.accesses_len(); + let elem = self.$idx.unproxy_with_world(_guard, &_accesses[_offset.._offset+width], _type_registry, _allocator)?; + + _offset += width; + elem + } + ,)*)) + + } + } + }; +} + +impl_tuple_unproxy_proxy!(); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13), (O, 14)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13), (O, 14), (P, 15)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13), (O, 14), (P, 15), (Q, 16)); + +#[cfg(test)] +mod test { + + use bevy::ecs::{component::Component, world::World}; + + use crate::bindings::{ReflectBase, ReflectBaseType}; + + use super::*; + + #[derive(Reflect, Component, PartialEq, Eq, Debug, Clone)] + struct Test(pub &'static str); + + #[derive(Debug, Clone, PartialEq, Eq)] + struct ValTestProxy(Test); + + impl From for ValTestProxy { + fn from(value: Test) -> Self { + Self(value) + } + } + + impl<'a> From<&'a ValTestProxy> for Test { + fn from(value: &'a ValTestProxy) -> Self { + value.0.clone() + } + } + + #[derive(Debug, Clone, PartialEq, Eq)] + struct TestProxy(ReflectReference); + + impl From for TestProxy { + fn from(value: ReflectReference) -> Self { + TestProxy(value) + } + } + + impl AsRef for TestProxy { + fn as_ref(&self) -> &ReflectReference { + &self.0 + } + } + + macro_rules! assert_proxy_invertible { + ($original:expr, $($proxy_ty:tt)*) => { + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + let mut allocator = ReflectAllocator::default(); + + // test with world version + let mut proxy = <$($proxy_ty)* as Proxy>::proxy_with_allocator($original, &mut allocator).unwrap(); + proxy.collect_accesses(&world, &mut accesses).unwrap(); + + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &mut accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!( + unproxied, $original, + "Proxy and unproxy does not yield original type, expected {:?}, got {:?}", + $original, unproxied + ); + + let mut proxy = <$($proxy_ty)* as Proxy>::proxy($original).unwrap(); + + let unproxied_without_world = proxy.unproxy().unwrap(); + assert_eq!( + unproxied_without_world, $original, + "Proxy and unproxy does not yield original type, expected {:?}, got {:?}", + $original, unproxied_without_world + ); + + }; + } + + #[test] + pub fn test_non_reflect_val_proxy() { + assert_proxy_invertible!(Test("test"), ValProxy::); + } + + #[test] + pub fn test_complex_types_proxy_is_inverse_of_unproxy() { + assert_proxy_invertible!([32; 4], [usize; 4]); + assert_proxy_invertible!( + core::array::from_fn::<_, 4, _>(|_| vec![Test("test")]), + [Vec::>; 4] + ); + assert_proxy_invertible!(Vec::::default(), Vec::); + assert_proxy_invertible!(Some(Test("test")), Option::>); + assert_proxy_invertible!(None::, Option::>); + assert_proxy_invertible!( + Some(Some(Test("test"))), + Option::>> + ); + assert_proxy_invertible!( + vec![Some(Test("test")), None, Some(Test("test"))], + Vec::>> + ); + assert_proxy_invertible!(vec![&1, &2, &3], Vec::<&usize>); + // assert_proxy_invertible!(vec![&(1, 2)], Vec::<&(usize, usize)>); + assert_proxy_invertible!(vec![vec![1, 2], vec![1, 2, 3]], Vec::>); + assert_proxy_invertible!( + vec![vec![(1, 2), (3, 4)], vec![(1, 2), (3, 4)]], + Vec::> + ); + assert_proxy_invertible!(Some(1), Option::); + assert_proxy_invertible!(Some(Some(1)), Option::>); + assert_proxy_invertible!(None::, Option::); + assert_proxy_invertible!(None::>, Option::>); + assert_proxy_invertible!(vec![Some(1), None, Some(2)], Vec::>); + assert_proxy_invertible!( + vec![Some(vec![1, 2, 3]), None, Some(vec![1, 4])], + Vec::>> + ); + } + + #[test] + pub fn test_val_proxy() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = ReflectValProxy::::new(TestProxy(ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + })); + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied.0, "test"); + } + + #[test] + pub fn test_proxy_ref() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = ReflectRefProxy::::new(TestProxy(ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + })); + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied.0, "test"); + } + + #[test] + pub fn test_proxy_ref_mut() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = ReflectRefMutProxy::::new(TestProxy(ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + })); + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied.0, "test"); + } + + #[test] + pub fn test_vec_proxy_ref_mut() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = vec![Some(ReflectRefMutProxy::::new(TestProxy( + ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + }, + )))]; + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied[0].as_ref().unwrap().0, "test"); + } + + #[test] + pub fn test_invalid_access() { + let mut allocator = ReflectAllocator::default(); + + let (allocation_id, _) = allocator.allocate(Test("test")); + + let reflect_ref = ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(allocation_id), + }, + reflect_path: vec![], + }; + + // mutable access to the same allocation + let proxy = vec![ + ReflectRefMutProxy::::new(TestProxy(reflect_ref.clone())), + ReflectRefMutProxy::::new(TestProxy(reflect_ref)), + ]; + + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + + let result = proxy.collect_accesses(&world, &mut accesses); + assert!(matches!(result, Err(..))); + } +} diff --git a/crates/bevy_mod_scripting_core/src/bindings/query.rs b/crates/bevy_mod_scripting_core/src/bindings/query.rs new file mode 100644 index 00000000..5a7db18a --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/query.rs @@ -0,0 +1,114 @@ +use std::{any::TypeId, ops::Deref, sync::Arc}; + +use bevy::{ecs::entity::Entity, reflect::TypeRegistration}; + +use super::{ReflectReference, WorldCallbackAccess, STALE_WORLD_MSG}; +use crate::prelude::{ScriptError, ScriptResult}; + +/// A wrapper around a `TypeRegistration` that provides additional information about the type. +/// +/// This is used as a hook to a rust type from a scripting language. We should be able to easily convert between a type name and a [`ScriptTypeRegistration`]. +#[derive(Clone)] +pub struct ScriptTypeRegistration(pub(crate) Arc); + +impl ScriptTypeRegistration { + pub fn new(arc: Arc) -> Self { + Self(arc) + } + + #[inline(always)] + pub fn short_name(&self) -> &str { + self.0.type_info().type_path_table().short_path() + } + + #[inline(always)] + pub fn type_name(&self) -> &'static str { + self.0.type_info().type_path_table().path() + } + + #[inline(always)] + pub fn type_id(&self) -> TypeId { + self.0.type_info().type_id() + } +} + +impl std::fmt::Debug for ScriptTypeRegistration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("ScriptTypeRegistration") + .field(&self.0.type_info().type_path()) + .finish() + } +} + +impl std::fmt::Display for ScriptTypeRegistration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.0.type_info().type_path()) + } +} + +impl Deref for ScriptTypeRegistration { + type Target = Arc; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[derive(Clone)] +pub struct ScriptQueryBuilder { + world: WorldCallbackAccess, + components: Vec, + with: Vec, + without: Vec, +} + +impl ScriptQueryBuilder { + pub fn new(world: WorldCallbackAccess) -> Self { + Self { + world, + components: vec![], + with: vec![], + without: vec![], + } + } + + pub fn components(&mut self, components: Vec) -> &mut Self { + self.components.extend(components); + self + } + + pub fn with(&mut self, with: Vec) -> &mut Self { + self.with.extend(with); + self + } + + pub fn without(&mut self, without: Vec) -> &mut Self { + self.without.extend(without); + self + } + + pub fn build(&mut self) -> ScriptResult> { + self.world.query( + std::mem::take(&mut self.components), + std::mem::take(&mut self.with), + std::mem::take(&mut self.without), + ) + } +} + +#[derive(Clone)] +pub struct ScriptQueryResult(pub Entity, pub Vec); + +impl WorldCallbackAccess { + pub fn query( + &mut self, + components: Vec, + with: Vec, + without: Vec, + ) -> ScriptResult> { + // for c in components { + + // } + todo!() + } +} diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs new file mode 100644 index 00000000..5a7e615b --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -0,0 +1,501 @@ +//! # Motivation +//! +//! Traits and structs needed to support the creation of bindings for scripting languages. +//! reflection gives us access to `dyn Reflect` objects via their type name, +//! Scripting languages only really support `Clone` objects so if we want to support references, +//! we need wrapper types which have owned and ref variants. +use lockable::LockableHashMap; + +use std::{ + any::TypeId, + cell::UnsafeCell, + error::Error, + fmt::Debug, + marker::PhantomData, + ops::Index, + sync::{Arc, Weak}, + time::Duration, +}; + +use bevy::{ + ecs::{ + change_detection::MutUntyped, + component::{Component, ComponentId}, + entity::Entity, + reflect::AppTypeRegistry, + system::Resource, + world::{unsafe_world_cell::UnsafeWorldCell, Mut, World}, + }, + ptr::Ptr, + reflect::{ + Access, ParsedPath, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError, TypeInfo, + TypeRegistry, + }, + utils::smallvec::SmallVec, +}; + +use crate::{ + bindings::{ReflectAllocation, ReflectAllocationId}, + prelude::{ReflectAllocator, ScriptError, ScriptResult}, +}; + +use super::{ + proxy::{Proxy, Unproxy}, + ReflectAccessId, ReflectAccessKind, WorldAccessGuard, WorldAccessWrite, DEFAULT_INTERVAL, + DEFAULT_TIMEOUT, +}; + +/// An accessor to a `dyn Reflect` struct, stores a base ID of the type and a reflection path +/// safe to build but to reflect on the value inside you need to ensure aliasing rules are upheld +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ReflectReference { + pub base: ReflectBaseType, + // TODO: experiment with Fixed capacity vec, boxed array etc, compromise between heap allocation and runtime cost + // needs benchmarks first though + /// The path from the top level type to the actual value we want to access + pub reflect_path: Vec, +} + +// just a dummy standin for unregistered types +struct UnregisteredType; + +impl ReflectReference { + + pub fn new_allocated( + value: T, + allocator: &mut ReflectAllocator, + ) -> ReflectReference { + let (id, _) = allocator.allocate(value); + ReflectReference { + base: ReflectBaseType { + type_id: TypeId::of::(), + base_id: ReflectBase::Owned(id), + }, + reflect_path: Vec::default(), + } + } + + /// Indexes into the reflect path inside this reference. + /// You can use [`Self::reflect`] and [`Self::reflect_mut`] to get the actual value. + pub fn index_path>(&mut self, index: T) { + self.reflect_path.push(index.into()); + } + + /// A form of [`Self::reflect`] which does the access checks for you. + /// Panics if it waits for access too long to prevent deadlocks. + pub fn with_reflect O>( + &self, + world: &WorldAccessGuard, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + f: F, + ) -> O { + let access = world + .get_access_timeout( + self.base.base_id.get_reflect_access_id(), + DEFAULT_TIMEOUT, + DEFAULT_INTERVAL, + ) + .unwrap_or_else(|| panic!("Timeout when waiting for access for: `{:?}`", self)); + + let reflect = self + .reflect( + world.as_unsafe_world_cell(), + &access, + type_registry, + allocator, + ) + .unwrap(); + let o = f(reflect); + world.release_access(access); + o + } + + pub fn with_reflect_mut O>( + &self, + world: &WorldAccessGuard, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + f: F, + ) -> O { + let mut access = world + .get_access_timeout( + self.base.base_id.get_reflect_access_id(), + DEFAULT_TIMEOUT, + DEFAULT_INTERVAL, + ) + .unwrap_or_else(|| panic!("Timeout when waiting for access for: `{:?}`", self)); + + let reflect = self + .reflect_mut( + world.as_unsafe_world_cell(), + &mut access, + type_registry, + allocator, + ) + .unwrap(); + let o = f(reflect); + world.release_access(access); + o + } + + /// Returns `Ok(())` if the given access is sufficient to read the value or an appropriate error otherwise + pub fn expect_read_access<'w>( + &self, + access: &WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + world: UnsafeWorldCell<'w>, + ) -> ScriptResult<()> { + if !access.can_read(self.base.base_id.get_reflect_access_id()) { + Err(ScriptError::new_reflection_error(format!( + "Invalid access when trying to read: `{}`, instead got access to `{}`", + self.base.display_with_type_name(type_registry), + access.to_enriched_str(type_registry, allocator, world) + ))) + } else { + Ok(()) + } + } + + /// Returns `Ok(())` if the given access is sufficient to write to the value or an appropriate error otherwise + /// Note that this is not sufficient for write access, you also need to ensure the [`WorldAccessWrite`] won't be used to access the same value mutably elsewhere, + /// if you have a `&mut WorldAccessWrite` you can guarantee this statically. This function just checks that the access itself is for the right base with write access + pub fn expect_write_access<'w>( + &self, + access: &WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + world: UnsafeWorldCell<'w>, + ) -> ScriptResult<()> { + if !access.can_read(self.base.base_id.get_reflect_access_id()) { + Err(ScriptError::new_reflection_error(format!( + "Invalid access when trying to write: `{}`, instead got access to `{}`", + self.base.display_with_type_name(type_registry), + access.to_enriched_str(type_registry, allocator, world) + ))) + } else { + Ok(()) + } + } + + /// Retrieves a reference to the underlying `dyn Reflect` type valid for the 'w lifetime of the world cell. + /// If the underlying componentId is not the same as the one we have access to, an error is returned. + pub fn reflect<'w, 'c>( + &self, + world: UnsafeWorldCell<'w>, + access: &'c WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'c ReflectAllocator>, + ) -> ScriptResult<&'c dyn Reflect> { + self.expect_read_access(access, type_registry, allocator, world)?; + // Safety: since we have read access to the underlying componentId we can safely access the component + // and we can return a reference tied to its lifetime, which will prevent invalid aliasing + return unsafe { self.reflect_unsafe(world, type_registry, allocator) }; + } + + /// Retrieves a reference to the underlying `dyn Reflect` type valid for the 'w lifetime of the world cell. + /// If the underlying componentId is not the same as the one we have access to, an error is returned. + /// + /// If we are accessing a component or resource, it's marked as changed + pub fn reflect_mut<'w, 'c>( + &self, + world: UnsafeWorldCell<'w>, + access: &'c mut WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'c ReflectAllocator>, + ) -> ScriptResult<&'c mut dyn Reflect> { + self.expect_write_access(access, type_registry, allocator, world)?; + // Safety: since we have write access to the underlying reflect access id we can safely access the component + // and we can return a reference tied to its lifetime, which will prevent invalid aliasing + return unsafe { self.reflect_mut_unsafe(world, type_registry, allocator) }; + } + + /// Retrieves a reference to the underlying `dyn Reflect` type valid for the 'w lifetime of the world cell + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no aliasing mut references to the same value exist at all at the same time + pub unsafe fn reflect_unsafe<'w>( + &self, + world: UnsafeWorldCell<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'w ReflectAllocator>, + ) -> ScriptResult<&'w dyn Reflect> { + if let ReflectBase::Owned(id) = &self.base.base_id { + let allocator = + allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?; + let arc = allocator + .get(*id) + .ok_or_else(|| ScriptError::new_reflection_error("Missing allocation"))?; + + // safety: caller promises it's fine :) + return self.walk_path(unsafe { &*arc.get_ptr() }); + }; + // all Reflect types should have this derived + let from_ptr_data: &ReflectFromPtr = type_registry + .get_type_data(self.base.type_id) + .expect("FromPtr is not registered for this type, cannot retrieve reflect reference"); + + let ptr = self + .base + .base_id + .clone() + .into_ptr(world) + .ok_or_else(|| + ScriptError::new_reflection_error( + format!("Base reference is invalid, is the component/resource initialized? does the entity exist?. When accessing: `{}`", self.base.display_with_type_name(type_registry))))?; + + // (Ptr) Safety: we use the same type_id to both + // 1) retrieve the ptr + // 2) retrieve the ReflectFromPtr type data + // (UnsafeWorldCell) Safety: + // we already have access to &world so no &mut world exists + debug_assert_eq!( + from_ptr_data.type_id(), + self.base.type_id, + "Invariant violated" + ); + let base = unsafe { from_ptr_data.as_reflect(ptr) }; + self.walk_path(base) + } + + /// Retrieves mutable reference to the underlying `dyn Reflect` type valid for the 'w lifetime of the world cell + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no other references to the same value exist at all at the same time (even if you have the correct access) + pub unsafe fn reflect_mut_unsafe<'w>( + &self, + world: UnsafeWorldCell<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'w ReflectAllocator>, + ) -> ScriptResult<&'w mut dyn Reflect> { + if let ReflectBase::Owned(id) = &self.base.base_id { + let allocator = allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?; + + let arc = allocator + .get_mut(*id) + .ok_or_else(|| ScriptError::new_reflection_error("Missing allocation"))?; + + // Safety: caller promises this is fine :) + return self.walk_path_mut(unsafe { &mut *arc.get_ptr() }); + }; + + // all Reflect types should have this derived + let from_ptr_data: &ReflectFromPtr = type_registry + .get_type_data(self.base.type_id) + .expect("FromPtr is not registered for this type, cannot retrieve reflect reference"); + + let ptr = self + .base + .base_id + .clone() + .into_ptr_mut(world) + .ok_or_else(|| + ScriptError::new_reflection_error( + format!("Base reference is invalid, is the component/resource initialized? does the entity exist?. When accessing: `{}`", self.base.display_with_type_name(type_registry))))? + .into_inner(); + + // (Ptr) Safety: we use the same type_id to both + // 1) retrieve the ptr + // 2) retrieve the ReflectFromPtr type data + // (UnsafeWorldCell) Safety: + // we already have access to &world so no &mut world exists + debug_assert_eq!( + from_ptr_data.type_id(), + self.base.type_id, + "Invariant violated" + ); + let base = unsafe { from_ptr_data.as_reflect_mut(ptr) }; + self.walk_path_mut(base) + } + + fn walk_path<'a>(&self, root: &'a dyn Reflect) -> ScriptResult<&'a dyn Reflect> { + let mut current = root; + for elem in self.reflect_path.iter() { + current = elem + .reflect_element(current) + .map_err(|e| ScriptError::new_reflection_error(e.to_string()))?; + } + Ok(current) + } + + fn walk_path_mut<'a>(&self, root: &'a mut dyn Reflect) -> ScriptResult<&'a mut dyn Reflect> { + let mut current = root; + for elem in self.reflect_path.iter() { + current = elem + .reflect_element_mut(current) + .map_err(|e| ScriptError::new_reflection_error(e.to_string()))?; + } + Ok(current) + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ReflectBaseType { + pub type_id: TypeId, + pub base_id: ReflectBase, +} + +impl ReflectBaseType { + pub fn type_name(type_id: TypeId, type_registry: &TypeRegistry) -> &'static str { + type_registry + .get_type_info(type_id) + .map(TypeInfo::type_path) + .unwrap_or("") + } + + pub fn display_with_type_name(&self, type_registry: &TypeRegistry) -> String { + format!( + "ReflectBase({}, {:?})", + Self::type_name(self.type_id, type_registry), + self.base_id + ) + } +} + +/// The Id of the kind of reflection base being pointed to +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum ReflectBase { + Component(Entity, ComponentId), + Resource(ComponentId), + Owned(ReflectAllocationId), +} + +impl ReflectBase { + /// Retrieves the pointer to the underlying `dyn Reflect` object valid for the 'w lifteime of the world cell + /// + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no aliasing mutable references to the same value exist at the same time + pub unsafe fn into_ptr(self, world: UnsafeWorldCell<'_>) -> Option> { + match self { + ReflectBase::Component(entity, component_id) => { + // Safety: the caller ensures invariants hold + world.get_entity(entity)?.get_by_id(component_id) + } + ReflectBase::Resource(component_id) => { + // Safety: the caller ensures invariants hold + world.get_resource_by_id(component_id) + } + _ => None, + } + } + + /// Retrieves the pointer to the underlying `dyn Reflect` object valid for the 'w lifteime of the world cell + /// + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no aliasing references to the same value exist at all at the same time + pub unsafe fn into_ptr_mut(self, world: UnsafeWorldCell<'_>) -> Option> { + match self { + ReflectBase::Component(entity, component_id) => { + // Safety: the caller ensures invariants hold + world.get_entity(entity)?.get_mut_by_id(component_id) + } + ReflectBase::Resource(component_id) => { + // Safety: the caller ensures invariants hold + world.get_resource_mut_by_id(component_id) + } + _ => None, + } + } + + pub fn get_reflect_access_id(&self) -> ReflectAccessId { + match self { + ReflectBase::Component(_, cid) | ReflectBase::Resource(cid) => (*cid).into(), + ReflectBase::Owned(id) => (*id).into(), + } + } +} + +/// An element in the reflection path, the base reference included +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum ReflectionPathElem { + /// A standard reflection path, i.e. `.field_name[vec_index]`, pre-parsed since we construct once potentially use many times + Reflection(ParsedPath), + /// a deferred reflection + DeferredReflection(DeferredReflection), +} + +impl ReflectionPathElem { + pub fn new_reflection>(path: I) -> Self { + Self::Reflection(path.into()) + } + + pub fn new_deferred>(defref: I) -> Self { + Self::DeferredReflection(defref.into()) + } +} + +impl From<(A, B)> for DeferredReflection +where + A: Fn(&dyn Reflect) -> Result<&dyn Reflect, ReflectPathError<'static>> + Send + Sync, + B: Fn(&mut dyn Reflect) -> Result<&mut dyn Reflect, ReflectPathError<'static>> + Send + Sync, +{ + fn from((get, get_mut): (A, B)) -> Self { + Self { + get: Arc::new(get), + get_mut: Arc::new(get_mut), + } + } +} + +impl> From for ReflectionPathElem { + fn from(value: T) -> Self { + Self::DeferredReflection(value.into()) + } +} + +impl From for ReflectionPathElem { + fn from(value: ParsedPath) -> Self { + Self::Reflection(value) + } +} + +impl<'a> ReflectPath<'a> for &'a ReflectionPathElem { + fn reflect_element<'r>( + self, + root: &'r dyn Reflect, + ) -> Result<&'r dyn Reflect, ReflectPathError<'a>> { + match self { + ReflectionPathElem::Reflection(path) => path.reflect_element(root), + ReflectionPathElem::DeferredReflection(f) => (f.get)(root), + } + } + + fn reflect_element_mut<'r>( + self, + root: &'r mut dyn Reflect, + ) -> Result<&'r mut dyn Reflect, ReflectPathError<'a>> { + match self { + ReflectionPathElem::Reflection(path) => path.reflect_element_mut(root), + ReflectionPathElem::DeferredReflection(defref) => (defref.get_mut)(root), + } + } +} + +/// A ReflectPath which can perform arbitrary operations on the root object to produce a sub-reference +#[derive(Clone)] +pub struct DeferredReflection { + pub get: + Arc Result<&dyn Reflect, ReflectPathError<'static>> + Send + Sync>, + pub get_mut: Arc< + dyn Fn(&mut dyn Reflect) -> Result<&mut dyn Reflect, ReflectPathError<'static>> + + Send + + Sync, + >, +} + +impl Debug for DeferredReflection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("DeferredReflection") + } +} + +impl PartialEq for DeferredReflection { + fn eq(&self, other: &Self) -> bool { + Arc::ptr_eq(&self.get, &other.get) && Arc::ptr_eq(&self.get_mut, &other.get_mut) + } +} + +impl Eq for DeferredReflection {} diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs new file mode 100644 index 00000000..ab81d908 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -0,0 +1,1878 @@ +//! # Motivation +//! +//! Traits and structs needed to support the creation of bindings for scripting languages. +//! reflection gives us access to `dyn Reflect` objects via their type name, +//! Scripting languages only really support `Clone` objects so if we want to support references, +//! we need wrapper types which have owned and ref variants. +use lockable::LockableHashMap; + +use std::{ + any::TypeId, + cell::UnsafeCell, + error::Error, + fmt::Debug, + marker::PhantomData, + ops::Index, + sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, Weak, + }, + time::Duration, +}; + +use bevy::{ + ecs::{ + change_detection::MutUntyped, + component::{Component, ComponentId}, + entity::Entity, + reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld, ReflectResource}, + system::{CommandQueue, Commands, Resource}, + world::{unsafe_world_cell::UnsafeWorldCell, Mut, World}, + }, + hierarchy::{BuildChildren, Children, DespawnRecursiveExt, Parent}, + ptr::Ptr, + reflect::{ + std_traits::ReflectDefault, Access, ParsedPath, Reflect, ReflectFromPtr, ReflectPath, + ReflectPathError, TypeInfo, TypePath, TypeRegistration, TypeRegistry, + }, + utils::smallvec::SmallVec, +}; + +use crate::{ + bindings::{ReflectAllocation, ReflectAllocationId}, + prelude::{ReflectAllocator, ScriptError, ScriptResult}, +}; + +use super::{ + proxy::{Proxy, Unproxy}, + ReflectBase, ReflectBaseType, ReflectReference, ScriptTypeRegistration, +}; + +/// Describes kinds of base value we are accessing via reflection +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub enum ReflectAccessKind { + ComponentOrResource, + Allocation, +} + +/// Describes the id pointing to the base value we are accessing via reflection, for components and resources this is the ComponentId +/// for script owned values this is an allocationId, this is used to ensure we have permission to access the value. +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub struct ReflectAccessId { + kind: ReflectAccessKind, + id: usize, +} + +impl From for ReflectAccessId { + fn from(value: ComponentId) -> Self { + Self { + kind: ReflectAccessKind::ComponentOrResource, + id: value.index(), + } + } +} + +impl From for ReflectAccessId { + fn from(value: ReflectAllocationId) -> Self { + Self { + kind: ReflectAccessKind::Allocation, + id: value.id(), + } + } +} + +/// While [`WorldAccessGuard`] prevents aliasing at runtime and also makes sure world exists at least as long as the guard itself, +/// borrows sadly do not persist the script-host boundary :(. That is to be expected, but instead we can make an abstraction which removes the lifetime parameter, making the outer type 'static, +/// while making sure the lifetime is still satisfied! +#[derive(Clone, Debug)] +pub struct WorldCallbackAccess(Weak>); + +impl WorldCallbackAccess { + /// Wraps a callback which requires access to the world in a 'static way via [`WorldCallbackAccess`]. + pub fn with_callback_access( + world: &mut World, + callback: impl FnOnce(&WorldCallbackAccess) -> T, + ) -> T { + // - the world cannot be dropped before the world drops since we have mutable reference to it in this entire function + // - nothing can alias inappropriately WorldAccessGuard since it's only instance is behind the raw Arc + let world_guard = Arc::new(WorldAccessGuard::new(world)); + let world_guard = unsafe { WorldCallbackAccess::new(Arc::downgrade(&world_guard)) }; + + callback(&world_guard) + } + + /// Creates a new [`WorldCallbackAccess`] with an erased lifetime. + /// + /// # Safety + /// - The caller must ensure the [`WorldAccessGuard`] must not outlive the 'w lifetime + /// - In practice this means that between the moment the original Arc is dropped, the lifetime 'w must be valid + /// - I.e. you *must* drop the original [`Arc`] before the original 'w scope ends + pub unsafe fn new<'w>(world: Weak>) -> Self { + // Safety: the caller ensures `WorldAccessGuard` does not outlive the original lifetime 'w + + let world = unsafe { + std::mem::transmute::>, Weak>>( + world, + ) + }; + + Self(world) + } + + /// Attempts to read the world access guard, if it still exists + pub fn read(&self) -> Option>> { + self.0.upgrade() + } +} + +pub(crate) const STALE_WORLD_MSG: &str = "Tried to access world via stale reference"; +pub(crate) const CONCURRENT_WORLD_ACCESS_MSG: &str = + "Something else is accessing the world right now!"; +pub(crate) const CONCURRENT_ACCESS_MSG: &str = + "Something else is accessing the resource/component/allocation right now!"; + +/// common world methods, see: +/// - [`crate::bindings::query`] for query related functionality +impl WorldCallbackAccess { + pub fn get_type_by_name(&self, type_name: &str) -> Option { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + world.with_resource(|_, registry: Mut| { + let registry = registry.read(); + registry + .get_with_short_type_path(type_name) + .or_else(|| registry.get_with_type_path(type_name)) + .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) + }) + } + + pub fn add_default_component( + &self, + entity: Entity, + registration: ScriptTypeRegistration, + ) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", + registration.type_info().type_path() + )))?; + + // we look for ReflectDefault or ReflectFromWorld data then a ReflectComponent data + let instance = if let Some(default_td) = registration.data::() { + default_td.default() + } else if let Some(from_world_td) = registration.data::() { + if let Some(world) = world.get_whole_world_access() { + from_world_td.from_world(world) + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + } else { + return Err(ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", + registration.type_info().type_path() + ))); + }; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = world.get_whole_world_access() { + let app_registry = world + .remove_resource::() + .unwrap_or_else(|| panic!("Missing type registry")); + + let mut entity = world.get_entity_mut(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + { + let registry = app_registry.read(); + component_data.insert(&mut entity, instance.as_ref(), ®istry); + } + world.insert_resource(app_registry); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn get_component( + &self, + entity: Entity, + component_id: ComponentId, + ) -> ScriptResult> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let entity = world.cell.get_entity(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + + let component_info = world + .cell + .components() + .get_info(component_id) + .ok_or_else(|| { + ScriptError::new_runtime_error(format!( + "Component does not exist: {:?}", + component_id + )) + })?; + + if entity.contains_id(component_id) { + Ok(Some(ReflectReference { + base: ReflectBaseType { + type_id: component_info + .type_id() + .expect("Component does not have type id"), + base_id: ReflectBase::Component(entity.id(), component_id), + }, + reflect_path: Default::default(), + })) + } else { + Ok(None) + } + } + + pub fn has_component(&self, entity: Entity, component_id: ComponentId) -> ScriptResult { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let entity = world.cell.get_entity(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + + Ok(entity.contains_id(component_id)) + } + + pub fn remove_component( + &self, + entity: Entity, + registration: ScriptTypeRegistration, + ) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", + registration.type_info().type_path() + )))?; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = world.get_whole_world_access() { + let mut entity = world.get_entity_mut(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + + component_data.remove(&mut entity); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + Ok(()) + } + + pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_info = world + .cell + .components() + .get_info(resource_id) + .ok_or_else(|| { + ScriptError::new_runtime_error(format!( + "Resource does not exist: {:?}", + resource_id + )) + })?; + + Ok(ReflectReference { + base: ReflectBaseType { + type_id: component_info + .type_id() + .expect("Resource does not have type id"), + base_id: ReflectBase::Resource(resource_id), + }, + reflect_path: Default::default(), + }) + } + + pub fn remove_resource(&self, registration: ScriptTypeRegistration) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", + registration.type_info().type_path() + )))?; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = world.get_whole_world_access() { + component_data.remove(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + Ok(()) + } + + pub fn has_resource(&self, resource_id: ComponentId) -> bool { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + world.cell.components().get_info(resource_id).is_some() + } + + pub fn get_children(&self, entity: Entity) -> ScriptResult> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let access = world + .get_component_access_typed::() + .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); + + Ok(world + .get_component::(&access, entity)? + .map(|c| c.to_vec()) + .unwrap_or_default()) + } + + pub fn get_parent(&self, entity: Entity) -> ScriptResult> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let access = world + .get_component_access_typed::() + .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); + + Ok(world + .get_component::(&access, entity)? + .map(|c| c.get())) + } + + pub fn push_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).push_children(children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn remove_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).remove_children(children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn insert_children( + &self, + parent: Entity, + index: usize, + children: &[Entity], + ) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).insert_children(index, children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn_recursive(&self, entity: Entity) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn_recursive(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn(&self, entity: Entity) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn_descendants(&self, entity: Entity) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn_descendants(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } +} + +/// Unit of world access +pub type WorldAccessUnit<'w> = WorldAccessWrite<'w>; + +pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5); +pub const DEFAULT_INTERVAL: Duration = Duration::from_millis(10); + +/// Provides safe access to the world via [`WorldAccess`] permissions, which enforce aliasing rules at runtime in multi-thread environments +#[derive(Clone)] +pub struct WorldAccessGuard<'w> { + cell: UnsafeWorldCell<'w>, + // TODO: this is fairly hefty, explore other ways to hand out locks on WorldAccess + accesses: Arc>>>, + /// true if anybody has any access to the world + accesses_count: Arc, + // TODO can we track code/stack locations of things holding onto theese locks for debugging? +} + +impl<'w> WorldAccessGuard<'w> { + /// Creates a new [`WorldAccessGuard`] for the given mutable borrow of the world + pub fn new(world: &'w mut World) -> Self { + Self { + cell: world.as_unsafe_world_cell(), + accesses: Default::default(), + accesses_count: Arc::new(AtomicUsize::new(0)), + } + } + + /// Retrieves the underlying unsafe world cell, with no additional guarantees of safety + /// proceed with caution and only use this if you understand what you're doing + pub fn as_unsafe_world_cell(&self) -> UnsafeWorldCell<'w> { + self.cell + } + + /// Retrieves the underlying read only unsafe world cell, with no additional guarantees of safety + /// proceed with caution and only use this if you understand what you're doing + pub fn as_unsafe_world_cell_readonly(&self) -> UnsafeWorldCell<'w> { + self.cell + } + + /// Checks nobody else is currently accessing the world, and if so locks access to it until + /// [`release_whole_world_access`] is called. + pub fn get_whole_world_access(&self) -> Option<&mut World> { + if self.accesses_count.load(Ordering::Relaxed) == 0 { + Some(unsafe { self.cell.world_mut() }) + } else { + None + } + } + + /// Releases whole world access. Allowing others to access it. + pub fn release_whole_world_access(&self, _world: &mut World) { + // we do not need ot use the world reference, it's there as proof that the caller has claimed access before + assert_eq!(self.accesses_count.load(Ordering::Relaxed), 1); + self.accesses_count.fetch_sub(1, Ordering::Relaxed); + } + + /// Tries to get access to the given reflect access id, if it's already given out returns `None`. If you want to wait for access, use [`WorldAccessGuard::get_access_timeout`] instead. + /// Remember to release this access once done with [`WorldAccessGuard::release_access`] or nobody else will be able to access this id!. + /// + /// Although forgetting to release access is safe, it's frankly quite rude and can lead to deadlocks. + pub fn get_access(&self, raid: ReflectAccessId) -> Option> { + let mut guard = self + .accesses + .blocking_lock(raid, lockable::SyncLimit::no_limit()) + .unwrap(); + let guard = guard.value_or_insert_with(|| { + Some(WorldAccessWrite { + raid, + _ph: PhantomData, + }) + }); + + if guard.is_some() { + self.accesses_count.fetch_add(1, Ordering::Relaxed); + guard.take() + } else { + // somebody has access to this already, we cannot access at the moment + None + } + } + + /// Blocking version of [`WorldAccessGuard::get_access`], waits for access to the given reflect access id. Will busy wait at the given intervals, untill the timeout is reached. + /// If interval is zero this is equivalent to busy waiting. + /// + /// # Panic + /// Will panic once access was not available after the timeout was reached + pub fn get_access_timeout( + &self, + raid: ReflectAccessId, + timeout: Duration, + interval: Duration, + ) -> Option> { + let mut access = self.get_access(raid); + let start = std::time::Instant::now(); + + while access.is_none() { + std::thread::sleep(interval); + access = self.get_access(raid); + if start.elapsed() > timeout { + return None; + } + } + access + } + + /// Releases access to the given reflect access id + pub fn release_access(&self, access: WorldAccessUnit<'w>) { + let mut guard = self + .accesses + .blocking_lock(access.raid, lockable::SyncLimit::no_limit()) + .unwrap(); + + let guard = guard + .value_mut() + .expect("Invariant violated, access should exist"); + + // should not be possible, we are the only ones who can instantiate WorldAccessUnit + assert!( + guard.is_none(), + "Invariant violated, an access has been released by someone else already who shouldn't have been able to do so" + ); + + self.accesses_count.fetch_sub(1, Ordering::Relaxed); + *guard = Some(access); + } + + /// Get access to the given component_id, this is the only way to access a component/resource safely (in the context of the world access guard) + /// since you can only access this component_id through a RwLock, there is no way to break aliasing rules. + /// Additionally the 'w lifetime prevents you from storing this access outside the lifetime of the underlying cell + pub fn get_component_access(&self, cid: ComponentId) -> Option> { + let access_id = ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: cid.index(), + }; + self.get_access(access_id) + } + + /// Similar to [`Self::get_component_access`] but typed, additionally panics if the component is not registered + pub fn get_component_access_typed(&self) -> Option> { + self.get_component_access( + self.cell + .components() + .component_id::() + .unwrap_or_else(|| { + panic!("Component not registered: `{}`", std::any::type_name::()) + }), + ) + } + + /// Get access to the given component_id, this is the only way to access a component/resource safely (in the context of the world access guard) + /// since you can only access this component_id through a RwLock, there is no way to break aliasing rules. + /// Additionally the 'w lifetime prevents you from storing this access outside the lifetime of the underlying cell + pub fn get_resource_access(&self, cid: ComponentId) -> Option> { + self.get_component_access(cid) + } + + /// Similar to [`Self::get_resource_access`] but typed, additionally panics if the resource is not registered + pub fn get_resource_access_typed(&self) -> Option> { + self.get_resource_access( + self.cell + .components() + .resource_id::() + .unwrap_or_else(|| { + panic!("Resource not registered: `{}`", std::any::type_name::()) + }), + ) + } + + /// Get access to the given allocation_id, this is the only way to access a script owned value safely (in the context of the world access guard) + pub fn get_allocation_access(&self, id: ReflectAllocationId) -> Option> { + let access_id = ReflectAccessId { + kind: ReflectAccessKind::Allocation, + id: id.id(), + }; + self.get_access(access_id) + } + + /// Provides access to a resource via callback. Panics if the resource does not exist or if waiting for access times out. + pub fn with_resource) -> O>(&self, f: F) -> O { + let cid = self + .cell + .components() + .resource_id::() + .unwrap_or_else(|| panic!("Resource not registered: `{}`", std::any::type_name::())); + + let mut access = self + .get_access_timeout(cid.into(), DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .unwrap_or_else(|| { + panic!( + "Timed out while waiting for access to resource: `{}`", + std::any::type_name::() + ) + }); + + let resource = self + .get_resource_mut::(&mut access) + .expect("invariant") + .expect("invariant"); + let out = f(self, resource); + self.release_access(access); + out + } + + /// Call a function on a type which can be proxied, first by unproxying the input with world access, + /// then calling the function and finally proxying the output with the allocator. + pub fn proxy_call<'i, O: Proxy, T: Unproxy, F: Fn(T::Output<'_>) -> O::Input<'i>>( + &self, + mut proxied_input: T, + f: F, + ) -> ScriptResult { + self.with_resource(|world, type_registry: Mut| { + world.with_resource(|_, mut allocator: Mut| { + let type_registry = type_registry.read(); + let mut world_acceses = SmallVec::default(); + + proxied_input.collect_accesses(self, &mut world_acceses)?; + let input = unsafe { + proxied_input.unproxy_with_world( + self, + &world_acceses, + &type_registry, + &allocator, + )? + }; + let out = f(input); + + O::proxy_with_allocator(out, &mut allocator) + }) + }) + } + + /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) + pub fn get_component( + &self, + access: &WorldAccessWrite, + entity: Entity, + ) -> ScriptResult> { + let component_id = match self.cell.components().component_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_read(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: component_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_entity(entity).and_then(|e| e.get::())) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot read component, received invalid access".to_string(), + )) + } + } + + /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) + pub fn get_component_mut( + &self, + access: &mut WorldAccessWrite, + entity: Entity, + ) -> ScriptResult>> { + let component_id = match self.cell.components().component_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_write(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: component_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_entity(entity).and_then(|e| e.get_mut::())) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot write component, received invalid access".to_string(), + )) + } + } + + /// Get access to the given resource + pub fn get_resource(&self, access: &WorldAccessWrite) -> ScriptResult> { + let resource_id = match self.cell.components().resource_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_read(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: resource_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_resource::()) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot read resource, received invalid access".to_string(), + )) + } + } + + /// Get access to the given resource, this is the only way to access a component/resource safely (in the context of the world access guard) + pub fn get_resource_mut( + &self, + access: &mut WorldAccessWrite, + ) -> ScriptResult>> { + let resource_id = match self.cell.components().resource_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_write(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: resource_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_resource_mut::()) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot write resource, received invalid access".to_string(), + )) + } + } +} + +/// Impl block for higher level world methods +impl<'w> WorldAccessGuard<'w> { + pub fn get_type_by_name(&self, type_name: &str) -> Option { + self.with_resource(|_, registry: Mut| { + let registry = registry.read(); + registry + .get_with_short_type_path(type_name) + .or_else(|| registry.get_with_type_path(type_name)) + .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) + }) + } + + pub fn add_default_component( + &self, + entity: Entity, + registration: ScriptTypeRegistration, + ) -> ScriptResult<()> { + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", + registration.type_info().type_path() + )))?; + + // we look for ReflectDefault or ReflectFromWorld data then a ReflectComponent data + let instance = if let Some(default_td) = registration.data::() { + default_td.default() + } else if let Some(from_world_td) = registration.data::() { + if let Some(world) = self.get_whole_world_access() { + from_world_td.from_world(world) + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + } else { + return Err(ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", + registration.type_info().type_path() + ))); + }; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = self.get_whole_world_access() { + let app_registry = world + .remove_resource::() + .unwrap_or_else(|| panic!("Missing type registry")); + + let mut entity = world.get_entity_mut(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + { + let registry = app_registry.read(); + component_data.insert(&mut entity, instance.as_ref(), ®istry); + } + world.insert_resource(app_registry); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } +} + +/// Having this is permission to access the contained [`ReflectAccessId`], there is no way to access anything safely through a [`WorldAccessGuard`] +/// without having a [`WorldAccess`] instance for that particular [`ReflectAccessId`]. +/// +/// If you do own a [`WorldAccess`] for some [`ReflectAccessId`], you can read and write to it safely. +/// If you only have an immutable borrow of [`WorldAccess`] you can only read it safely. +/// If you have a mutable borrow of [`WorldAccess`] you can read and write to it safely. +#[derive(Debug)] +pub struct WorldAccessWrite<'a> { + pub raid: ReflectAccessId, + pub(self) _ph: PhantomData<&'a usize>, +} + +impl<'w> WorldAccessWrite<'w> { + pub fn can_read(&self, raid: ReflectAccessId) -> bool { + self.raid == raid + } + + #[inline] + pub fn can_write(&self, raid: ReflectAccessId) -> bool { + self.can_read(raid) + } + + /// Prints the type of access this [`WorldAccessWrite`] entails, enriched with type information from the registry + pub fn to_enriched_str( + &self, + registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + cell: UnsafeWorldCell, + ) -> String { + let (base_type, type_id) = match self.raid.kind { + ReflectAccessKind::ComponentOrResource => { + let type_id = cell + .components() + .get_info(ComponentId::new(self.raid.id)) + .and_then(|info| info.type_id()); + + ("Component/Resource", type_id) + } + ReflectAccessKind::Allocation => { + let type_id = allocator + .and_then(|allocator| allocator.get_type_id(ReflectAllocationId(self.raid.id))); + ("Allocation", type_id) + } + }; + + type_id + .and_then(|type_id| registry.get_type_info(type_id)) + .map(|info| format!("{base_type}<{}>", info.type_path())) + .unwrap_or(format!("{:?}", self.raid)) + } +} + +// pub struct + +#[cfg(test)] +mod test { + + use std::{any::Any, cell::UnsafeCell, convert::identity, sync::RwLock}; + + use crate::{ + bindings::{ + DeferredReflection, ReflectBase, ReflectBaseType, ReflectReference, ReflectionPathElem, + }, + bindings::{ReflectAllocation, ReflectAllocator}, + }; + + use super::*; + use bevy::{ + ecs::{component::Component, reflect::ReflectResource, system::Resource, world::World}, + reflect::TypeRegistryArc, + }; + + #[derive(Component, Reflect, PartialEq, Eq, Debug)] + #[reflect(Component)] + pub(crate) struct TestComponent { + pub strings: Vec, + } + + #[derive(Resource, Reflect, Default, PartialEq, Eq, Debug)] + #[reflect(Resource)] + pub(crate) struct TestResource { + pub bytes: Vec, + } + + pub(crate) fn setup_world( + init: F, + ) -> (World, ComponentId, ComponentId) { + let mut world = World::default(); + let allocator = ReflectAllocator::default(); + + let component_id = world.init_component::(); + let resource_id = world.init_resource::(); + + let mut type_registry = TypeRegistry::new(); + type_registry.register::(); + type_registry.register::(); + + init(&mut world, &mut type_registry); + + world.insert_resource(allocator); + + world.insert_resource(AppTypeRegistry(TypeRegistryArc { + internal: Arc::new(RwLock::new(type_registry)), + })); + + (world, component_id, resource_id) + } + + /// Tests that the given ref_ can be accessed and the value is as expected and access is released correctly (not for allocated values) + fn assert_access_yields< + O: Reflect + PartialEq + Debug, + F: FnOnce(&mut World, ComponentId, ComponentId) -> ReflectReference, + G: FnOnce(&WorldAccessGuard, ComponentId, ComponentId), + >( + init: F, + post_check: G, + expected: O, + ) { + let (mut world, component_id, resource_id) = setup_world(|_, _| {}); + let ref_ = init(&mut world, component_id, resource_id); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let world = world.read().unwrap(); + + // test read + world.with_resource(|world, allocator: Mut| { + world.with_resource(|world, type_registry: Mut| { + let type_registry = type_registry.read(); + ref_.with_reflect(world, &type_registry, Some(&allocator), |reflect| { + let orig = reflect.downcast_ref::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + assert_eq!(orig, &expected); + }) + }) + }); + + assert!( + world.get_component_access(component_id).is_some(), + "access to component was not release correctly" + ); + + assert!( + world.get_resource_access(resource_id).is_some(), + "access to component was not release correctly" + ); + + post_check(&world, component_id, resource_id); + }); + } + + /// Tests that setting to the expected value works as well as follow up reads give the expected value + fn assert_set_then_get_yields< + O: Reflect + PartialEq + Debug + Clone, + F: FnOnce(&mut World, ComponentId, ComponentId) -> ReflectReference, + G: FnOnce(&WorldAccessGuard, ComponentId, ComponentId), + >( + init: F, + post_check: G, + expected: O, + ) { + let (mut world, component_id, resource_id) = setup_world(|_, _| {}); + let ref_ = init(&mut world, component_id, resource_id); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let world = world.read().unwrap(); + // test set + world.with_resource(|world, allocator: Mut| { + world.with_resource(|world, type_registry: Mut| { + let type_registry = type_registry.read(); + ref_.with_reflect_mut(world, &type_registry, Some(&allocator), |reflect| { + let orig = reflect.downcast_mut::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + *orig = expected.clone(); + }) + }) + }); + + // test read + world.with_resource(|world, allocator: Mut| { + world.with_resource(|world, type_registry: Mut| { + let type_registry = type_registry.read(); + ref_.with_reflect(world, &type_registry, Some(&allocator), |reflect| { + let orig = reflect.downcast_ref::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + assert_eq!(orig, &expected); + }) + }) + }); + post_check(&world, component_id, resource_id); + }); + } + + #[test] + fn test_component_access() { + let init = |world: &mut World, component_id, _| { + let entity = world + .spawn(TestComponent { + strings: vec![String::from("initial")], + }) + .id(); + + ReflectReference { + base: ReflectBaseType { + base_id: ReflectBase::Component(entity, component_id), + type_id: TypeId::of::(), + }, + reflect_path: vec![ + ReflectionPathElem::Reflection(ParsedPath::parse_static(".strings").unwrap()), + ReflectionPathElem::DeferredReflection(DeferredReflection { + get: Arc::new(|root| { + let strings = root.downcast_ref::>().unwrap(); + Ok(strings.first().unwrap()) + }), + get_mut: Arc::new(|root| { + let strings = root.downcast_mut::>().unwrap(); + Ok(strings.first_mut().unwrap()) + }), + }), + ], + } + }; + + assert_access_yields(init, |_, _, _| {}, String::from("initial")); + assert_set_then_get_yields(init, |_, _, _| {}, String::from("set")); + } + + #[test] + fn test_resource_access() { + let init = |world: &mut World, _, resource_id| { + world.insert_resource(TestResource { bytes: vec![42u8] }); + + ReflectReference { + base: ReflectBaseType { + base_id: ReflectBase::Resource(resource_id), + type_id: TypeId::of::(), + }, + reflect_path: vec![ + ReflectionPathElem::Reflection(ParsedPath::parse_static(".bytes").unwrap()), + ReflectionPathElem::DeferredReflection(DeferredReflection { + get: Arc::new(|root| { + let strings = root.downcast_ref::>().unwrap(); + Ok(strings.first().unwrap()) + }), + get_mut: Arc::new(|root| { + let strings = root.downcast_mut::>().unwrap(); + Ok(strings.first_mut().unwrap()) + }), + }), + ], + } + }; + assert_access_yields(init, |_, _, _| {}, 42u8); + assert_set_then_get_yields(init, |_, _, _| {}, 69u8); + } + + #[test] + fn test_script_alloc_access() { + let init = |world: &mut World, _, _| { + let mut script_allocator = ReflectAllocator::default(); + let mut ref_ = ReflectReference::new_allocated( + TestComponent { + strings: vec![String::from("initial")], + }, + &mut script_allocator, + ); + ref_.index_path(ParsedPath::parse_static(".strings").unwrap()); + ref_.index_path(DeferredReflection { + get: Arc::new(|root| { + let strings = root.downcast_ref::>().unwrap(); + Ok(strings.first().unwrap()) + }), + get_mut: Arc::new(|root| { + let strings = root.downcast_mut::>().unwrap(); + Ok(strings.first_mut().unwrap()) + }), + }); + world.insert_resource(script_allocator); + ref_ + }; + let post_check = |world: &WorldAccessGuard, _, _| { + assert!( + world + .get_allocation_access(ReflectAllocationId(0)) + .is_some(), + "allocation access was not released correctly" + ); + }; + assert_access_yields(init, post_check, String::from("initial")); + assert_set_then_get_yields(init, post_check, String::from("set")); + } + + #[test] + #[allow(clippy::drop_non_drop)] + fn test_invalid_runtime_access() { + let mut world = World::new(); + let world = WorldAccessGuard::new(&mut world); + let access = world.get_component_access(ComponentId::new(0)); + assert!( + world.get_component_access(ComponentId::new(0)).is_none(), + "access was allowed to alias" + ); + drop(access); + } + + #[test] + #[should_panic] + fn test_double_release_panics() { + let mut world = World::new(); + let world = WorldAccessGuard::new(&mut world); + let access = world.get_component_access(ComponentId::new(0)).unwrap(); + world.release_access(access); + // This won't be possible in client code + world.release_access(WorldAccessWrite { + raid: ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: 0, + }, + _ph: PhantomData, + }); + } + + #[test] + fn test_count_updated_correctly() { + let mut world = World::new(); + let guard = WorldAccessGuard::new(&mut world); + let access = guard.get_access(ComponentId::new(0).into()).unwrap(); + assert_eq!(1, guard.accesses_count.load(Ordering::Relaxed)); + guard.release_access(access); + assert_eq!(0, guard.accesses_count.load(Ordering::Relaxed)); + } +} + +#[cfg(test)] +mod test_api { + use bevy::ecs::system::{CommandQueue, Commands}; + use bevy::ecs::world::FromWorld; + use bevy::hierarchy::BuildChildren; + + use crate::bindings::ScriptTypeRegistration; + use crate::prelude::{ScriptErrorInner, ScriptErrorKind}; + + use super::test::{setup_world, TestComponent, TestResource}; + + use super::*; + + fn get_reg(world: &WorldCallbackAccess, name: &str) -> ScriptTypeRegistration { + world.get_type_by_name(name).expect("Type not found") + } + + fn test_comp_reg(world: &WorldCallbackAccess) -> ScriptTypeRegistration { + world + .get_type_by_name("TestComponent") + .expect("Component not found") + } + + fn test_resource_reg(world: &WorldCallbackAccess) -> ScriptTypeRegistration { + world + .get_type_by_name("TestResource") + .expect("Resource not found") + } + + #[test] + fn test_get_type_by_name() { + let (mut world, _, _) = setup_world(|_, _| {}); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = world.get_type_by_name("TestComponent").unwrap(); + let resource_reg = world.get_type_by_name("TestResource").unwrap(); + + assert_eq!( + comp_reg.type_info().type_id(), + std::any::TypeId::of::() + ); + assert_eq!( + resource_reg.type_info().type_id(), + std::any::TypeId::of::() + ); + }); + } + + #[test] + fn test_get_type_by_name_invalid() { + let (mut world, _, _) = setup_world(|_, _| {}); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = world.get_type_by_name("x"); + let resource_reg = world.get_type_by_name("z"); + + assert!(comp_reg.is_none()); + assert!(resource_reg.is_none()); + }); + } + + #[test] + fn test_add_default_component_from_world() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(FromWorld, Component)] + struct CompWithFromWorld(pub String); + impl FromWorld for CompWithFromWorld { + fn from_world(_: &mut World) -> Self { + Self(String::from("FromWorld")) + } + } + + let (mut world, _, _) = setup_world(|w, r| { + w.init_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + world.add_default_component(entity, comp_reg).unwrap() + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + Some(&CompWithFromWorld(String::from("FromWorld"))) + ); + } + + #[test] + fn test_add_default_component_default() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(Default, Component)] + struct CompWithFromWorld(pub String); + + impl Default for CompWithFromWorld { + fn default() -> Self { + Self(String::from("Default")) + } + } + + let (mut world, _, _) = setup_world(|w, r| { + w.init_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + world.add_default_component(entity, comp_reg).unwrap() + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + Some(&CompWithFromWorld(String::from("Default"))) + ); + } + + #[test] + fn test_add_default_component_missing_from_world_and_default() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(Component)] + struct CompWithFromWorld(pub String); + + let (mut world, _, _) = setup_world(|w, r| { + w.init_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + match world.add_default_component(entity, comp_reg.clone()) { + Ok(_) => { + panic!("Expected error") + } + Err(ScriptError(inner)) => { + assert_eq!(inner.kind, ScriptErrorKind::RuntimeError); + assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", comp_reg.type_info().type_path())); + } + } + }); + } + + #[test] + fn test_add_default_component_missing_component_data() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(Default)] + struct CompWithFromWorld(pub String); + + impl Default for CompWithFromWorld { + fn default() -> Self { + Self(String::from("Default")) + } + } + + let (mut world, _, _) = setup_world(|w, r| { + w.init_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + match world.add_default_component(entity, comp_reg.clone()) { + Ok(_) => { + panic!("Expected error") + } + Err(ScriptError(inner)) => { + assert_eq!(inner.kind, ScriptErrorKind::RuntimeError); + assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", comp_reg.type_info().type_path())); + } + } + }); + } + + #[test] + fn test_get_component_existing() { + let (mut world, comp_id, _) = setup_world(|_, _| {}); + let entity = world.spawn(TestComponent { strings: vec![] }).id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(entity, comp_id).unwrap().unwrap(); + assert_eq!( + comp_ref, + ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Component(entity, comp_id), + }, + reflect_path: Default::default(), + } + ); + }); + } + + #[test] + fn test_get_component_missing() { + let (mut world, comp_id, _) = setup_world(|_, _| {}); + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(entity, comp_id).unwrap(); + assert_eq!(comp_ref, None); + }); + } + + #[test] + fn test_get_component_missing_entity() { + let (mut world, comp_id, _) = setup_world(|_, _| {}); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(Entity::from_raw(0), comp_id); + match comp_ref { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), "Entity does not exist: 0v1"); + } + } + }); + } + + #[test] + fn test_get_component_unregistered_component() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + let fake_id = ComponentId::new(999); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(entity, fake_id); + match comp_ref { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!( + e.reason.to_string(), + format!("Component does not exist: {fake_id:?}"), + ); + } + } + }); + } + + #[test] + fn test_remove_component() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world + .spawn(TestComponent { + strings: vec![String::from("strings")], + }) + .id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world + .remove_component(entity, test_comp_reg(world)) + .unwrap(); + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + None + ); + } + + #[test] + fn test_remove_component_empty_idempotent() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world + .remove_component(entity, test_comp_reg(world)) + .unwrap(); + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + None + ); + } + + #[test] + fn test_remove_component_missing_comp_registration() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let result = world.remove_component(entity, test_resource_reg(world)); + match result { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), format!("Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", test_resource_reg(world).type_info().type_path())); + } + } + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + None + ); + } + + #[test] + fn test_remove_component_missing_entity() { + let (mut world, _, _) = setup_world(|_, _| {}); + let fake_entity = Entity::from_raw(0); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let result = world.remove_component(fake_entity, test_comp_reg(world)); + match result { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), "Entity does not exist: 0v1"); + } + } + }); + } + + #[test] + fn test_get_resource_existing() { + let (mut world, _, resource_id) = setup_world(|_, _| {}); + world.insert_resource(TestResource { bytes: vec![1] }); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_resource(resource_id).unwrap(); + assert_eq!( + comp_ref, + ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Resource(resource_id), + }, + reflect_path: Default::default(), + } + ); + }); + } + + #[test] + fn test_get_resource_non_existing() { + let (mut world, _, _) = setup_world(|_, _| {}); + let fake_comp = ComponentId::new(999); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_resource(fake_comp); + match comp_ref { + Ok(_) => panic!("Expected error"), + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!( + e.reason.to_string(), + format!("Resource does not exist: {fake_comp:?}") + ) + } + } + }); + } + + #[test] + fn test_remove_resource() { + let (mut world, _, _) = setup_world(|_, _| {}); + + world.insert_resource(TestResource { bytes: vec![1] }); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_resource(test_resource_reg(world)).unwrap(); + }); + + assert_eq!(world.get_resource::(), None); + } + + #[test] + fn test_remove_resource_missing_idempotent() { + let (mut world, _, _) = setup_world(|_, _| {}); + + world.remove_resource::(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_resource(test_resource_reg(world)).unwrap(); + }); + + assert_eq!(world.get_resource::(), None); + } + + #[test] + fn test_remove_resource_missing_resource_registration() { + let (mut world, _, _) = setup_world(|_, _| {}); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + match world.remove_resource(test_comp_reg(world)) { + Ok(_) => panic!("Expected error"), + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), format!("Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", test_comp_reg(world).type_info().type_path())); + } + } + }); + } + + #[test] + fn test_has_resource_existing() { + let (mut world, _, res_reg) = setup_world(|_, _| {}); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + assert!(world.has_resource(res_reg)); + }); + } + + #[test] + fn test_has_resource_missing() { + let (mut world, _, res_reg) = setup_world(|_, _| {}); + + world.remove_resource::(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + assert!(world.has_resource(res_reg)); + }); + } + + #[test] + fn test_get_children_1_child() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let children = world.get_children(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child); + }); + } + + #[test] + #[should_panic( + expected = "Component not registered: `bevy_hierarchy::components::children::Children`" + )] + fn test_get_children_children_component_unregistered() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.get_children(parent).unwrap(); + }); + } + + #[test] + fn test_get_children_no_children() { + let (mut world, _, _) = setup_world(|_, _| {}); + + world.init_component::(); + let parent = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let children = world.get_children(parent).unwrap(); + assert_eq!(children.len(), 0); + }); + } + + #[test] + fn test_get_parent_1_parent() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let found_parent = world.get_parent(child).unwrap(); + assert_eq!(found_parent, Some(parent)); + }); + } + + #[test] + fn test_get_parent_no_parent() { + let (mut world, _, _) = setup_world(|_, _| {}); + world.init_component::(); + + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let found_parent = world.get_parent(child).unwrap(); + assert_eq!(found_parent, None); + }); + } + + #[test] + #[should_panic( + expected = "Component not registered: `bevy_hierarchy::components::parent::Parent`" + )] + fn test_get_parent_parent_component_unregistered() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.get_parent(child).unwrap(); + }); + } + + #[test] + fn test_push_children_empty_entity() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.push_children(parent, &[child]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child); + } + + #[test] + fn test_push_children_entity_with_1_child() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child]); + cmnds.apply(&mut world); + + let child_2 = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.push_children(parent, &[child_2]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 2); + assert_eq!(children[0], child); + assert_eq!(children[1], child_2); + } + + #[test] + fn test_remove_children_entity_with_1_child() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_children(parent, &[child]).unwrap(); + }); + + let children = world.get::(parent); + assert!(children.is_none()); + } + + #[test] + fn test_remove_children_remove_half_children() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let child_2 = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child, child_2]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_children(parent, &[child]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child_2); + } + + #[test] + fn test_insert_children_empty() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.insert_children(parent, 0, &[child]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child); + } + + #[test] + fn test_insert_children_middle() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let child_2 = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child, child_2]); + cmnds.apply(&mut world); + + let child_to_insert = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world + .insert_children(parent, 1, &[child_to_insert]) + .unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 3); + assert_eq!(children[0], child); + assert_eq!(children[1], child_to_insert); + assert_eq!(children[2], child_2); + } + + #[test] + fn test_despawn_entity() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.despawn(entity).unwrap(); + }); + + assert!(world.get_entity(entity).is_none()); + } + + #[test] + fn test_despawn_recursive() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.despawn_recursive(parent).unwrap(); + }); + + assert!(world.get_entity(parent).is_none()); + assert!(world.get_entity(child).is_none()); + } + + #[test] + fn test_despawn_descendants() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).push_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.despawn_descendants(parent).unwrap(); + }); + + assert!(world.get_entity(parent).is_some()); + assert!(world.get_entity(child).is_none()); + } +} diff --git a/crates/bevy_mod_scripting_core/src/commands.rs b/crates/bevy_mod_scripting_core/src/commands.rs new file mode 100644 index 00000000..33b90ca7 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/commands.rs @@ -0,0 +1,146 @@ +use std::marker::PhantomData; + +use bevy::{ + asset::Handle, + ecs::{system::Command, world::Mut}, + log::debug, +}; + +use crate::{ + asset::ScriptAsset, + context::{Context, ContextLoadingSettings, ScriptContexts}, + prelude::{Runtime, RuntimeContainer}, + script::{Script, ScriptId, Scripts}, +}; + +pub struct DeleteScript { + pub id: ScriptId, + // hack to make this Send, C does not need to be Send since it is not stored in the command + pub _ph: PhantomData, +} + +impl DeleteScript { + pub fn new(id: ScriptId) -> Self { + Self { + id, + _ph: PhantomData, + } + } +} + +impl Command for DeleteScript { + fn apply(self, world: &mut bevy::prelude::World) { + let settings = world + .get_resource::>() + .expect("No ScriptLoadingSettings resource found") + .clone(); + + world.resource_scope(|world, mut scripts: Mut| { + if let Some(script) = scripts.scripts.remove(&self.id) { + debug!("Deleting script with id: {}", self.id); + let mut ctxts = world.get_non_send_resource_mut::>(); + let ctxts = ctxts.as_deref_mut().unwrap(); + let assigner = settings + .assigner + .as_ref() + .expect("Could not find context assigner in settings"); + debug!("Removing script with id: {}", self.id); + (assigner.remove)(script.context_id, &script, ctxts) + } else { + bevy::log::error!( + "Attempted to delete script with id: {} but it does not exist, doing nothing!", + self.id + ); + } + }); + + world.insert_resource(settings); + } +} + +/// Creates new script with the given ID, if a script with the given ID already exists, this is treated as an update +/// +/// If script comes from an asset, expects it to be loaded, otherwise this command will fail to process the script. +pub struct CreateOrUpdateScript { + id: ScriptId, + content: Box<[u8]>, + asset: Option>, + // Hack to make this Send, C does not need to be Send since it is not stored in the command + _ph: std::marker::PhantomData, +} + +impl CreateOrUpdateScript { + pub fn new(id: ScriptId, content: Box<[u8]>, asset: Option>) -> Self { + Self { + id, + content, + asset, + _ph: std::marker::PhantomData, + } + } +} + +impl Command for CreateOrUpdateScript { + fn apply(self, world: &mut bevy::prelude::World) { + let settings = world + .get_resource::>() + .unwrap() + .clone(); + let mut contexts = world + .remove_non_send_resource::>() + .unwrap(); + let mut runtime = world + .remove_non_send_resource::>() + .unwrap(); + // assign context + let assigner = settings.assigner.clone().expect("No context assigner set"); + let builder = settings.loader.clone().expect("No context loader set"); + + world.resource_scope(|world, mut scripts: Mut| { + + // check if script already exists + + let mut script = scripts.scripts.get_mut(&self.id); + let previous_context_id = script.as_ref().map(|s| s.context_id); + debug!( + "CreateOrUpdateScript command applying with to (script_id: {}, previous_context_id: {:?})", + self.id, previous_context_id + ); + + // If None assign new context ID, otherwise assign the old one + // If re-loading and different from the previous one, the old one will be removed + let current_context_id = (assigner.assign)(script.as_deref(), &self.id, &self.content, &mut contexts); + let current_context_id = if let Some(id) = current_context_id { + id + } else { + let ctxt = (builder.load)(&self.id, &self.content, &settings.context_initializers, &settings.context_pre_handling_initializers, world, runtime.runtime.as_mut().unwrap()).unwrap(); + contexts.insert(ctxt) + }; + + if let Some(previous) = previous_context_id { + if previous != current_context_id { + debug!( + "Script is being moved to a new context with id: {}, removing up old context.", + current_context_id + ); + script.as_deref_mut().unwrap().context_id = current_context_id; + (assigner.remove)(previous, script.unwrap(), &mut contexts); + } + } + + + // now we can insert the actual script + scripts.scripts.insert( + self.id.clone(), + Script { + id: self.id, + asset: self.asset, + context_id: current_context_id, + }, + ); + }); + world.insert_resource(settings); + world.insert_non_send_resource(runtime); + world.insert_non_send_resource(contexts); + } +} diff --git a/crates/bevy_mod_scripting_core/src/context.rs b/crates/bevy_mod_scripting_core/src/context.rs new file mode 100644 index 00000000..169cd831 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/context.rs @@ -0,0 +1,152 @@ +use std::{collections::HashMap, sync::atomic::AtomicU32}; + +use bevy::ecs::{entity::Entity, system::Resource, world::World}; + +use crate::{ + prelude::{Runtime, ScriptError}, + script::{Script, ScriptId}, +}; + +pub trait Context: 'static {} +impl Context for T {} + +pub type ContextId = u32; + +#[derive(Resource)] +pub struct ScriptContexts { + pub(crate) contexts: HashMap, +} + +impl Default for ScriptContexts { + fn default() -> Self { + Self { + contexts: Default::default(), + } + } +} + +static CONTEXT_ID_COUNTER: AtomicU32 = AtomicU32::new(0); +impl ScriptContexts { + pub fn new() -> Self { + Self { + contexts: HashMap::new(), + } + } + + /// Allocates a new ContextId and inserts the context into the map + pub fn insert(&mut self, ctxt: T) -> ContextId { + let id = CONTEXT_ID_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + self.contexts.insert(id, ctxt); + id + } + + /// Allocate new context id without inserting a context + pub fn allocate_id(&self) -> ContextId { + CONTEXT_ID_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + } + + pub fn remove(&mut self, id: ContextId) -> Option { + self.contexts.remove(&id) + } +} + +/// Initializer run once after creating a context but before executing it for the first time +pub type ContextInitializer = fn(&ScriptId, &mut C) -> Result<(), ScriptError>; +/// Initializer run every time before executing or loading a script +pub type ContextPreHandlingInitializer = + fn(&ScriptId, Entity, &mut C) -> Result<(), ScriptError>; + +#[derive(Resource)] +pub struct ContextLoadingSettings { + pub loader: Option>, + pub assigner: Option>, + pub context_initializers: Vec>, + pub context_pre_handling_initializers: Vec>, +} + +impl Default for ContextLoadingSettings { + fn default() -> Self { + Self { + loader: None, + assigner: None, + context_initializers: Default::default(), + context_pre_handling_initializers: Default::default(), + } + } +} + +impl Clone for ContextLoadingSettings { + fn clone(&self) -> Self { + Self { + loader: self.loader.clone(), + assigner: self.assigner.clone(), + context_initializers: self.context_initializers.clone(), + context_pre_handling_initializers: self.context_pre_handling_initializers.clone(), + } + } +} + +/// A strategy for loading and reloading contexts +pub struct ContextBuilder { + pub load: fn( + script: &ScriptId, + content: &[u8], + &[ContextInitializer], + &[ContextPreHandlingInitializer], + &mut World, + runtime: &mut R, + ) -> Result, + pub reload: fn( + script: &ScriptId, + new_content: &[u8], + context: &mut C, + &[ContextInitializer], + &[ContextPreHandlingInitializer], + &mut World, + &mut R, + ) -> Result<(), ScriptError>, +} + +impl Clone for ContextBuilder { + fn clone(&self) -> Self { + Self { + load: self.load, + reload: self.reload, + } + } +} + +/// A strategy for assigning contexts to new and existing but re-loaded scripts as well as for managing old contexts +pub struct ContextAssigner { + /// Assign a context to the script, if script is `None`, this is a new script, otherwise it is an existing script with a context inside `contexts`. + /// Returning None means the script should be assigned a new context + pub assign: fn( + old_script: Option<&Script>, + script_id: &ScriptId, + new_content: &[u8], + contexts: &ScriptContexts, + ) -> Option, + + /// Handle the removal of the script, if any clean up in contexts is necessary perform it here. + /// This will also be called, when a script is assigned a contextId on reload different from the previous one + /// the context_id in that case will be the old context_id and the one stored in the script will be the old one + pub remove: fn(context_id: ContextId, script: &Script, contexts: &mut ScriptContexts), +} + +impl Default for ContextAssigner { + fn default() -> Self { + Self { + assign: |_, _, _, c| Some(c.allocate_id()), + remove: |id, _, c| _ = c.remove(id), + } + } +} + +impl Clone for ContextAssigner { + fn clone(&self) -> Self { + Self { + assign: self.assign, + remove: self.remove, + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/docs.rs b/crates/bevy_mod_scripting_core/src/docs.rs index 8a2a2dfd..d186bcfe 100644 --- a/crates/bevy_mod_scripting_core/src/docs.rs +++ b/crates/bevy_mod_scripting_core/src/docs.rs @@ -1,10 +1,24 @@ -use crate::error::ScriptError; +use bevy::ecs::system::Resource; -/// A documentation piece exported by an `APIProvider` -pub trait DocFragment: 'static { +/// A documentation piece which can be used to make a piece of documentation, most often a module. +pub trait DocumentationFragment: 'static + Sized { + /// Merges two documentation fragments into one, retaining the title of the first fragment. fn merge(self, o: Self) -> Self; - fn gen_docs(self) -> Result<(), ScriptError>; + fn gen_docs(self) -> Result<(), Box>; /// Retrieves the name of the documentation fragment, most likely the name of your game! fn name(&self) -> &'static str; } + +#[derive(Resource)] +pub struct Documentation { + pub fragments: Vec, +} + +impl Default for Documentation { + fn default() -> Self { + Self { + fragments: Default::default(), + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/error.rs b/crates/bevy_mod_scripting_core/src/error.rs index 3f0dd2be..ad111348 100644 --- a/crates/bevy_mod_scripting_core/src/error.rs +++ b/crates/bevy_mod_scripting_core/src/error.rs @@ -1,30 +1,181 @@ +use std::{ + ops::{Deref, DerefMut}, + sync::Arc, +}; + +use bevy::reflect::Reflect; use thiserror::Error; -#[derive(Error, Debug, Clone)] -pub enum ScriptError { - #[error("Runtime error in script `{script}` {msg}")] - RuntimeError { script: String, msg: String }, - #[error("Failed to load script asset for `{script}` {msg}")] - FailedToLoad { script: String, msg: String }, - #[error("Syntax error for script `{script}` {msg}")] - SyntaxError { script: String, msg: String }, - #[error("Callback method `{callback}` invalid for script `{script}` {msg}")] - InvalidCallback { - script: String, - callback: String, - msg: String, - }, - #[error("Failed to attach API for script `{script}` {msg}")] - FailedToAttachAPI { script: String, msg: String }, - #[error("Failed to generate documentation `{0}`")] - DocGenError(String), - #[error("{0}")] - Other(String), +use crate::{bindings::ReflectAllocationId, bindings::ReflectReference}; + +pub type ScriptResult = Result; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum ScriptErrorKind { + /// Any other error, default for script errors generated via Into conversions + Other, + /// Errors specifically to do with reflecting & reading/writing stuff from the world + ReflectionError, + /// Erorrs to do with invalid script API usage, invalid arguments etc. + RuntimeError, + /// Errors to do with the script lifecycle, loading, unloading etc. + Lifecycle, +} + +impl std::fmt::Display for ScriptErrorKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ScriptErrorKind::ReflectionError => f.write_str("Reflection Error"), + ScriptErrorKind::Lifecycle => f.write_str("Script Lifecycle Error"), + ScriptErrorKind::Other => f.write_str("Error"), + ScriptErrorKind::RuntimeError => f.write_str("Runtime Error"), + }; + Ok(()) + } +} + +#[derive(Error, Debug)] +pub struct ScriptErrorWrapper(ScriptError); + +impl std::fmt::Display for ScriptErrorWrapper { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl From for Box { + fn from(val: ScriptError) -> Self { + ScriptErrorWrapper(val).into() + } +} +/// An error with an optional script Context +#[derive(Debug, Clone)] +pub struct ScriptError(pub Arc); + +impl Deref for ScriptError { + type Target = ScriptErrorInner; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +/// The innards are separated to reduce the size of this error +#[derive(Debug)] +pub struct ScriptErrorInner { + pub script: Option, + pub kind: ScriptErrorKind, + pub context: String, + pub reason: Arc, } impl ScriptError { - /// Create new `ScriptError::Other` from another error - pub fn new_other(other: T) -> Self { - Self::Other(other.to_string()) + pub fn new_reflection_error>>( + reason: E, + ) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::ReflectionError, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn new_generic_error>>(reason: E) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::Other, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn new_lifecycle_error>>( + reason: E, + ) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::Lifecycle, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn new_runtime_error>>(reason: E) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::RuntimeError, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn with_context(self, context: S) -> Self { + Self(Arc::new(ScriptErrorInner { + script: self.0.script.clone(), + kind: self.0.kind.clone(), + context: context.to_string(), + reason: self.0.reason.clone(), + })) } } + +impl From for ScriptError { + fn from(value: T) -> Self { + Self::new_generic_error(value) + } +} + +impl std::fmt::Display for ScriptError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if let Some(script) = &self.0.script { + write!( + f, + "Encountered {} error in script `{}`: {}", + self.0.kind, script, self.0.reason + ) + } else { + write!( + f, + "Encountered {} error in a script: {}", + self.0.kind, self.0.reason + ) + } + } +} + +// #[derive(Error, Debug, Clone)] +// pub enum ReflectionError { +// #[error("Base reference `{base}` is invalid. {reason}")] +// InvalidBaseReference { base: String, reason: String }, +// #[error("Cannot safely access `{base}`. {reason}")] +// InsufficientAccess { base: String, reason: String }, +// #[error("Tried to access `{base:?}` with insufficient provenance. {reason}")] +// InsufficientProvenance { +// base: ReflectReference, +// reason: String, +// }, +// #[error("Cannot downcast reference: {reference:?} to: {to}")] +// CannotDowncast { +// reference: ReflectReference, +// to: String, +// }, +// #[error("Could not assign `{rhs}` to `{lhs:?}`. {reason}")] +// InvalidAssignment { +// lhs: ReflectReference, +// rhs: String, +// reason: String, +// }, +// #[error("Failed to build concrete type from &Reflect type: `{ref_}`. Does this type have a FromReflect type data?")] +// FromReflectFailure { ref_: String }, +// #[error("Could not dereference script allocation with ID: {id}. {reason}")] +// AllocationError { +// id: ReflectAllocationId, +// reason: String, +// }, +// #[error("Attempted to access world via stale world reference. Did you store a reference to a world across a frame boundary?")] +// StaleWorldAccess, + +// #[error("{0}")] +// Other(String), +// } diff --git a/crates/bevy_mod_scripting_core/src/event.rs b/crates/bevy_mod_scripting_core/src/event.rs index 7ba34707..2921d19c 100644 --- a/crates/bevy_mod_scripting_core/src/event.rs +++ b/crates/bevy_mod_scripting_core/src/event.rs @@ -1,6 +1,6 @@ -use bevy::prelude::Event; +use bevy::{ecs::entity::Entity, prelude::Event}; -use crate::{error::ScriptError, hosts::Recipients}; +use crate::{error::ScriptError, handler::Args, script::ScriptId}; /// An error coming from a script #[derive(Debug, Event)] @@ -8,15 +8,235 @@ pub struct ScriptErrorEvent { pub error: ScriptError, } -/// An event emitted when a script was loaded or re-loaded (with a hot-reload), -/// guaranteed to be sent for every script at least once and immediately after it's loaded. -#[derive(Clone, Debug, Event)] -pub struct ScriptLoaded { - pub sid: u32, +/// A string which disallows common invalid characters in callback labels, +/// particularly at the start of the string +/// +/// a valid callback label starts with a letter or underscore, and contains only ascii characters, as well as disallows some common keywords +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +pub struct CallbackLabel(String); + +impl CallbackLabel { + fn filter_invalid(s: &str) -> String { + let mut out = String::with_capacity(s.len()); + let mut first = true; + for char in s.chars() { + if char == '_' + || ((!first && char.is_ascii_alphanumeric()) || char.is_ascii_alphabetic()) + { + out.push(char); + first = false; + } else { + continue; + } + } + if FORBIDDEN_KEYWORDS.contains(&s) { + String::default() + } else { + out + } + } + + pub fn new_lossy(label: &str) -> Self { + Self(Self::filter_invalid(label)) + } + + pub fn new(label: &str) -> Option { + let new_lossy = Self::new_lossy(label); + if new_lossy.0.len() != label.len() { + None + } else { + Some(new_lossy) + } + } +} + +pub trait IntoCallbackLabel { + fn into_callback_label() -> CallbackLabel; +} + +impl From<&str> for CallbackLabel { + fn from(s: &str) -> Self { + Self::new_lossy(s) + } +} +impl From for CallbackLabel { + fn from(s: String) -> Self { + Self::from(s.as_str()) + } +} + +impl AsRef for CallbackLabel { + fn as_ref(&self) -> &str { + &self.0 + } +} + +impl std::fmt::Display for CallbackLabel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.as_ref()) + } } -/// A trait for events to be handled by scripts -pub trait ScriptEvent: Send + Sync + Clone + Event + 'static { - /// Retrieves the recipient scripts for this event - fn recipients(&self) -> &Recipients; +/// Describes the designated recipients of a script event +#[derive(Clone, Debug)] +pub enum Recipients { + /// The event needs to be handled by all scripts + All, + /// The event is to be handled by a specific script + Script(ScriptId), + /// The event is to be handled by all the scripts on the specified entity + Entity(Entity), +} + +/// A callback event meant to trigger a callback in a subset/set of scripts in the world with the given arguments +#[derive(Clone, Event, Debug)] +pub struct ScriptCallbackEvent { + pub label: CallbackLabel, + pub recipients: Recipients, + pub args: A, +} + +impl ScriptCallbackEvent { + pub fn new>(label: L, args: A, recipients: Recipients) -> Self { + Self { + label: label.into(), + args, + recipients, + } + } + + pub fn new_for_all>(label: L, args: A) -> Self { + Self::new(label, args, Recipients::All) + } +} + +static FORBIDDEN_KEYWORDS: [&str; 82] = [ + // Lua + "and", + "break", + "do", + "else", + "elseif", + "end", + "false", + "for", + "function", + "if", + "in", + "local", + "nil", + "not", + "or", + "repeat", + "return", + "then", + "true", + "until", + "while", + // Rhai + "true", + "false", + "let", + "const", + "is_shared", + "if", + "else", + "switch", + "do", + "while", + "loop", + "until", + "for", + "in", + "continue", + "break", + "fn", + "private", + "is_def_fn", + "this", + "return", + "throw", + "try", + "catch", + "import", + "export", + "as", + "global", + "Fn", + "call", + "curry", + "type_of", + "print", + "debug", + "eval", + "is_def_var", + "var", + "static", + "is", + "goto", + "match", + "case", + "public", + "protected", + "new", + "use", + "with", + "module", + "package", + "super", + "spawn", + "thread", + "go", + "sync", + "async", + "await", + "yield", + "default", + "void", + "null", + "nil", +]; + +#[cfg(test)] +mod test { + use super::FORBIDDEN_KEYWORDS; + + #[test] + fn test_invalid_strings() { + FORBIDDEN_KEYWORDS.iter().for_each(|keyword| { + assert_eq!(super::CallbackLabel::new(keyword), None); + }); + } + + #[test] + fn test_bad_chars() { + let bad_chars = [ + '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '{', '}', '[', ']', + '|', '\\', ':', ';', '"', '\'', '<', '>', ',', '.', '?', '/', '`', '~', + ]; + bad_chars.iter().for_each(|char| { + assert_eq!(super::CallbackLabel::new(&format!("bad{}", char)), None); + }); + } + + #[test] + fn bad_first_letter() { + let bad_chars = [ + '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '@', '#', '$', '%', '^', '&', '*', + '(', ')', '-', '+', '=', '{', '}', '[', ']', '|', '\\', ':', ';', '"', '\'', '<', '>', + ',', '.', '?', '/', '`', '~', + ]; + bad_chars.iter().for_each(|char| { + assert_eq!(super::CallbackLabel::new(&format!("{}bad", char)), None); + }); + } + + #[test] + fn test_valid_idents() { + let valid = ["h", "_v", "hello", "_2d", "heloo_2", "_1231412"]; + valid.iter().for_each(|ident| { + assert!(super::CallbackLabel::new(ident).is_some()); + assert_eq!(super::CallbackLabel::new_lossy(ident).as_ref(), *ident); + }); + } } diff --git a/crates/bevy_mod_scripting_core/src/handler.rs b/crates/bevy_mod_scripting_core/src/handler.rs new file mode 100644 index 00000000..63bc1e08 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/handler.rs @@ -0,0 +1,37 @@ +use bevy::ecs::{entity::Entity, system::Resource, world::World}; + +use crate::{ + context::{Context, ContextPreHandlingInitializer}, + event::CallbackLabel, + prelude::ScriptError, + runtime::Runtime, + script::ScriptId, +}; + +pub trait Args: Clone + Send + Sync + 'static {} +impl Args for T {} + +pub type HandlerFn = fn( + args: A, + entity: Entity, + script_id: &ScriptId, + callback: &CallbackLabel, + context: &mut C, + pre_handling_initializers: &[ContextPreHandlingInitializer], + runtime: &mut R, + world: &mut World, +) -> Result<(), ScriptError>; + +/// A resource that holds the settings for the callback handler for a specific combination of type parameters +#[derive(Resource)] +pub struct CallbackSettings { + pub callback_handler: Option>, +} + +impl Default for CallbackSettings { + fn default() -> Self { + Self { + callback_handler: None, + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/hosts.rs b/crates/bevy_mod_scripting_core/src/hosts.rs deleted file mode 100644 index 9e8ff585..00000000 --- a/crates/bevy_mod_scripting_core/src/hosts.rs +++ /dev/null @@ -1,448 +0,0 @@ -//! All script host related stuff -use bevy::{asset::Asset, ecs::schedule::ScheduleLabel, prelude::*}; -use std::{ - collections::HashMap, - iter::once, - sync::atomic::{AtomicU32, Ordering}, -}; - -use crate::{ - asset::CodeAsset, - docs::DocFragment, - error::ScriptError, - event::{ScriptEvent, ScriptLoaded}, - world::WorldPointer, -}; - -/// Describes the target set of scripts this event should -/// be handled by -#[derive(Clone, Debug)] -pub enum Recipients { - /// Send to all scripts - All, - /// Send only to scripts on the given entity - Entity(Entity), - /// Send to script with the given ID - ScriptID(u32), - // Send to script with the given name - ScriptName(String), -} - -#[derive(Debug)] -/// Data used to describe a script instance. -pub struct ScriptData<'a> { - pub sid: u32, - pub entity: Entity, - pub name: &'a str, -} - -impl Recipients { - /// Returns true if the given script is a recipient - pub fn is_recipient(&self, c: &ScriptData) -> bool { - match self { - Recipients::All => true, - Recipients::Entity(e) => e == &c.entity, - Recipients::ScriptID(i) => i == &c.sid, - Recipients::ScriptName(n) => n == c.name, - } - } -} - -impl Default for Recipients { - fn default() -> Self { - Self::All - } -} - -/// A script host is the interface between your rust application -/// and the scripts in some interpreted language. -pub trait ScriptHost: Send + Sync + 'static + Default + Resource { - /// the type of the persistent script context, representing the execution context of the script - type ScriptContext: Send + Sync + 'static; - /// the type of events picked up by lua callbacks - type ScriptEvent: ScriptEvent; - /// the type of asset representing the script files for this host - type ScriptAsset: CodeAsset; - /// the type representing the target of api providers, i.e. the - /// script engine or the script context itself - type APITarget: Send + Sync + 'static; - /// the type of each doc fragment - type DocTarget: DocFragment; - - /// Loads a script in byte array format, the script name can be used - /// to send useful errors. - fn load_script( - &mut self, - script: &[u8], - script_data: &ScriptData, - providers: &mut APIProviders, - ) -> Result; - - /// Perform one-off initialization of scripts (happens for every new or re-loaded script) - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError>; - - /// the main point of contact with the bevy world. - /// Scripts are called with appropriate events in the event order - fn handle_events<'a>( - &mut self, - world_ptr: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ); - - /// Loads and runs script instantaneously without storing any script data into the world. - /// The script id is set to `u32::MAX`. - fn run_one_shot( - &mut self, - script: &[u8], - script_name: &str, - entity: Entity, - world: &mut World, - event: Self::ScriptEvent, - ) -> Result<(), ScriptError> { - let fd = ScriptData { - name: script_name, - sid: u32::MAX, - entity, - }; - - let mut providers: APIProviders = world.remove_resource().unwrap(); - let mut ctx = self.load_script(script, &fd, &mut providers).unwrap(); - self.setup_script(&fd, &mut ctx, &mut providers)?; - let events = [event; 1]; - - self.handle_events(world, &events, once((fd, &mut ctx)), &mut providers); - - world.insert_resource(providers); - - Ok(()) - } - - /// Registers the script host with the given app, and attaches handlers to deal with spawning/removing scripts in the given System Set. - /// - /// Ideally place after any game logic which can spawn/remove/modify scripts to avoid frame lag. (typically `PostUpdate`) - fn register_with_app(app: &mut App, schedule: impl ScheduleLabel) { - #[derive(SystemSet, Hash, Debug, Eq, PartialEq, Clone, Copy)] - struct DummySet; - - Self::register_with_app_in_set(app, schedule, DummySet); - } - - /// Similar to `register_with_app` but allows you to specify a system set to add the handler to. - fn register_with_app_in_set(app: &mut App, schedule: impl ScheduleLabel, set: impl SystemSet); -} - -/// Implementors can modify a script context in order to enable -/// API access. ScriptHosts call `attach_api` when creating scripts -pub trait APIProvider: 'static + Send + Sync { - /// the type of script engine/context the API is attached to, this must be the same as the APITarget of the ScriptHost meant to receive it. - type APITarget: Send + Sync + 'static; - /// The type of script context the APIProvider works with, must be the same as the ScriptContext of the target ScriptHost. - type ScriptContext: Send + Sync + 'static; - /// The type of documentation fragment produced by the APIProvider, must be the same as the DocTarget of the target ScriptHost. - type DocTarget: DocFragment; - - /// provide the given script context with the API permamently. - /// Depending on the host, API's may be attached on a per-script basis - /// or on a per-engine basis. Rhai for example allows you to decouple the State of each script from the - /// engine. For one-time setup use `Self::setup_script` - fn attach_api(&mut self, api: &mut Self::APITarget) -> Result<(), ScriptError>; - - /// Hook executed every time a script is about to handle events, most notably used to "refresh" world pointers - fn setup_script_runtime( - &mut self, - _world_ptr: WorldPointer, - _script_data: &ScriptData, - _ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - Ok(()) - } - - /// Setup meant to be executed once for every single script. Use this if you need to consistently setup scripts. - /// For API's use `Self::attach_api` instead. - fn setup_script( - &mut self, - _script_data: &ScriptData, - _ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - Ok(()) - } - - /// Generate a piece of documentation to be merged with the other documentation fragments - /// provided by other API providers - fn get_doc_fragment(&self) -> Option { - None - } - - /// Some providers might provide additional types which need to be registered - /// with the reflection API to work. - fn register_with_app(&self, _app: &mut App) {} -} - -#[derive(Resource)] -/// Stores many API providers -pub struct APIProviders { - pub providers: Vec< - Box< - dyn APIProvider< - APITarget = T::APITarget, - DocTarget = T::DocTarget, - ScriptContext = T::ScriptContext, - >, - >, - >, -} - -impl Default for APIProviders { - fn default() -> Self { - Self { - providers: Default::default(), - } - } -} - -impl APIProviders { - pub fn attach_all(&mut self, ctx: &mut T::APITarget) -> Result<(), ScriptError> { - for p in self.providers.iter_mut() { - p.attach_api(ctx)?; - } - - Ok(()) - } - - pub fn setup_runtime_all( - &mut self, - world_ptr: WorldPointer, - script_data: &ScriptData, - ctx: &mut T::ScriptContext, - ) -> Result<(), ScriptError> { - for p in self.providers.iter_mut() { - p.setup_script_runtime(world_ptr.clone(), script_data, ctx)?; - } - - Ok(()) - } - - pub fn setup_all( - &mut self, - script_data: &ScriptData, - ctx: &mut T::ScriptContext, - ) -> Result<(), ScriptError> { - for p in self.providers.iter_mut() { - p.setup_script(script_data, ctx)?; - } - - Ok(()) - } - - pub fn gen_all(&self) -> Result<(), ScriptError> { - let mut d: Option = None; - for p in self.providers.iter() { - if let Some(f) = p.get_doc_fragment() { - if let Some(prev) = d { - d = Some(prev.merge(f)) - } else { - d = Some(f) - } - } - } - d.map(|d| d.gen_docs()).unwrap_or_else(|| Ok(())) - } -} - -/// A resource storing the script contexts for each script instance. -/// The reason we need this is to split the world borrow in our handle event systems, but this -/// has the added benefit that users don't see the contexts at all, and we can provide -/// generic handling for each new/removed script in one place. -/// -/// We keep this public for now since there is no API for communicating with scripts -/// outside of events. Later this might change. -#[derive(Resource)] -pub struct ScriptContexts { - /// holds script contexts for all scripts given their instance ids. - /// This also stores contexts which are not fully loaded hence the Option - pub context_entities: HashMap, String)>, -} - -impl Default for ScriptContexts { - fn default() -> Self { - Self { - context_entities: Default::default(), - } - } -} - -impl ScriptContexts { - pub fn script_owner(&self, script_id: u32) -> Option { - self.context_entities.get(&script_id).map(|(e, _c, _n)| *e) - } - - pub fn insert_context(&mut self, fd: ScriptData, ctx: Option) { - self.context_entities - .insert(fd.sid, (fd.entity, ctx, fd.name.to_owned())); - } - - pub fn remove_context(&mut self, script_id: u32) { - self.context_entities.remove(&script_id); - } - - pub fn has_context(&self, script_id: u32) -> bool { - self.context_entities - .get(&script_id) - .map_or(false, |(_, c, _)| c.is_some()) - } - - pub fn is_empty(&self) -> bool { - self.context_entities.is_empty() - } -} - -/// A struct defining an instance of a script asset. -/// Multiple instances of the same script can exist on the same entity -#[derive(Debug, Reflect)] -pub struct Script { - /// a strong handle to the script asset - handle: Handle, - - /// the name of the script, usually its file name + relative asset path - name: String, - - /// uniquely identifies the script instance (scripts which use the same asset don't necessarily have the same ID) - id: u32, -} - -static COUNTER: AtomicU32 = AtomicU32::new(0); - -impl Script { - /// creates a new script instance with the given name and asset handle - /// automatically gives this script instance a unique ID. - /// No two scripts instances ever share the same ID - pub fn new(name: String, handle: Handle) -> Self { - Self { - handle, - name, - id: COUNTER.fetch_add(1, Ordering::Relaxed), - } - } - - #[inline(always)] - /// returns the name of the script - pub fn name(&self) -> &str { - &self.name - } - - #[inline(always)] - /// returns the asset handle which this script is executing - pub fn handle(&self) -> &Handle { - &self.handle - } - - #[inline(always)] - /// returns the unique ID of this script instance - pub fn id(&self) -> u32 { - self.id - } - - /// reloads the script by deleting the old context and inserting a new one - /// if the script context never existed, it will after this call. - pub(crate) fn reload_script( - host: &mut H, - script: &Script, - script_assets: &Assets, - providers: &mut APIProviders, - contexts: &mut ScriptContexts, - event_writer: &mut EventWriter, - ) { - debug!("reloading script {}", script.id); - - // retrieve owning entity - if let Some(entity) = contexts.script_owner(script.id()) { - // remove old context - contexts.remove_context(script.id()); - // insert new re-loaded context - Self::insert_new_script_context::( - host, - script, - entity, - script_assets, - providers, - contexts, - event_writer, - ); - } else { - // remove old context - contexts.remove_context(script.id()); - } - } - - /// checks if a script has loaded, and if so loads (`ScriptHost::load_script`), - /// sets up (`ScriptHost::setup_script`) and inserts its new context into the contexts resource - /// otherwise inserts None. Sends ScriptLoaded event if the script was loaded - pub(crate) fn insert_new_script_context( - host: &mut H, - new_script: &Script, - entity: Entity, - script_assets: &Assets, - providers: &mut APIProviders, - contexts: &mut ScriptContexts, - event_writer: &mut EventWriter, - ) { - let fd = ScriptData { - sid: new_script.id(), - entity, - name: new_script.name(), - }; - - let script = match script_assets.get(&new_script.handle) { - Some(s) => s, - None => { - // not loaded yet - debug!("Inserted script which hasn't loaded yet {:?}", fd); - contexts.insert_context(fd, None); - return; - } - }; - debug!("Inserted script {:?}", fd); - - match host.load_script(script.bytes(), &fd, providers) { - Ok(mut ctx) => { - host.setup_script(&fd, &mut ctx, providers) - .expect("Failed to setup script"); - contexts.insert_context(fd, Some(ctx)); - event_writer.send(ScriptLoaded { - sid: new_script.id(), - }); - } - Err(e) => { - warn! {"Error in loading script {}:\n{}", &new_script.name,e} - // this script will now never execute, unless manually reloaded - // but contexts are left in a valid state - contexts.insert_context(fd, None); - } - } - } -} - -#[derive(Component, Debug, Reflect)] -#[reflect(Component, Default)] -/// The component storing many scripts. -/// Scripts receive information about the entity they are attached to -/// Scripts have unique identifiers and hence multiple copies of the same script -/// can be attached to the same entity -pub struct ScriptCollection { - pub scripts: Vec>, -} - -impl Default for ScriptCollection { - fn default() -> Self { - Self { - scripts: Default::default(), - } - } -} diff --git a/crates/bevy_mod_scripting_core/src/lib.rs b/crates/bevy_mod_scripting_core/src/lib.rs index 617571c8..0b762ba5 100644 --- a/crates/bevy_mod_scripting_core/src/lib.rs +++ b/crates/bevy_mod_scripting_core/src/lib.rs @@ -1,211 +1,177 @@ -use crate::{ - event::ScriptErrorEvent, - hosts::{APIProvider, APIProviders, ScriptHost}, +#![allow(clippy::arc_with_non_send_sync)] + +use crate::event::ScriptErrorEvent; +use asset::{ScriptAsset, ScriptAssetLoader, ScriptAssetSettings}; +use bevy::prelude::*; +use bindings::ReflectAllocator; +use context::{ + Context, ContextAssigner, ContextBuilder, ContextInitializer, ContextLoadingSettings, + ContextPreHandlingInitializer, ScriptContexts, }; -use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; -use event::ScriptLoaded; -use systems::script_event_handler; +use handler::{Args, CallbackSettings, HandlerFn}; +use prelude::{ + initialize_runtime, + runtime::{RuntimeInitializer, RuntimeSettings}, + sync_script_data, Documentation, DocumentationFragment, ScriptCallbackEvent, +}; +use runtime::{Runtime, RuntimeContainer}; +use script::Scripts; +use systems::garbage_collector; pub mod asset; +pub mod bindings; +pub mod commands; +pub mod context; pub mod docs; pub mod error; pub mod event; -pub mod hosts; +pub mod handler; +pub mod runtime; +pub mod script; pub mod systems; pub mod world; pub mod prelude { - // general - pub use { - crate::asset::CodeAsset, - crate::docs::DocFragment, - crate::error::ScriptError, - crate::event::{ScriptErrorEvent, ScriptEvent}, - crate::hosts::{ - APIProvider, APIProviders, Recipients, Script, ScriptCollection, ScriptContexts, - ScriptData, ScriptHost, - }, - crate::systems::script_event_handler, - crate::{ - AddScriptApiProvider, AddScriptHost, AddScriptHostHandler, GenDocumentation, - ScriptingPlugin, - }, - bevy_event_priority::{ - AddPriorityEvent, PriorityEvent, PriorityEventReader, PriorityEventWriter, - PriorityEvents, PriorityIterator, - }, - }; + pub use {crate::docs::*, crate::error::*, crate::event::*, crate::systems::*, crate::*}; } -pub use bevy_event_priority as events; #[derive(Default)] -/// Bevy plugin enabling run-time scripting -pub struct ScriptingPlugin; +/// Bevy plugin enabling scripting within the bevy mod scripting framework +pub struct ScriptingPlugin { + /// Callback for initiating the runtime + pub runtime_builder: Option R>, + /// The handler used for executing callbacks in scripts + pub callback_handler: Option>, + /// The context builder for loading contexts + pub context_builder: Option>, + /// The context assigner for assigning contexts to scripts, if not provided default strategy of keeping each script in its own context is used + pub context_assigner: Option>, +} -impl Plugin for ScriptingPlugin { +impl Plugin for ScriptingPlugin { fn build(&self, app: &mut bevy::prelude::App) { - app.add_event::(); + app.add_event::() + .add_event::>() + .init_resource::() + .init_resource::() + .init_resource::() + .init_asset::() + .register_asset_loader(ScriptAssetLoader { + language: "<>".into(), + extensions: &[], + preprocessor: None, + }) + // not every script host will have a runtime, for convenience we add a dummy runtime + .insert_non_send_resource::>(RuntimeContainer { + runtime: self.runtime_builder.map(|f| f()), + }) + .init_non_send_resource::>() + .init_non_send_resource::>() + .insert_resource::>(CallbackSettings { + callback_handler: self.callback_handler, + }) + .insert_resource::>(ContextLoadingSettings { + loader: self.context_builder.clone(), + assigner: Some(self.context_assigner.clone().unwrap_or_default()), + context_initializers: vec![], + context_pre_handling_initializers: vec![], + }) + .add_systems(PostUpdate, (garbage_collector, sync_script_data::)) + .add_systems(PostStartup, initialize_runtime::); } } -pub trait GenDocumentation { - fn update_documentation(&mut self) -> &mut Self; +pub trait AddRuntimeInitializer { + fn add_runtime_initializer(&mut self, initializer: RuntimeInitializer) -> &mut Self; } -impl GenDocumentation for App { - /// Updates/Generates documentation and any other artifacts required for script API's. Disabled in optimized builds unless `doc_always` feature is enabled. - fn update_documentation(&mut self) -> &mut Self { - #[cfg(any(debug_assertions, feature = "doc_always"))] - { - info!("Generating documentation"); - let w = &mut self.world; - let providers: &APIProviders = w.resource(); - if let Err(e) = providers.gen_all() { - error!("{}", e); - } - info!("Documentation generated"); - } - +impl AddRuntimeInitializer for App { + fn add_runtime_initializer(&mut self, initializer: RuntimeInitializer) -> &mut Self { + self.world.init_resource::>(); + self.world + .resource_mut::>() + .as_mut() + .initializers + .push(initializer); self } } -/// Trait for app builder notation -pub trait AddScriptHost { - /// registers the given script host with your app, - /// the given system set will contain systems handling script loading, re-loading, removal etc. - /// This system set will also send events related to the script lifecycle. - /// - /// Note: any systems which need to run the same frame a script is loaded must run after this set. - fn add_script_host(&mut self, schedule: impl ScheduleLabel) -> &mut Self; - - /// Similar to `add_script_host` but allows you to specify a system set to add the script host to. - fn add_script_host_to_set( +pub trait AddContextInitializer { + fn add_context_initializer( &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, + initializer: ContextInitializer, ) -> &mut Self; } -impl AddScriptHost for App { - fn add_script_host_to_set( +impl AddContextInitializer for App { + fn add_context_initializer( &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) -> &mut Self - where - T: ScriptHost, - { - T::register_with_app_in_set(self, schedule, set); - self.init_resource::(); - self.add_event::(); - self - } - - fn add_script_host(&mut self, schedule: impl ScheduleLabel) -> &mut Self - where - T: ScriptHost, - { - T::register_with_app(self, schedule); - self.init_resource::(); - self.add_event::(); + initializer: ContextInitializer, + ) -> &mut Self { + self.world.init_resource::>(); + self.world + .resource_mut::>() + .as_mut() + .context_initializers + .push(initializer); self } } -pub trait AddScriptApiProvider { - fn add_api_provider( +pub trait AddContextPreHandlingInitializer { + fn add_context_pre_handling_initializer( &mut self, - provider: Box< - dyn APIProvider< - APITarget = T::APITarget, - DocTarget = T::DocTarget, - ScriptContext = T::ScriptContext, - >, - >, + initializer: ContextPreHandlingInitializer, ) -> &mut Self; } -impl AddScriptApiProvider for App { - fn add_api_provider( +impl AddContextPreHandlingInitializer for App { + fn add_context_pre_handling_initializer( &mut self, - provider: Box< - dyn APIProvider< - APITarget = T::APITarget, - DocTarget = T::DocTarget, - ScriptContext = T::ScriptContext, - >, - >, + initializer: ContextPreHandlingInitializer, ) -> &mut Self { - provider.register_with_app(self); - let w = &mut self.world; - let providers: &mut APIProviders = &mut w.resource_mut(); - providers.providers.push(provider); + self.world + .resource_mut::>() + .as_mut() + .context_pre_handling_initializers + .push(initializer); self } } -pub trait AddScriptHostHandler { - /// Enables this script host to handle events with priorities in the range [0,min_prio] (inclusive), - /// during from within the given set. - /// - /// Note: this is identical to adding the script_event_handler system manually, so if you require more complex setup, you can use the following: - /// ```rust,ignore - /// self.add_systems( - /// MySchedule, - /// script_event_handler:: - /// ); - /// ``` - /// - /// Think of event handler systems as event sinks, which collect and "unpack" the instructions in each event every frame. - /// Because events are also prioritised, you can enforce a particular order of execution for your events (within each frame) - /// regardless of where they were fired from. - /// - /// A good example of this is Unity [game loop's](https://docs.unity3d.com/Manual/ExecutionOrder.html) `onUpdate` and `onFixedUpdate`. - /// FixedUpdate runs *before* any physics while Update runs after physics and input events. - /// - /// In this crate you can achieve this by using a separate system set before and after your physics, - /// then assigning event priorities such that your events are forced to run at the points you want them to, for example: - /// - /// PrePhysics priority range [0,1] - /// PostPhysics priority range [2,4] - /// - /// | Priority | Handler | Event | - /// | -------- | ----------- | ------------ | - /// | 0 | PrePhysics | Start 0 | - /// | 1 | PrePhysics | FixedUpdate 1 | - /// | 2 | PostPhysics | OnCollision 2 | - /// | 3 | PostPhysics | OnMouse 3 | - /// | 4 | PostPhysics | Update 4 | - /// - /// Note: in this example, if your FixedUpdate event is fired *after* the handler system set has run, it will be discarded (since other handlers discard events of higher priority). - fn add_script_handler( - &mut self, - schedule: impl ScheduleLabel, - ) -> &mut Self; - - /// The same as `add_script_handler` but allows you to specify a system set to add the handler to. - fn add_script_handler_to_set( - &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) -> &mut Self; +pub trait StoreDocumentation { + /// Adds a documentation fragment to the documentation store. + fn add_documentation_fragment(&mut self, fragment: D) -> &mut Self; + /// Consumes all the stored documentation fragments, and merges them into one, then generates the documentation. + fn generate_docs(&mut self) -> Result<(), Box>; } -impl AddScriptHostHandler for App { - fn add_script_handler_to_set( - &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) -> &mut Self { - self.add_systems(schedule, script_event_handler::.in_set(set)); +impl StoreDocumentation for App { + fn add_documentation_fragment(&mut self, fragment: D) -> &mut Self { + self.world.init_non_send_resource::>(); + self.world + .non_send_resource_mut::>() + .as_mut() + .fragments + .push(fragment); self } - fn add_script_handler( - &mut self, - schedule: impl ScheduleLabel, - ) -> &mut Self { - self.add_systems(schedule, script_event_handler::); - self + fn generate_docs(&mut self) -> Result<(), Box> { + let mut docs = match self.world.remove_non_send_resource::>() { + Some(docs) => docs, + None => return Ok(()), + }; + + let mut top_fragment = match docs.fragments.pop() { + Some(fragment) => fragment, + None => return Ok(()), + }; + + for fragment in docs.fragments.into_iter() { + top_fragment = top_fragment.merge(fragment); + } + + top_fragment.gen_docs() } } diff --git a/crates/bevy_mod_scripting_core/src/runtime.rs b/crates/bevy_mod_scripting_core/src/runtime.rs new file mode 100644 index 00000000..65308299 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/runtime.rs @@ -0,0 +1,36 @@ +//! "Runtime" here refers to the execution evironment of scripts. This might be the VM executing bytecode or the interpreter executing source code. +//! The important thing is that there is only one runtime which is used to execute all scripts of a particular type or `context`. + +use bevy::ecs::system::Resource; + +pub trait Runtime: 'static {} +impl Runtime for T {} + +pub type RuntimeInitializer = fn(&mut R); + +#[derive(Clone, Resource)] +pub struct RuntimeSettings { + pub initializers: Vec>, +} + +impl Default for RuntimeSettings { + fn default() -> Self { + Self { + initializers: Default::default(), + } + } +} + +/// Stores a particular runtime. +#[derive(Resource)] +pub struct RuntimeContainer { + pub runtime: Option, +} + +impl Default for RuntimeContainer { + fn default() -> Self { + Self { + runtime: Default::default(), + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/script.rs b/crates/bevy_mod_scripting_core/src/script.rs new file mode 100644 index 00000000..4d39427b --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/script.rs @@ -0,0 +1,42 @@ +//! Everything to do with the way scripts and their contexts are stored and handled. + +use std::{borrow::Cow, collections::HashMap, ops::Deref}; + +use bevy::{asset::Handle, ecs::system::Resource, reflect::Reflect}; + +use crate::{asset::ScriptAsset, context::ContextId}; + +pub type ScriptId = Cow<'static, str>; + +#[derive(bevy::ecs::component::Component, Reflect)] +pub struct ScriptComponent(pub Vec); + +impl Deref for ScriptComponent { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl ScriptComponent { + pub fn new(components: Vec) -> Self { + Self(components) + } +} + +/// All the scripts which are currently loaded or loading and their mapping to contexts +#[derive(Resource, Default, Clone)] +pub struct Scripts { + pub(crate) scripts: HashMap, +} + +/// A script +#[derive(Clone)] +pub struct Script { + pub id: ScriptId, + /// the asset holding the content of the script if it comes from an asset + pub asset: Option>, + /// The id of the context this script is currently assigned to + pub context_id: ContextId, +} diff --git a/crates/bevy_mod_scripting_core/src/systems.rs b/crates/bevy_mod_scripting_core/src/systems.rs index 1ce4f340..5ab54765 100644 --- a/crates/bevy_mod_scripting_core/src/systems.rs +++ b/crates/bevy_mod_scripting_core/src/systems.rs @@ -1,228 +1,426 @@ -use std::collections::HashSet; - use bevy::{ecs::system::SystemState, prelude::*}; -use bevy_event_priority::PriorityEventReader; +use std::any::type_name; use crate::{ - event::ScriptLoaded, - prelude::{APIProviders, Script, ScriptCollection, ScriptContexts, ScriptData, ScriptHost}, - ScriptErrorEvent, + asset::{ScriptAsset, ScriptAssetSettings}, + bindings::ReflectAllocator, + commands::{CreateOrUpdateScript, DeleteScript}, + context::{Context, ContextLoadingSettings, ScriptContexts}, + event::{IntoCallbackLabel, ScriptCallbackEvent, ScriptErrorEvent}, + handler::{Args, CallbackSettings}, + prelude::RuntimeSettings, + runtime::{Runtime, RuntimeContainer}, + script::{ScriptComponent, Scripts}, }; -/// Labels for scripting related systems -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SystemSet)] -pub enum ScriptSystemSet { - /// event handling systems are always marked with this label - EventHandling, +/// Cleans up dangling script allocations +pub fn garbage_collector(mut allocator: ResMut) { + allocator.clean_garbage_allocations() } -/// Handles creating contexts for new/modified scripts -/// Scripts are likely not loaded instantly at this point, so most of the time -/// this system simply inserts an empty context -pub fn script_add_synchronizer( - query: Query< - ( - Entity, - &ScriptCollection, - Ref>, - ), - Changed>, - >, - mut host: ResMut, - mut providers: ResMut>, - script_assets: Res>, - mut contexts: ResMut>, - mut event_writer: EventWriter, +pub fn initialize_runtime( + mut runtime: NonSendMut>, + settings: Res>, ) { - debug!("Handling addition/modification of scripts"); - - query.iter().for_each(|(entity, new_scripts, tracker)| { - if tracker.is_added() { - new_scripts.scripts.iter().for_each(|new_script| { - Script::::insert_new_script_context::( - &mut host, - new_script, - entity, - &script_assets, - &mut providers, - &mut contexts, - &mut event_writer, - ) - }) - } else { - // changed but structure already exists in contexts - // find out what's changed - // we only care about added or removed scripts here - // if the script asset gets changed we deal with that elsewhere - - let context_ids = contexts - .context_entities - .iter() - .filter_map(|(sid, (e, _, _))| if *e == entity { Some(sid) } else { None }) - .cloned() - .collect::>(); - let script_ids = new_scripts - .scripts - .iter() - .map(|s| s.id()) - .collect::>(); + if let Some(r) = runtime.runtime.as_mut() { + for initializer in settings.initializers.iter() { + (initializer)(r); + } + }; +} - let removed_scripts = context_ids.difference(&script_ids); - let added_scripts = script_ids.difference(&context_ids); +/// Processes and reacts appropriately to script asset events, and queues commands to update the internal script state +pub fn sync_script_data( + mut events: EventReader>, + script_assets: Res>, + asset_settings: Res, + mut commands: Commands, +) { + for event in events.read() { + debug!("Responding to script asset event: {:?}", event); + let (id, remove) = match event { + // emitted when a new script asset is loaded for the first time + AssetEvent::Added { id } => (id, false), + AssetEvent::Modified { id } => (id, false), + AssetEvent::Removed { id } | AssetEvent::Unused { id } => (id, true), + _ => continue, + }; + // get the path + let asset = script_assets.get(*id); + let asset = asset.as_ref().expect("Asset was expected to be loaded!"); - for r in removed_scripts { - contexts.remove_context(*r); - } + let path = &asset.asset_path; + // convert it to script id + let converter = asset_settings.script_id_mapper.map; + let script_id = converter(path); - for a in added_scripts { - let script = new_scripts.scripts.iter().find(|e| &e.id() == a).unwrap(); - Script::::insert_new_script_context::( - &mut host, - script, - entity, - &script_assets, - &mut providers, - &mut contexts, - &mut event_writer, - ) - } + if !remove { + commands.add(CreateOrUpdateScript::::new( + script_id, + asset.content.clone(), + Some(script_assets.reserve_handle()), + )); + } else { + commands.add(DeleteScript::::new(script_id)); } - }) + } } -/// Handles the removal of script components and their contexts -pub fn script_remove_synchronizer( - mut query: RemovedComponents>, - mut contexts: ResMut>, -) { - for v in query.read() { - // we know that this entity used to have a script component - // ergo a script context must exist in ctxts, remove all scripts on the entity - let script_ids = contexts - .context_entities - .iter() - .filter_map(|(script_id, (entity, ..))| { - (entity.index() == v.index()).then_some(*script_id) - }) - .collect::>(); - for script_id in script_ids { - contexts.remove_context(script_id); +macro_rules! push_err_and_continue { + ($errors:ident, $expr:expr) => { + match $expr { + Ok(v) => v, + Err(e) => { + $errors.push(e); + continue; + } } - } + }; } -/// Reloads hot-reloaded scripts, or loads missing contexts for scripts which were added but not loaded -pub fn script_hot_reload_handler( - mut events: EventReader>, - mut host: ResMut, - scripts: Query<&ScriptCollection>, - script_assets: Res>, - mut providers: ResMut>, - mut contexts: ResMut>, - mut event_writer: EventWriter, +/// Passes events with the specified label to the script callback with the same name and runs the callback +pub fn event_handler( + world: &mut World, + params: &mut SystemState<( + EventReader>, + Res>, + Res>, + Res, + Query<(Entity, Ref)>, + )>, ) { - for e in events.read() { - let (handle, created) = match e { - AssetEvent::Modified { id } => (id, false), - AssetEvent::Added { id } => (id, true), - _ => continue, - }; + debug!("Handling events with label `{}`", L::into_callback_label()); + + let mut runtime_container = world + .remove_non_send_resource::>() + .unwrap_or_else(|| { + panic!( + "No runtime container for runtime {} found", + type_name::() + ) + }); + let runtime = runtime_container.runtime.as_mut().unwrap_or_else(|| { + panic!( + "No valid runtime in runtime container for runtime {}", + type_name::() + ) + }); + let mut script_contexts = world + .remove_non_send_resource::>() + .unwrap_or_else(|| panic!("No script contexts found for context {}", type_name::())); - // find script using this handle by handle id - // whether this script was modified or created - // if a script exists with this handle, we should reload it to load in a new context - // which at this point will be either None or Some(outdated context) - // both ways are fine - for scripts in scripts.iter() { - for script in &scripts.scripts { - // the script could have well loaded in the same frame that it was added - // in that case it will have a context attached and we do not want to reload it - if script.handle().id() == *handle - && !(contexts.has_context(script.id()) && created) - { - Script::::reload_script::( - &mut host, - script, - &script_assets, - &mut providers, - &mut contexts, - &mut event_writer, - ); + let (mut script_events, callback_settings, context_settings, scripts, entities) = + params.get_mut(world); + + let handler = *callback_settings + .callback_handler + .as_ref() + .unwrap_or_else(|| { + panic!( + "No handler registered for - Runtime: {}, Context: {}, Args: {}", + type_name::(), + type_name::(), + type_name::() + ) + }); + let pre_handling_initializers = context_settings.context_pre_handling_initializers.clone(); + let scripts = scripts.clone(); + let mut errors = Vec::default(); + + let events = script_events.read().cloned().collect::>(); + let entity_scripts = entities + .iter() + .map(|(e, s)| (e, s.0.clone())) + .collect::>(); + + for event in events + .into_iter() + .filter(|e| e.label == L::into_callback_label()) + { + for (entity, entity_scripts) in entity_scripts.iter() { + for script_id in entity_scripts.iter() { + match &event.recipients { + crate::event::Recipients::Script(target_script_id) + if target_script_id != script_id => + { + continue + } + crate::event::Recipients::Entity(target_entity) if target_entity != entity => { + continue + } + _ => (), } + debug!( + "Handling event for script {} on entity {:?}", + script_id, entity + ); + let script = match scripts.scripts.get(script_id) { + Some(s) => s, + None => { + info!( + "Script `{}` on entity `{:?}` is either still loading or doesn't exist, ignoring.", + script_id, entity + ); + continue; + } + }; + let ctxt = script_contexts + .contexts + .get_mut(&script.context_id) + .unwrap(); + + let handler_result = (handler)( + event.args.clone(), + *entity, + &script.id, + &L::into_callback_label(), + ctxt, + &pre_handling_initializers, + runtime, + world, + ); + + push_err_and_continue!(errors, handler_result) } } } + + world.insert_non_send_resource(runtime_container); + world.insert_non_send_resource(script_contexts); + + for error in errors { + let mut error_events = world + .get_resource_mut::>() + .expect("Missing events resource"); + + bevy::log::error!( + "Encountered error in event handling for - Runtime {}, Context: {}, Args: {}. {}", + type_name::(), + type_name::(), + type_name::(), + error.to_string() + ); + error_events.send(ScriptErrorEvent { error }); + } } -/// Lets the script host handle all script events -pub fn script_event_handler(world: &mut World) { - // we need to collect the events to drop the borrow of the world - let mut state: CachedScriptState = world.remove_resource().unwrap(); +#[cfg(test)] +mod test { + use std::{borrow::Cow, collections::HashMap}; - let events = state - .event_state - .get_mut(world) - .0 - .iter_prio_range(MAX, MIN) - .collect::>(); + use crate::{ + event::CallbackLabel, + handler::HandlerFn, + script::{Script, ScriptId}, + }; - world.insert_resource(state); + use super::*; + struct OnTestCallback; - // should help a lot with performance on frames where no events are fired - if events.is_empty() { - return; + impl IntoCallbackLabel for OnTestCallback { + fn into_callback_label() -> CallbackLabel { + "OnTest".into() + } } - let mut ctxts: ScriptContexts = world.remove_resource().unwrap(); - - let mut host: H = world.remove_resource().unwrap(); - let mut providers: APIProviders = world.remove_resource().unwrap(); - - // we need a resource scope to be able to simultaneously access the contexts as well - // as provide world access to scripts - // afaik there is not really a better way to do this in bevy just now - let ctx_iter = ctxts - .context_entities - .iter_mut() - .filter_map(|(sid, (entity, o, name))| { - let ctx = match o { - Some(v) => v, - None => return None, - }; - - Some(( - ScriptData { - sid: *sid, - entity: *entity, - name, - }, - ctx, - )) + struct TestRuntime { + pub invocations: Vec<(Entity, ScriptId)>, + } + + struct TestContext { + pub invocations: Vec, + } + + fn setup_app( + handler_fn: HandlerFn, + runtime: R, + contexts: HashMap, + scripts: HashMap, + ) -> App { + let mut app = App::new(); + + app.add_event::>(); + app.add_event::(); + app.insert_resource::>(CallbackSettings { + callback_handler: Some(handler_fn), + }); + app.add_systems(Update, event_handler::); + app.insert_resource::(Scripts { scripts }); + app.insert_non_send_resource::>(RuntimeContainer { + runtime: Some(runtime), }); + app.insert_non_send_resource::>(ScriptContexts { contexts }); + app + } - // safety: we have unique access to world, future accesses are protected - // by the lock in the pointer - host.handle_events(world, &events, ctx_iter, &mut providers); + #[test] + fn test_handler_called_with_right_args() { + let test_script_id = Cow::Borrowed("test_script"); + let test_ctxt_id = 0; + let test_script = Script { + id: test_script_id.clone(), + asset: None, + context_id: test_ctxt_id, + }; + let scripts = HashMap::from_iter(vec![(test_script_id.clone(), test_script.clone())]); + let contexts = HashMap::from_iter(vec![( + test_ctxt_id, + TestContext { + invocations: vec![], + }, + )]); + let runtime = TestRuntime { + invocations: vec![], + }; + let mut app = setup_app::( + |args, entity, script, _, ctxt, _, runtime, _| { + ctxt.invocations.push(args); + runtime.invocations.push((entity, script.clone())); + Ok(()) + }, + runtime, + contexts, + scripts, + ); + let test_entity_id = app + .world + .spawn(ScriptComponent(vec![test_script_id.clone()])) + .id(); - world.insert_resource(ctxts); - world.insert_resource(host); - world.insert_resource(providers); -} + app.world + .send_event(ScriptCallbackEvent::::new_for_all( + OnTestCallback::into_callback_label(), + "test_args".to_owned(), + )); + app.update(); -#[derive(Resource)] -/// system state for exclusive systems dealing with script events -pub struct CachedScriptState { - pub event_state: SystemState<( - PriorityEventReader<'static, 'static, H::ScriptEvent>, - EventWriter<'static, ScriptErrorEvent>, - EventReader<'static, 'static, ScriptLoaded>, - )>, -} + let test_context = app + .world + .get_non_send_resource::>() + .unwrap(); + let test_runtime = app + .world + .get_non_send_resource::>() + .unwrap(); -impl FromWorld for CachedScriptState { - fn from_world(world: &mut World) -> Self { - Self { - event_state: SystemState::new(world), - } + assert_eq!( + test_context + .contexts + .get(&test_ctxt_id) + .unwrap() + .invocations, + vec!["test_args"] + ); + + assert_eq!( + test_runtime + .runtime + .as_ref() + .unwrap() + .invocations + .iter() + .map(|(e, s)| (*e, s.clone())) + .collect::>(), + vec![(test_entity_id, test_script_id.clone())] + ); + } + + #[test] + fn test_handler_called_on_right_recipients() { + let test_script_id = Cow::Borrowed("test_script"); + let test_ctxt_id = 0; + let test_script = Script { + id: test_script_id.clone(), + asset: None, + context_id: test_ctxt_id, + }; + let scripts = HashMap::from_iter(vec![ + (test_script_id.clone(), test_script.clone()), + ( + "wrong".into(), + Script { + id: "wrong".into(), + asset: None, + context_id: 1, + }, + ), + ]); + let contexts = HashMap::from_iter(vec![ + ( + test_ctxt_id, + TestContext { + invocations: vec![], + }, + ), + ( + 1, + TestContext { + invocations: vec![], + }, + ), + ]); + let runtime = TestRuntime { + invocations: vec![], + }; + let mut app = setup_app::( + |args, entity, script, _, ctxt, _, runtime, _| { + ctxt.invocations.push(args); + runtime.invocations.push((entity, script.clone())); + Ok(()) + }, + runtime, + contexts, + scripts, + ); + let test_entity_id = app + .world + .spawn(ScriptComponent(vec![test_script_id.clone()])) + .id(); + + app.world.send_event(ScriptCallbackEvent::::new( + OnTestCallback::into_callback_label(), + "test_args_script".to_owned(), + crate::event::Recipients::Script(test_script_id.clone()), + )); + + app.world.send_event(ScriptCallbackEvent::::new( + OnTestCallback::into_callback_label(), + "test_args_entity".to_owned(), + crate::event::Recipients::Entity(test_entity_id), + )); + app.update(); + + let test_context = app + .world + .get_non_send_resource::>() + .unwrap(); + let test_runtime = app + .world + .get_non_send_resource::>() + .unwrap(); + + assert_eq!( + test_context + .contexts + .get(&test_ctxt_id) + .unwrap() + .invocations, + vec!["test_args_script", "test_args_entity"] + ); + + assert_eq!( + test_runtime + .runtime + .as_ref() + .unwrap() + .invocations + .iter() + .map(|(e, s)| (*e, s.clone())) + .collect::>(), + vec![ + (test_entity_id, test_script_id.clone()), + (test_entity_id, test_script_id.clone()) + ] + ); } } diff --git a/crates/languages/bevy_mod_scripting_rhai_derive/Cargo.toml b/crates/bevy_mod_scripting_derive/Cargo.toml similarity index 67% rename from crates/languages/bevy_mod_scripting_rhai_derive/Cargo.toml rename to crates/bevy_mod_scripting_derive/Cargo.toml index 18afb127..4540176a 100644 --- a/crates/languages/bevy_mod_scripting_rhai_derive/Cargo.toml +++ b/crates/bevy_mod_scripting_derive/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "bevy_mod_scripting_rhai_derive" +name = "bevy_mod_scripting_derive" version = "0.6.0" authors = ["Maksymilian Mozolewski "] edition = "2021" license = "MIT OR Apache-2.0" -description = "Necessary functionality for Rhai support with bevy_mod_scripting" +description = "Necessary functionality for Lua support with bevy_mod_scripting" repository = "https://github.com/makspll/bevy_mod_scripting" homepage = "https://github.com/makspll/bevy_mod_scripting" keywords = ["bevy", "gamedev", "scripting", "rhai"] @@ -12,14 +12,14 @@ categories = ["game-development"] readme = "readme.md" [lib] -name = "bevy_mod_scripting_rhai_derive" +name = "bevy_mod_scripting_derive" path = "src/lib.rs" proc-macro = true [dependencies] -bevy_mod_scripting_common = { path = "../../bevy_mod_scripting_common", version = "0.6.0" } paste = "1.0.7" -syn = { version = "1.0.57", features = ["full", "fold", "extra-traits"] } +darling = "0.20.3" +syn = { version = "2.0.38", features = ["full", "fold", "extra-traits"] } quote = "1.0.8" proc-macro2 = "1.0" convert_case = "0.5.0" @@ -27,3 +27,5 @@ rustdoc-types = "0.11.0" serde = { version = "1.0", features = ["derive"] } serde_derive = "1.0.137" indexmap = { version = "1.9.1", features = ["serde"] } +strum = { version = "0.24.1", features = ["derive"] } +vec1 = "1.10.1" diff --git a/crates/languages/bevy_mod_scripting_lua_derive/readme.md b/crates/bevy_mod_scripting_derive/readme.md similarity index 100% rename from crates/languages/bevy_mod_scripting_lua_derive/readme.md rename to crates/bevy_mod_scripting_derive/readme.md diff --git a/crates/bevy_mod_scripting_derive/src/input.rs b/crates/bevy_mod_scripting_derive/src/input.rs new file mode 100644 index 00000000..4fc68695 --- /dev/null +++ b/crates/bevy_mod_scripting_derive/src/input.rs @@ -0,0 +1,115 @@ +use darling::{util::Flag, FromDeriveInput, FromMeta}; +use proc_macro2::Ident; +use std::ops::{Deref, DerefMut}; +use syn::{spanned::Spanned, visit_mut::VisitMut, Attribute, Field, TraitItemFn, Variant}; + +#[derive(FromMeta)] +pub struct BMSCorePath(pub syn::Path); + +impl Default for BMSCorePath { + fn default() -> Self { + Self(syn::parse_quote!(bevy_mod_scripting::core)) + } +} + +#[derive(FromMeta)] +pub struct BMSLuaPath(pub syn::Path); + +impl Default for BMSLuaPath { + fn default() -> Self { + Self(syn::parse_quote!(bevy_mod_scripting::lua)) + } +} + +#[derive(FromDeriveInput)] +#[darling(attributes(proxy), forward_attrs(allow, doc, cfg))] +pub struct ProxyInput { + /// The name of the type for which we are generating a proxy (target type) + pub ident: syn::Ident, + /// The visibility of the target type + pub vis: syn::Visibility, + /// The generics on the target type + pub generics: syn::Generics, + /// The attributes on the target type + pub attrs: Vec, + + /// The path to the type for which we are generating a proxy if it's a foreign type + pub remote: Option, + + /// if provided will call the function at this path to get the world callback access. Normally this is retrieved using a global variable. + pub get_world_callback_access_fn: Option, + + /// If set will use the given path as the type for the proxy instead of generating a new one + /// Only used for the special world proxies, probably not useful for anything else, the macro assumes we have an inner ReflectReference in the wrapper + pub proxy_as_type: Option, + + /// The path to the bevy_mod_scripting_core crate + #[darling(default)] + pub bms_core_path: BMSCorePath, + /// The path to the bevy_mod_scripting_lua crate + #[darling(default)] + pub bms_lua_path: BMSLuaPath, + + /// The name to use for the proxy type, if not provided the language derive macro + /// will generate one using a standard prefix. + #[darling(rename = "name")] + pub proxy_name: Option, + + /// The body of the type for which we are generating a proxy + pub data: darling::ast::Data, + + /// A list of multi-lang function definitions to be generated on the proxy type + #[darling(default)] + pub functions: TraitItemFnsWrapper, +} + +#[derive(Default)] +pub struct TraitItemFnsWrapper(pub Vec); + +impl FromMeta for TraitItemFnsWrapper { + fn from_string(value: &str) -> darling::Result { + let token_stream: proc_macro2::TokenStream = value.parse().map_err(syn::Error::from)?; + let trait_items_vec = vec![syn::parse2(token_stream)?]; + Ok(TraitItemFnsWrapper(trait_items_vec)) + } + + fn from_list(items: &[darling::ast::NestedMeta]) -> darling::Result { + Ok(TraitItemFnsWrapper( + items + .iter() + .map(Self::from_nested_meta) + .collect::, _>>()? + .into_iter() + .flat_map(|v| v.0.into_iter()) + .collect::>(), + )) + } +} + +impl Deref for TraitItemFnsWrapper { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl DerefMut for TraitItemFnsWrapper { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +/// Replaces every occurence of an identifier with +/// the given string while preserving the original span +pub struct IdentifierRenamingVisitor<'a> { + pub target: &'a str, + pub replacement: &'a str, +} + +impl VisitMut for IdentifierRenamingVisitor<'_> { + fn visit_ident_mut(&mut self, i: &mut Ident) { + if *i == self.target { + *i = Ident::new(self.replacement, i.span()); + } + } +} diff --git a/crates/bevy_mod_scripting_derive/src/lib.rs b/crates/bevy_mod_scripting_derive/src/lib.rs new file mode 100644 index 00000000..6c932ffc --- /dev/null +++ b/crates/bevy_mod_scripting_derive/src/lib.rs @@ -0,0 +1,531 @@ +mod input; +mod utils; + +use crate::{input::*, utils::doc_attribute_to_string_lit}; + +use std::collections::HashMap; +use darling::util::Flag; +use syn::{ + spanned::Spanned, Path, Token, TraitItemFn, parse_quote, + parse_macro_input, parse_quote_spanned, DeriveInput, ExprClosure, FnArg, + punctuated::Punctuated +}; + +use darling::{FromAttributes, FromDeriveInput}; +use proc_macro::TokenStream; +use proc_macro2::*; +use quote::*; + + +const SELF_ALIAS: &str = "_self"; +const CTXT_ALIAS: &str = "lua"; +const PROXY_PREFIX: &str = "Lua"; + +/// Convert receiver to a standardised form, for example: +/// - instead o a `&self` receiver we have a `_self: LuaRefProxy` +/// - instead of a `&mut self` receiver we have a `_self: LuaRefMutProxy` +/// - instead of a `self` receiver we have a `_self: ValLuaProxy` +/// Returns true if the receiver was changed +fn standardise_receiver(receiver: &mut FnArg, target_type: &Path, bms_lua_path: &Path, proxy_as_type: Option<&Path>) -> bool { + let replacement = if let FnArg::Receiver(receiver) = receiver { + let ref_ = &receiver.reference.as_ref().map(|(amp, lifetime)| { + quote_spanned! {receiver.span()=> + #amp #lifetime + } + }); + + let self_ident = syn::Ident::new(SELF_ALIAS, receiver.span()); + let self_ident_type = match proxy_as_type{ + Some(target_type) => { + quote_spanned! {receiver.span()=> + #target_type + } + }, + None => { + let unproxy_container_name = match (ref_.is_some(), receiver.mutability.is_some()) { + (true, true) => "LuaReflectRefMutProxy", + (true, false) => "LuaReflectRefProxy", + (false, _) => "LuaReflectValProxy", + }; + let unproxy_ident = syn::Ident::new(unproxy_container_name, receiver.span()); + + quote_spanned! {receiver.span()=> + #bms_lua_path::bindings::proxy::#unproxy_ident::<#target_type> + } + } + }; + + Some(syn::FnArg::Typed(parse_quote_spanned! {receiver.span()=> + #self_ident: #self_ident_type + })) + } else { + None + }; + if let Some(replacement) = replacement { + *receiver = replacement; + true + } else { + false + } +} + +/// Collect all arguments into a tuple, for example: +/// - `fn foo(a: i32, b: f32)` becomes `(name: (i32, f32))` +fn collect_args_in_tuple<'a, I: Iterator>( + args: I, + name: &Ident, + outer_mut: bool, +) -> FnArg { + let (_, arg_types) = args + .map(|arg| { + if let FnArg::Typed(arg) = arg { + (arg.pat.clone(), arg.ty.clone()) + } else { + panic!("Function arguments must be typed") + } + }) + .unzip::<_, _, Vec<_>, Vec<_>>(); + + let outer_mut = if outer_mut { + Some(Token![mut](name.span())) + } else { + None + }; + + parse_quote!( #outer_mut #name : (#(#arg_types),*) ) +} + +/// Convert a function definition to a closure, for example: +/// - `fn foo(a: i32, b: f32) -> f32 { a + b }` becomes `|a: i32, b: f32| { a + b} ` +fn convert_function_def_to_closure(f: &TraitItemFn) -> ExprClosure { + let span = f.span(); + let sig = &f.sig.inputs; + let body = f + .default + .as_ref() + .unwrap_or_else(|| panic!("Function {} must have a body", f.sig.ident)); + parse_quote_spanned! {span => + |#sig| #body + } +} + +/// Processes the function def to wrap it in the necessary proxying logic +/// Will convert the function signature to take in two arguments: +/// - a context argument +/// - a tuple of all arguments passed to the underlying function +fn proxy_wrap_function_def( + f: &mut TraitItemFn, + target_type: &Path, + bms_core: &Path, + bms_lua: &Path, + get_world_callback_access_fn: Option<&Path>, + proxy_as_type: Option<&Path>, + mlua: &Path, + attrs: &FunctionAttrs, +) { + + // collect all args into tuple and add lua context arg + let ctxt_alias = syn::Ident::new(CTXT_ALIAS, f.sig.inputs.span()); + + let ctxt_arg = if attrs.with_context.is_present() { + f.sig + .inputs + .pop() + .expect("Expected at least one argument for the context") + .into_value() + } else { + parse_quote_spanned! {f.span()=> + #ctxt_alias: &#mlua::Lua + } + }; + + let ctxt_arg_ident = match &ctxt_arg { + FnArg::Typed(arg) => arg.pat.clone(), + _ => panic!("Expected a typed argument, not a receiver for the context argument"), + }; + + let mut has_receiver = false; + if let Some(first_arg) = f.sig.inputs.first_mut() { + has_receiver = standardise_receiver(first_arg, target_type, bms_lua, proxy_as_type); + }; + + let func_name = &f.sig.ident; + let (mut original_arg_idents, _) = f + .sig + .inputs + .iter() + .map(|arg| { + if let FnArg::Typed(arg) = arg { + (arg.pat.clone(), arg.ty.clone()) + } else { + panic!("Function arguments must be typed") + } + }) + .unzip::<_, _, Vec<_>, Vec<_>>(); + + let span = f.span(); + let args_ident = format_ident!("args", span = f.sig.inputs.span()); + let args_tail_ident = format_ident!("args_tail", span = f.sig.inputs.span()); + let args_head_ident = format_ident!("args_head", span = f.sig.inputs.span()); + let args_split = if get_world_callback_access_fn.is_some() { + let tail = (1..original_arg_idents.len()).map(|i| { + let i = syn::Index::from(i); + quote_spanned!(span=> #args_ident.#i) + }); + quote_spanned!(span=> + let #args_head_ident = #args_ident.0; + let #args_tail_ident = (#(#tail),*); + ) + } else { + Default::default() + }; + + + + // change signature to take in a single args tuple instead of multiple arguments (on top of a context arg) + f.sig.inputs = Punctuated::from_iter(vec![ + ctxt_arg, + collect_args_in_tuple(f.sig.inputs.iter(), &args_ident, true), + ]); + + let args_var_to_use = if get_world_callback_access_fn.is_some() { + original_arg_idents.remove(0); + args_tail_ident + } else { + args_ident + }; + + let out_type = match &f.sig.output { + syn::ReturnType::Default => quote_spanned! {f.span()=> + () + }, + syn::ReturnType::Type(_, ty) => ty.to_token_stream(), + }; + + + // wrap function body in our unwrapping and wrapping logic, ignore pre-existing body + let mut fn_call = std::panic::catch_unwind(|| { + match (&f.default, &attrs.as_trait, get_world_callback_access_fn.is_some()) { + (_, _, true) => quote_spanned!(span=> + world.#func_name(#(#original_arg_idents),*) + ), + (Some(body), _, _) => quote_spanned!(span=> + (||{ #body })() + ), + (_, None, _) => quote_spanned!(span=> + #target_type::#func_name(#(#original_arg_idents),*) + ), + (_, Some(trait_path), _) => { + let trait_path = quote_spanned!(span=> #trait_path); + quote_spanned!(span=> + <#target_type as #trait_path>::#func_name(#(#original_arg_idents),*) + ) + } + } + }) + .unwrap(); // todo: handle the error nicer + + if f.sig.unsafety.is_some() { + fn_call = quote_spanned!(span=> + unsafe { #fn_call } + ); + } + + if attrs.no_proxy.is_present() { + f.default = Some(parse_quote_spanned! {span=> + { + #fn_call + } + }); + } else { + let world = if let Some(world_getter_fn_path) = get_world_callback_access_fn { + quote_spanned!(span=> + let mut world: #bms_core::bindings::WorldCallbackAccess = #world_getter_fn_path(#args_head_ident); + let mut world = world.read().ok_or_else(|| #mlua::Error::external("World no longer exists"))?; + ) + } else { + quote_spanned!(span=> + let mut world: #bms_lua::bindings::proxy::LuaValProxy<#bms_core::bindings::WorldCallbackAccess> = #ctxt_arg_ident.globals().get("world")?; + let mut world = <#bms_lua::bindings::proxy::LuaValProxy<#bms_core::bindings::WorldCallbackAccess> as #bms_core::bindings::Unproxy>::unproxy(&mut world).map_err(#mlua::Error::external)?; + let mut world = world.read().ok_or_else(|| #mlua::Error::external("World no longer exists"))?; + ) + }; + + + f.default = Some(parse_quote_spanned! {span=> + { + #args_split + #world + let out: #out_type = world.proxy_call(#args_var_to_use, |(#(#original_arg_idents),*)| { + #fn_call + }).map_err(|e| #mlua::Error::external(e))?; + Ok(out) + } + }); + } +} + +fn generate_methods_registration( + attrs: &FunctionAttrs, + span: Span, + name: proc_macro2::TokenStream, + closure: ExprClosure, +) -> proc_macro2::TokenStream { + let registration_method = if attrs.metamethod.is_some() { + quote_spanned!(span=>add_meta_function) + } else { + quote_spanned!(span=>add_function) + }; + let docs = attrs.doc.iter().map(|doc| { + quote_spanned! {span=> + methods.document(#doc); + } + }); + quote_spanned! {span=> + #(#docs)* + methods.#registration_method(#name, #closure); + } +} + +#[derive(FromAttributes, Clone)] +#[darling(attributes(lua))] +struct FunctionAttrs { + #[darling(multiple)] + pub doc: Vec, + + /// Marks the function as a composite with the given ID, at least one another function with the same composite + /// ID must exist resulting in a combined function being generated. The actual function to dispatch to will be decided based on + /// the types of arguments. If the signature is invalid (i.e. doesn't allow us to dispatch) an error will be thrown + #[darling(default)] + pub composite: Option, + + /// Marks this to be ignored, only used for fields as functions are opt-in + pub skip: Flag, + + /// If passed will generate statement before calling the method + /// on the type + pub as_trait: Option, + + /// If passed will generate a metamethod call instead of using the function name + pub metamethod: Option, + + /// If true will pass in the context as the last argument, + /// i.e. will remove that argument from the function signature and use it's name as the context alias + pub with_context: Flag, + + /// Skips the unproxying & proxying call, useful for functions that don't need to access the world + pub no_proxy: Flag, +} + +#[proc_macro_derive(LuaProxy, attributes(lua, proxy))] +pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { + let derive_input = parse_macro_input!(input as DeriveInput); + + let mut meta: ProxyInput = match ProxyInput::from_derive_input(&derive_input) { + Ok(v) => v, + Err(e) => return darling::Error::write_errors(e).into(), + }; + if meta.proxy_name.is_some() { + // throw error + return syn::Error::new( + derive_input.span(), + "The `name` attribute is not supported for lua proxies", + ) + .to_compile_error() + .into(); + } + + let target_type = meta.remote.unwrap_or(meta.ident.clone().into()); + let target_type_str = target_type.segments.last().unwrap().ident.to_string(); + let proxy_type_ident = match meta.proxy_as_type.as_ref() { + Some(proxy_as_type) => proxy_as_type.clone(), + None => meta.proxy_name.unwrap_or_else(|| format_ident!("{PROXY_PREFIX}{}", &target_type_str, span = meta.ident.span())).into(), + }; + + + let bms_core = meta.bms_core_path.0; + let bms_lua = meta.bms_lua_path.0; + let tealr: Path = parse_quote_spanned!(bms_lua.span()=> + #bms_lua::tealr + ); + let mlua: Path = parse_quote_spanned!(bms_core.span()=> + #tealr::mlu::mlua + ); + + // generate type level tealr documentation calls + let type_level_document_calls = meta + .attrs + .iter() + .filter(|&a| a.meta.path().is_ident("doc")) + .map(doc_attribute_to_string_lit) + .map(|tkns| { + quote_spanned!(meta.ident.span()=> + methods.document_type(#tkns); + ) + }); + + // extract composites first + let mut composites: HashMap> = HashMap::new(); + meta.functions.0.retain(|f| { + let attrs = FunctionAttrs::from_attributes(&f.attrs).unwrap(); + if let Some(composite_id) = &attrs.composite { + composites + .entry(composite_id.to_owned()) + .or_default() + .push((f.clone(), attrs)); + false + } else { + true + } + }); + + let add_composite_function_stmts = composites.into_values().map(|functions| { + let (first_function, first_function_attrs) = functions + .first() + .cloned() + .expect("At least one function must be a composite for this code to be reached"); + + let name = match &first_function_attrs.metamethod { + Some(metamethod) => quote_spanned!(metamethod.span()=> + #mlua::MetaMethod::#metamethod + ), + None => first_function.sig.ident.to_string().to_token_stream(), + }; + + let value_arg_types = (0..first_function.sig.inputs.len()) + .map(|_| { + quote_spanned!(first_function.span()=> + #mlua::Value + ) + }) + .collect::>(); + + let value_arg_names = (0..first_function.sig.inputs.len()).map(|i| { + format_ident!("arg{}", i, span = first_function.span()) + }).collect::>(); + + let closures = functions + .into_iter() + .map(|(mut f, attrs)| { + proxy_wrap_function_def(&mut f, &target_type, &bms_core, &bms_lua, meta.get_world_callback_access_fn.as_ref() ,meta.proxy_as_type.as_ref(), &mlua, &attrs); + convert_function_def_to_closure(&f) + }) + .collect::>(); + + let closure_args_types = closures.iter().map(|closure| { + let last = closure.inputs.last().unwrap(); + if let syn::Pat::Type(pat_type) = last { + &pat_type.ty + } else { + panic!("Closure must have a single argument tuple as its last argument") + } + }); + + let closure = parse_quote_spanned! {first_function.span()=> + |ctxt, (#(#value_arg_names,)*): (#(#value_arg_types,)*)| { + let args = #mlua::MultiValue::from_vec(vec![#(#value_arg_names,)*]); + #( + if let Ok(args) = <#closure_args_types as #mlua::FromLuaMulti>::from_lua_multi(args.clone(), ctxt) { + let out : Result<_, #mlua::Error> = (#closures)(ctxt, args); + return out?.into_lua(ctxt) + } + )* + Err(#mlua::Error::external("Invalid arguments for composite function")) + } + }; + + generate_methods_registration(&first_function_attrs, first_function.span(), name, closure) + }); + + let add_function_stmts = meta.functions.0.into_iter().filter_map(|mut f| { + let attrs = FunctionAttrs::from_attributes(&f.attrs).unwrap(); + + if attrs.skip.is_present() { + return None; + } + + proxy_wrap_function_def(&mut f, &target_type, &bms_core, &bms_lua, meta.get_world_callback_access_fn.as_ref(), meta.proxy_as_type.as_ref(), &mlua, &attrs); + + let name = match &attrs.metamethod { + Some(metamethod) => quote_spanned!(metamethod.span()=> + #mlua::MetaMethod::#metamethod + ), + None => f.sig.ident.to_string().to_token_stream(), + }; + let span = f.span(); + + let closure = convert_function_def_to_closure(&f); + + Some(generate_methods_registration(&attrs, span, name, closure)) + }); + + let vis = &meta.vis; + + let definition = if let Some(proxy_as_type) = meta.proxy_as_type.as_ref() { + Default::default() + } else { + quote_spanned!(derive_input.span()=> + #[derive(Clone, Debug, #tealr::mlu::UserData, #tealr::ToTypename)] + #vis struct #proxy_type_ident (pub #bms_core::bindings::ReflectReference); + ) + }; + + let conversions = if let Some(proxy_as_type) = meta.proxy_as_type.as_ref() { + Default::default() + } else { + quote_spanned!(derive_input.span()=> + impl AsRef<#bms_core::bindings::ReflectReference> for #proxy_type_ident { + fn as_ref(&self) -> &#bms_core::bindings::ReflectReference { + &self.0 + } + } + + impl From<#bms_core::bindings::ReflectReference> for #proxy_type_ident { + fn from(r: #bms_core::bindings::ReflectReference) -> Self { + Self(r) + } + } + ) + }; + + + quote_spanned! {meta.ident.span()=> + + #definition + + impl #bms_lua::bindings::proxy::LuaProxied for #target_type { + type Proxy = #proxy_type_ident; + } + + impl #tealr::mlu::TealData for #proxy_type_ident { + fn add_methods<'lua, M: #tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut M) { + #(#type_level_document_calls)* + #(#add_composite_function_stmts)* + #(#add_function_stmts)* + } + } + + + impl<'lua> #tealr::mlu::mlua::FromLua<'lua> for #proxy_type_ident { + fn from_lua( + value: #tealr::mlu::mlua::Value<'lua>, + _lua: &#tealr::mlu::mlua::Lua, + ) -> Result { + match value { + tealr::mlu::mlua::Value::UserData(ud) => Ok(ud.borrow::()?.clone()), + _ => { + return Err(#tealr::mlu::mlua::Error::FromLuaConversionError { + from: value.type_name(), + to: stringify!(#proxy_type_ident), + message: None, + }) + } + } + } + } + + #conversions + } + .into() +} + diff --git a/crates/bevy_mod_scripting_common/src/utils.rs b/crates/bevy_mod_scripting_derive/src/utils.rs similarity index 100% rename from crates/bevy_mod_scripting_common/src/utils.rs rename to crates/bevy_mod_scripting_derive/src/utils.rs diff --git a/crates/bevy_script_api/Cargo.toml b/crates/bevy_script_api/Cargo.toml deleted file mode 100644 index 4f069e48..00000000 --- a/crates/bevy_script_api/Cargo.toml +++ /dev/null @@ -1,41 +0,0 @@ -[package] -name = "bevy_script_api" -version = "0.6.0" -authors = ["Maksymilian Mozolewski "] -edition = "2021" -license = "MIT OR Apache-2.0" -description = "Bevy API for multiple script languages, part of bevy_mod_scripting." -repository = "https://github.com/makspll/bevy_mod_scripting" -homepage = "https://github.com/makspll/bevy_mod_scripting" -keywords = ["bevy", "gamedev", "scripting", "lua", "rhai"] -categories = ["game-development"] -readme = "readme.md" - -[features] -lua = ["bevy_mod_scripting_lua", "bevy_mod_scripting_lua_derive"] -rhai = ["bevy_mod_scripting_rhai"] - -[dependencies] -bevy = { workspace = true, default-features = false, features = [ - "bevy_asset", - "bevy_gltf", - "bevy_animation", - "bevy_core_pipeline", - "bevy_ui", - "bevy_pbr", - "bevy_render", - "bevy_text", - "bevy_sprite", - "file_watcher", - "multi-threaded", -] } -bevy_mod_scripting_core = { workspace = true } -parking_lot = "0.12.1" -paste = "1.0.7" -thiserror = "1.0.32" -# lua -bevy_mod_scripting_lua = { path = "../languages/bevy_mod_scripting_lua", version = "0.6.0", optional = true } -bevy_mod_scripting_lua_derive = { path = "../languages/bevy_mod_scripting_lua_derive", version = "0.6.0", optional = true } -bevy_mod_scripting_rhai = { path = "../languages/bevy_mod_scripting_rhai", version = "0.6.0", optional = true } -smol_str = "0.2" -allocator-api2 = "0.2" diff --git a/crates/bevy_script_api/readme.md b/crates/bevy_script_api/readme.md deleted file mode 100644 index 2a766e09..00000000 --- a/crates/bevy_script_api/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# bevy_script_api - -This crate is a part of the ["bevy_mod_scripting" workspace](https://github.com/makspll/bevy_mod_scripting). \ No newline at end of file diff --git a/crates/bevy_script_api/src/common/bevy/mod.rs b/crates/bevy_script_api/src/common/bevy/mod.rs deleted file mode 100644 index 40cf4ab1..00000000 --- a/crates/bevy_script_api/src/common/bevy/mod.rs +++ /dev/null @@ -1,304 +0,0 @@ -use std::{ - ops::{Deref, DerefMut}, - sync::Arc, -}; - -use crate::ReflectReference; -/// Common functionality for all script hosts -use bevy::{ - ecs::system::Command, - prelude::{ - AppTypeRegistry, BuildWorldChildren, Children, DespawnChildrenRecursive, DespawnRecursive, - Entity, Parent, ReflectComponent, ReflectDefault, ReflectResource, - }, - reflect::{ - DynamicArray, DynamicEnum, DynamicList, DynamicMap, DynamicStruct, DynamicTuple, - DynamicTupleStruct, TypeRegistration, - }, -}; -use bevy_mod_scripting_core::{prelude::ScriptError, world::WorldPointer}; - -/// Helper trait for retrieving a world pointer from a script context. -pub trait GetWorld { - type Error; - fn get_world(&self) -> Result; -} - -#[derive(Clone)] -pub struct ScriptTypeRegistration(pub(crate) Arc); - -impl ScriptTypeRegistration { - pub fn new(arc: Arc) -> Self { - Self(arc) - } - - #[inline(always)] - pub fn short_name(&self) -> &str { - self.0.type_info().type_path_table().short_path() - } - - #[inline(always)] - pub fn type_name(&self) -> &'static str { - self.0.type_info().type_path_table().path() - } -} - -impl std::fmt::Debug for ScriptTypeRegistration { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("ScriptTypeRegistration") - .field(&self.0.type_info().type_path()) - .finish() - } -} - -impl std::fmt::Display for ScriptTypeRegistration { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(self.0.type_info().type_path()) - } -} - -impl Deref for ScriptTypeRegistration { - type Target = TypeRegistration; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -#[derive(Clone, Debug)] -pub struct ScriptWorld(WorldPointer); - -impl std::fmt::Display for ScriptWorld { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str("World") - } -} - -impl Deref for ScriptWorld { - type Target = WorldPointer; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for ScriptWorld { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl AsRef for ScriptWorld { - fn as_ref(&self) -> &WorldPointer { - &self.0 - } -} - -impl From for WorldPointer { - fn from(val: ScriptWorld) -> Self { - val.0 - } -} - -impl ScriptWorld { - pub fn new(ptr: WorldPointer) -> Self { - Self(ptr) - } - pub fn get_children(&self, parent: Entity) -> Vec { - let w = self.read(); - w.get::(parent) - .map(|v| v.to_vec()) - .unwrap_or_default() - } - - pub fn get_parent(&self, entity: Entity) -> Option { - let w = self.read(); - w.get::(entity).map(|parent| parent.get()) - } - - pub fn push_child(&self, parent: Entity, child: Entity) { - let mut w = self.write(); - if let Some(mut entity) = w.get_entity_mut(parent) { - entity.push_children(&[child]); - } - } - - pub fn remove_children(&self, parent: Entity, children: &[Entity]) { - let mut w = self.write(); - - if let Some(mut entity) = w.get_entity_mut(parent) { - entity.remove_children(children); - } - } - - pub fn insert_children(&self, parent: Entity, index: usize, children: &[Entity]) { - let mut w = self.write(); - - if let Some(mut entity) = w.get_entity_mut(parent) { - entity.insert_children(index, children); - } - } - - pub fn despawn_children_recursive(&self, entity: Entity) { - let mut w = self.write(); - DespawnChildrenRecursive { entity }.apply(&mut w); - } - - pub fn despawn_recursive(&self, entity: Entity) { - let mut w = self.write(); - DespawnRecursive { entity }.apply(&mut w); - } - - pub fn get_type_by_name(&self, type_name: &str) -> Option { - let w = self.read(); - - let registry: &AppTypeRegistry = w.get_resource().unwrap(); - - let registry = registry.read(); - - registry - .get_with_short_type_path(type_name) - .or_else(|| registry.get_with_type_path(type_name)) - .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) - } - - pub fn add_default_component( - &self, - entity: Entity, - comp_type: ScriptTypeRegistration, - ) -> Result { - let mut w = self.write(); - - // Remove: AppTypeRegistry - let registry: AppTypeRegistry = w.remove_resource().unwrap(); - - let mut entity_ref = w - .get_entity_mut(entity) - .ok_or_else(|| ScriptError::Other(format!("Entity is not valid {:#?}", entity)))?; - - let component_data = comp_type.data::().ok_or_else(|| { - ScriptError::Other(format!("Not a component {}", comp_type.short_name())) - })?; - - let registry_lock = registry.read(); - - // this is just a formality - // TODO: maybe get an add_default impl added to ReflectComponent - // this means that we don't require ReflectDefault for adding components! - match comp_type.0.type_info(){ - bevy::reflect::TypeInfo::Struct(_) => component_data.insert(&mut entity_ref, &DynamicStruct::default(), ®istry_lock), - bevy::reflect::TypeInfo::TupleStruct(_) => component_data.insert(&mut entity_ref, &DynamicTupleStruct::default(), ®istry_lock), - bevy::reflect::TypeInfo::Tuple(_) => component_data.insert(&mut entity_ref, &DynamicTuple::default(), ®istry_lock), - bevy::reflect::TypeInfo::List(_) => component_data.insert(&mut entity_ref, &DynamicList::default(), ®istry_lock), - bevy::reflect::TypeInfo::Array(_) => component_data.insert(&mut entity_ref, &DynamicArray::new(Box::new([])), ®istry_lock), - bevy::reflect::TypeInfo::Map(_) => component_data.insert(&mut entity_ref, &DynamicMap::default(), ®istry_lock), - bevy::reflect::TypeInfo::Value(_) => component_data.insert(&mut entity_ref, - comp_type.data::().ok_or_else(|| - ScriptError::Other(format!("Component {} is a value or dynamic type with no `ReflectDefault` type_data, cannot instantiate sensible value",comp_type.short_name())))? - .default() - .as_ref(), - ®istry_lock), - bevy::reflect::TypeInfo::Enum(_) => component_data.insert(&mut entity_ref, &DynamicEnum::default(), ®istry_lock) - }; - // if we do not drop the lock here, line below will complain registry is still borrowed at drop - drop(registry_lock); - - // Insert: AppTypeRegistry - w.insert_resource(registry); - - Ok(ReflectReference::new_component_ref( - component_data.clone(), - entity, - self.clone().into(), - )) - } - - pub fn get_component( - &self, - entity: Entity, - comp_type: ScriptTypeRegistration, - ) -> Result, ScriptError> { - let w = self.read(); - - let entity_ref = w - .get_entity(entity) - .ok_or_else(|| ScriptError::Other(format!("Entity is not valid {:#?}", entity)))?; - - let component_data = comp_type.data::().ok_or_else(|| { - ScriptError::Other(format!("Not a component {}", comp_type.short_name())) - })?; - - Ok(component_data.reflect(entity_ref).map(|_component| { - ReflectReference::new_component_ref(component_data.clone(), entity, self.clone().into()) - })) - } - - pub fn has_component( - &self, - entity: Entity, - comp_type: ScriptTypeRegistration, - ) -> Result { - let w = self.read(); - let component_data = comp_type.data::().ok_or_else(|| { - ScriptError::Other(format!("Not a component {}", comp_type.short_name())) - })?; - - let entity_ref = w - .get_entity(entity) - .ok_or_else(|| ScriptError::Other(format!("Entity is not valid {:#?}", entity)))?; - - Ok(component_data.reflect(entity_ref).is_some()) - } - - pub fn remove_component( - &mut self, - entity: Entity, - comp_type: ScriptTypeRegistration, - ) -> Result<(), ScriptError> { - let mut w = self.write(); - - let mut entity_ref = w - .get_entity_mut(entity) - .ok_or_else(|| ScriptError::Other(format!("Entity is not valid {:#?}", entity)))?; - - let component_data = comp_type.data::().ok_or_else(|| { - ScriptError::Other(format!("Not a component {}", comp_type.short_name())) - })?; - component_data.remove(&mut entity_ref); - Ok(()) - } - - pub fn get_resource( - &self, - res_type: ScriptTypeRegistration, - ) -> Result, ScriptError> { - let w = self.read(); - - let resource_data = res_type.data::().ok_or_else(|| { - ScriptError::Other(format!("Not a resource {}", res_type.short_name())) - })?; - - Ok(resource_data.reflect(&w).map(|_res| { - ReflectReference::new_resource_ref(resource_data.clone(), self.clone().into()) - })) - } - - pub fn has_resource(&self, res_type: ScriptTypeRegistration) -> Result { - let w = self.read(); - - let resource_data = res_type.data::().ok_or_else(|| { - ScriptError::Other(format!("Not a resource {}", res_type.short_name())) - })?; - - Ok(resource_data.reflect(&w).is_some()) - } - pub fn remove_resource(&mut self, res_type: ScriptTypeRegistration) -> Result<(), ScriptError> { - let mut w = self.write(); - - let resource_data = res_type.data::().ok_or_else(|| { - ScriptError::Other(format!("Not a resource {}", res_type.short_name())) - })?; - resource_data.remove(&mut w); - Ok(()) - } -} diff --git a/crates/bevy_script_api/src/common/mod.rs b/crates/bevy_script_api/src/common/mod.rs deleted file mode 100644 index 70b747d3..00000000 --- a/crates/bevy_script_api/src/common/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod bevy; -pub mod std; diff --git a/crates/bevy_script_api/src/common/std.rs b/crates/bevy_script_api/src/common/std.rs deleted file mode 100644 index dcf85073..00000000 --- a/crates/bevy_script_api/src/common/std.rs +++ /dev/null @@ -1,139 +0,0 @@ -use std::marker::PhantomData; - -use bevy::reflect::{FromReflect, TypePath}; - -use crate::{error::ReflectionError, ReflectReference, ValueIndex}; - -pub struct ScriptVec { - pub(crate) ref_: ReflectReference, - _ph: PhantomData, -} - -impl Clone for ScriptVec { - fn clone(&self) -> Self { - Self { - ref_: self.ref_.clone(), - _ph: PhantomData, - } - } -} - -impl std::fmt::Debug for ScriptVec { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("ScriptVec") - .field("ref_", &self.ref_) - .finish() - } -} - -impl std::fmt::Display for ScriptVec { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let str = self - .ref_ - .get_typed(|s: &Vec| s.iter().map(|v| format!("{v}")).collect::>()) - .map_err(|_| std::fmt::Error)? - .join(","); - f.write_str("[")?; - f.write_str(&str)?; - f.write_str("]") - } -} - -impl ScriptVec { - pub fn new_ref(ref_: ReflectReference) -> Self { - Self { - ref_, - _ph: PhantomData, - } - } - - pub fn is_empty(&self) -> Result { - Ok(self.len()? == 0) - } - - pub fn len(&self) -> Result { - self.ref_.get_typed(|s: &Vec| s.len()) - } - - pub fn push(&mut self, val: T) -> Result<(), ReflectionError> { - self.ref_.get_mut_typed(|s: &mut Vec| { - s.push(val); - Ok(()) - })? - } - - pub fn pop(&mut self) -> Result, ReflectionError> { - self.ref_.get_mut_typed(|s: &mut Vec| s.pop()) - } - - pub fn clear(&mut self) -> Result<(), ReflectionError> { - self.ref_.get_mut_typed(|s: &mut Vec| { - s.clear(); - Ok(()) - })? - } - - pub fn insert(&mut self, idx: usize, val: T) -> Result<(), ReflectionError> { - self.ref_.get_mut_typed(|s: &mut Vec| { - s.insert(idx, val); - Ok(()) - })? - } - - pub fn remove(&mut self, idx: usize) -> Result { - self.ref_ - .get_mut_typed(|s: &mut Vec| Ok(s.remove(idx)))? - } -} - -impl ValueIndex for ScriptVec { - type Output = ReflectReference; - - fn index(&self, index: usize) -> Self::Output { - self.ref_.index(index) - } -} - -impl From> for ReflectReference { - fn from(v: ScriptVec) -> Self { - v.ref_ - } -} - -pub struct ScriptVecIterator { - current: usize, - len: usize, - base: ScriptVec, -} - -impl Iterator for ScriptVecIterator { - type Item = ReflectReference; - - fn next(&mut self) -> Option { - let nxt = (self.current < self.len).then(|| self.base.index(self.current)); - self.current += 1; - nxt - } -} - -impl IntoIterator for ScriptVec { - type Item = ReflectReference; - - type IntoIter = ScriptVecIterator; - - /// Converts the vector into an iterator over references - /// - /// # Panics - /// will panic if the base reference is invalid or mutably locked - fn into_iter(self) -> Self::IntoIter { - ScriptVecIterator { - current: 0, - // TODO?: end used to be an Option, and this check moved into the next method but - // I am not sure if this will ever realistically fail, so if you do get this exception happening - // hit me with an issue - // if len > 0, subtract 1, otherwise set to 0 - len: self.len().expect("Failed to get length of ScriptVec"), - base: self, - } - } -} diff --git a/crates/bevy_script_api/src/core_providers.rs b/crates/bevy_script_api/src/core_providers.rs deleted file mode 100644 index 0e1196ea..00000000 --- a/crates/bevy_script_api/src/core_providers.rs +++ /dev/null @@ -1,114 +0,0 @@ -use crate::lua::RegisterForeignLuaType; - -pub struct LuaCoreBevyAPIProvider; - -#[derive(Default)] -pub(crate) struct CoreBevyGlobals; - -crate::impl_tealr_generic!(pub(crate) struct T); - -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for CoreBevyGlobals { - 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( - "world", - crate::lua::util::DummyTypeName::::new, - )?; - instances.add_instance( - "script", - crate::lua::util::DummyTypeName::::new, - )?; - instances.add_instance( - "entity", - crate::lua::util::DummyTypeName::::new, - )?; - Ok(()) - } -} - -impl bevy_mod_scripting_core::hosts::APIProvider for LuaCoreBevyAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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(CoreBevyGlobals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other(e.to_string())) - } - - fn get_doc_fragment(&self) -> Option { - Some(bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "CoreBevyAPI", - |tw| { - tw - .document_global_instance::().expect("Something went wrong documenting globals") - .process_type::() - .process_type::>() - .process_type::() - .process_type::>() - .process_type::() - .process_type::>() - }, - )) - } - - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Could not get context"); - let globals = ctx.globals(); - globals - .set( - "entity", - crate::providers::bevy_ecs::LuaEntity::new(script_data.entity), - ) - .map_err(bevy_mod_scripting_core::error::ScriptError::new_other)?; - globals - .set::<_, crate::lua::bevy::LuaScriptData>("script", script_data.into()) - .map_err(bevy_mod_scripting_core::error::ScriptError::new_other)?; - - 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> { - let ctx = ctx.get_mut().expect("Could not get context"); - let globals = ctx.globals(); - globals - .set("world", crate::lua::bevy::LuaWorld::new(world_ptr)) - .map_err(bevy_mod_scripting_core::error::ScriptError::new_other) - } - - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - } -} diff --git a/crates/bevy_script_api/src/error.rs b/crates/bevy_script_api/src/error.rs deleted file mode 100644 index aa2ae622..00000000 --- a/crates/bevy_script_api/src/error.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::borrow::Cow; -use thiserror::Error; - -#[derive(Error, Debug, Clone)] -pub enum ReflectionError { - #[error("Base reference `{base}` is invalid. {reason}")] - InvalidBaseReference { base: String, reason: String }, - #[error("Insuficient provenance error while accessing `{path}`. {msg}")] - InsufficientProvenance { path: String, msg: String }, - #[error("Invalid reflection path: `{path}`. {msg}")] - InvalidReflectionPath { path: String, msg: String }, - #[error("Cannot downcast from `{from}` to `{to}`")] - CannotDowncast { - from: Cow<'static, str>, - to: Cow<'static, str>, - }, - #[error("{0}")] - Other(String), -} - -#[cfg(feature = "lua")] -impl From for bevy_mod_scripting_lua::tealr::mlu::mlua::Error { - fn from(e: ReflectionError) -> Self { - bevy_mod_scripting_lua::tealr::mlu::mlua::Error::RuntimeError(e.to_string()) - } -} - -#[cfg(feature = "rhai")] -impl From for Box { - fn from(e: ReflectionError) -> Self { - bevy_mod_scripting_rhai::rhai::EvalAltResult::ErrorRuntime( - e.to_string().into(), - bevy_mod_scripting_rhai::rhai::Position::NONE, - ) - .into() - } -} diff --git a/crates/bevy_script_api/src/lib.rs b/crates/bevy_script_api/src/lib.rs deleted file mode 100644 index eee50f03..00000000 --- a/crates/bevy_script_api/src/lib.rs +++ /dev/null @@ -1,45 +0,0 @@ -extern crate bevy; - -pub mod error; -#[cfg(feature = "lua")] -pub mod lua; -#[cfg(feature = "rhai")] -pub mod rhai; - -pub mod common; - -#[cfg(feature = "lua")] -pub(crate) mod core_providers; -// for now providers do not support any other lang so just remove this whole module if they are not needed -#[cfg(feature = "lua")] -pub(crate) mod providers; - -pub mod script_ref; -pub mod sub_reflect; -pub mod wrappers; - -pub use {script_ref::*, sub_reflect::*}; - -pub mod prelude { - #[cfg(feature = "lua")] - pub use crate::{ - core_providers::LuaCoreBevyAPIProvider, - lua::{std::LuaVec, FromLuaProxy, IntoLuaProxy, LuaProxyable, ReflectLuaProxyable}, - providers::LuaBevyAPIProvider, - LuaProxy, - }; - - #[cfg(feature = "rhai")] - pub use crate::rhai::{ - bevy::RhaiBevyAPIProvider, - std::{RhaiCopy, RhaiVec}, - FromRhaiProxy, ReflectRhaiProxyable, RhaiProxyable, ToRhaiProxy, - }; - - pub use crate::{common::bevy::GetWorld, ValueIndex}; -} - -#[cfg(feature = "lua")] -pub use bevy_mod_scripting_lua_derive::LuaProxy; - -pub use parking_lot; diff --git a/crates/bevy_script_api/src/lua/bevy/mod.rs b/crates/bevy_script_api/src/lua/bevy/mod.rs deleted file mode 100644 index 69896455..00000000 --- a/crates/bevy_script_api/src/lua/bevy/mod.rs +++ /dev/null @@ -1,296 +0,0 @@ -use crate::common::bevy::{ScriptTypeRegistration, ScriptWorld}; -use crate::providers::bevy_ecs::LuaEntity; -use crate::{impl_from_lua_with_clone, impl_tealr_type}; - -use std::sync::Arc; - -use bevy::hierarchy::BuildWorldChildren; -use bevy::prelude::AppTypeRegistry; - -use bevy::prelude::ReflectResource; -use bevy_mod_scripting_core::prelude::*; -use bevy_mod_scripting_lua::tealr; - -use tealr::mlu::{ - mlua::{self}, - TealData, TealDataMethods, -}; - -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) { - methods.document_type("An object representing an existing and registered rust type."); - methods.document_type("Can be obtained via [`LuaWorld::get_type_by_name`]."); - } - - fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(fields: &mut F) { - fields.document("The [short name](https://docs.rs/bevy/latest/bevy/reflect/struct.TypeRegistration.html#method.get_short_name) of a type"); - fields.add_field_method_get("short_name", |_, s| Ok(s.short_name().to_string())); - - fields.document("The full name of the type"); - fields.add_field_method_get("type_name", |_, s| Ok(s.type_name())); - } -} - -#[derive(Debug)] -pub struct LuaScriptData { - sid: u32, -} - -impl From<&ScriptData<'_>> for LuaScriptData { - fn from(sd: &ScriptData) -> Self { - Self { sid: sd.sid } - } -} - -impl_tealr_type!(LuaScriptData); - -impl TealData for LuaScriptData { - fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(fields: &mut F) { - fields.document("The unique ID of this script"); - fields.add_field_method_get("sid", |_, s| Ok(s.sid)) - } - - fn add_methods<'lua, T: TealDataMethods<'lua, Self>>(methods: &mut T) { - methods.add_meta_method(tealr::mlu::mlua::MetaMethod::ToString, |_, s, ()| { - Ok(format!("{:?}", s)) - }); - } -} - -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) { - methods.document_type("Represents the bevy world all scripts live in."); - methods.document_type("Provides ways to interact with and modify the world."); - - methods.add_meta_method(tealr::mlu::mlua::MetaMethod::ToString, |_, s, ()| { - Ok(format!("{s:?}")) - }); - - methods.document("Retrieves type information given either a short (`MyType`) or fully qualified rust type name (`MyModule::MyType`)."); - methods.document( - "Returns `nil` if no such type exists or if one wasn't registered on the rust side.", - ); - methods.document("\n"); - methods.document("This is used extensively in [`LuaWorld`]"); - methods.add_method("get_type_by_name", |_, world, type_name: String| { - let w = world.read(); - - let registry: &AppTypeRegistry = w.get_resource().unwrap(); - - let registry = registry.read(); - - Ok(registry - .get_with_short_type_path(&type_name) - .or_else(|| registry.get_with_type_path(&type_name)) - .map(|registration| LuaTypeRegistration::new(Arc::new(registration.clone())))) - }); - - methods.document("Inserts a component of the given type to the given entity by instantiating a default version of it."); - methods.document("The component can then be modified using field access."); - methods.add_method( - "add_default_component", - |_, world, (entity, comp_type): (LuaEntity, LuaTypeRegistration)| { - world - .add_default_component(entity.inner()?, comp_type) - .map_err(|e| mlua::Error::RuntimeError(e.to_string())) - }, - ); - - methods.document("Retrieves a component of the given type from the given entity."); - methods.document("If such a component does not exist returns `nil`."); - methods.add_method( - "get_component", - |_, world, (entity, comp_type): (LuaEntity, LuaTypeRegistration)| { - world - .get_component(entity.inner()?, comp_type) - .map_err(|e| mlua::Error::RuntimeError(e.to_string())) - }, - ); - - methods - .document("Returns `true` if the given entity contains a component of the given type."); - methods.add_method( - "has_component", - |_, world, (entity, comp_type): (LuaEntity, LuaTypeRegistration)| { - world - .has_component(entity.inner()?, comp_type) - .map_err(|e| mlua::Error::RuntimeError(e.to_string())) - }, - ); - - methods.document("Removes the given component from the given entity, does nothing if it doesn't exist on the entity."); - methods.add_method_mut( - "remove_component", - |_, world, (entity, comp_type): (LuaEntity, LuaTypeRegistration)| { - world - .remove_component(entity.inner()?, comp_type) - .map_err(|e| mlua::Error::RuntimeError(e.to_string())) - }, - ); - - methods.document("Retrieves a resource of the given type from the world."); - methods.document("If such a resource does not exist returns `nil`."); - methods.add_method("get_resource", |_, world, res_type: LuaTypeRegistration| { - world - .get_resource(res_type) - .map_err(|e| mlua::Error::RuntimeError(e.to_string())) - }); - - methods.document( - "Removes the given resource from the world, if one doesn't exist it does nothing.", - ); - methods.add_method( - "remove_resource", - |_, world, res_type: LuaTypeRegistration| { - let mut w = world.write(); - - let resource_data = res_type.data::().ok_or_else(|| { - mlua::Error::RuntimeError(format!("Not a resource {}", res_type.short_name())) - })?; - resource_data.remove(&mut w); - Ok(()) - }, - ); - - methods.document("Returns `true` if the world contains a resource of the given type."); - methods.add_method("has_resource", |_, world, res_type: LuaTypeRegistration| { - let w = world.read(); - - let resource_data = res_type.data::().ok_or_else(|| { - mlua::Error::RuntimeError(format!("Not a resource {}", res_type.short_name())) - })?; - - Ok(resource_data.reflect(&w).is_some()) - }); - - methods.document("Retrieves children entities of the parent entity if it has any."); - methods.add_method("get_children", |_, world, parent: LuaEntity| { - Ok(world - .get_children(parent.inner()?) - .into_iter() - .map(LuaEntity::new) - .collect::>()) - }); - - methods.document("Retrieves the parent entity of the given entity if it has any."); - methods.add_method("get_parent", |_, world, parent: LuaEntity| { - Ok(world.get_parent(parent.inner()?).map(LuaEntity::new)) - }); - - methods.document("Attaches children entities to the given parent entity."); - methods.add_method( - "push_children", - |_, world, (parent, children): (LuaEntity, Vec)| { - let mut w = world.write(); - let children = children - .iter() - .map(|e| e.inner()) - .collect::, _>>()?; - - if let Some(mut entity) = w.get_entity_mut(parent.inner()?) { - entity.push_children(&children); - } - - Ok(()) - }, - ); - - methods.document("Attaches child entity to the given parent entity."); - methods.add_method_mut( - "push_child", - |_, world, (parent, child): (LuaEntity, LuaEntity)| { - world.push_child(parent.inner()?, child.inner()?); - Ok(()) - }, - ); - - methods.document("Removes children entities from the given parent entity."); - methods.add_method( - "remove_children", - |_, world, (parent, children): (LuaEntity, Vec)| { - let children = children - .iter() - .map(|e| e.inner()) - .collect::, _>>()?; - - world.remove_children(parent.inner()?, &children); - Ok(()) - }, - ); - - methods.document("Removes child entity from the given parent entity."); - methods.add_method( - "remove_child", - |_, world, (parent, child): (LuaEntity, LuaEntity)| { - world.remove_children(parent.inner()?, &[child.inner()?]); - Ok(()) - }, - ); - - methods - .document("Inserts children entities to the given parent entity at the given index."); - methods.add_method( - "insert_children", - |_, world, (parent, index, children): (LuaEntity, LuaIndex, Vec)| { - let children = children - .iter() - .map(|e| e.inner()) - .collect::, _>>()?; - - world.insert_children(parent.inner()?, *index, &children); - Ok(()) - }, - ); - - methods.document("Inserts child entity to the given parent entity at the given index."); - methods.add_method( - "insert_child", - |_, world, (parent, index, child): (LuaEntity, LuaIndex, LuaEntity)| { - world.insert_children(parent.inner()?, *index, &[child.inner()?]); - Ok(()) - }, - ); - - methods.document("Despawns the given entity's children recursively"); - methods.add_method( - "despawn_children_recursive", - |_, world, entity: LuaEntity| { - world.despawn_children_recursive(entity.inner()?); - Ok(()) - }, - ); - - methods.document("Despawns the given entity and the entity's children recursively"); - methods.add_method("despawn_recursive", |_, world, entity: LuaEntity| { - world.despawn_recursive(entity.inner()?); - Ok(()) - }); - - methods.document("Spawns a new entity and returns its Entity ID"); - methods.add_method("spawn", |_, world, ()| { - let mut w = world.write(); - - Ok(LuaEntity::new(w.spawn(()).id())) - }); - - methods.document( - "Despawns the given entity if it exists, returns true if deletion was successfull", - ); - methods.add_method("despawn", |_, world, entity: LuaEntity| { - let mut w = world.write(); - - Ok(w.despawn(entity.inner()?)) - }); - } -} diff --git a/crates/bevy_script_api/src/lua/mod.rs b/crates/bevy_script_api/src/lua/mod.rs deleted file mode 100644 index 08bcb30b..00000000 --- a/crates/bevy_script_api/src/lua/mod.rs +++ /dev/null @@ -1,306 +0,0 @@ -use ::std::any::TypeId; -use ::std::borrow::Cow; - -use crate::common::bevy::GetWorld; -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::{self, ToTypename}; - -use tealr::mlu::mlua::MetaMethod; -use tealr::mlu::{ - mlua::{self, FromLua, IntoLua, Lua, UserData, Value}, - TealData, TealDataMethods, -}; - -use crate::script_ref::{ReflectReference, ReflectedValue, ValueIndex}; - -use self::bevy::LuaWorld; -use self::util::to_host_idx; - -pub mod bevy; -pub mod std; -pub mod util; - -/// A trait allowing to register the [`LuaProxyable`] trait with the type registry for foreign types -/// -/// If you have access to the type you should prefer to use `#[reflect(LuaProxyable)]` instead. -/// This is exactly equivalent. -pub trait RegisterForeignLuaType { - /// Register an instance of `ReflecLuaProxyable` type data on this type's registration, - /// if a registration does not yet exist, creates one. - fn register_foreign_lua_type( - &mut self, - ) -> &mut Self; -} - -impl RegisterForeignLuaType for App { - fn register_foreign_lua_type( - &mut self, - ) -> &mut Self { - { - let registry = self.world.resource_mut::(); - let mut registry = registry.write(); - - let user_data = >::from_type(); - - if let Some(registration) = registry.get_mut(TypeId::of::()) { - registration.insert(user_data) - } else { - let mut registration = T::get_type_registration(); - registration.insert(user_data); - registry.add_registration(registration); - } - } - - self - } -} - -impl ValueIndex> for ReflectReference { - type Output = Result; - - fn index(&self, index: Value<'_>) -> Self::Output { - match index { - Value::Integer(idx) => Ok(self.index(to_host_idx(idx as usize))), - Value::String(field) => { - let str_ = field.to_str()?.to_string(); - // TODO: hopefully possible to use a &'_ str here - // but this requires Reflect implementation for &str - Ok(>>::index( - self, - str_.into(), - )) - } - _ => Err(mlua::Error::RuntimeError(format!( - "Cannot index a rust object with {:?}", - index - ))), - } - } -} - -/// For internal use only. -/// -/// Mainly necessary for separation of concerns on the [`ReflectReference`] type, but might have other uses potentially. -/// -/// This is not the same as [`LuaProxyable`], internally this in fact will use [`LuaProxyable`] so treating it like so will cause inifnite loops. -pub(crate) trait ApplyLua { - /// set the proxied object with the given lua value - fn apply_lua<'lua>(&mut self, ctx: &'lua Lua, v: Value<'lua>) -> mlua::Result<()>; -} -impl ApplyLua for ReflectReference { - /// Applies the given lua value to the proxied reflect type. Semantically equivalent to `Reflect::apply` - fn apply_lua<'lua>(&mut self, ctx: &'lua Lua, v: Value<'lua>) -> Result<(), mlua::Error> { - let luaworld = ctx.globals().get::<_, LuaWorld>("world").unwrap(); - - // remove typedata from the world to be able to manipulate world - let proxyable = { - let world = luaworld.read(); - let type_registry = world.resource::().read(); - type_registry - .get_type_data::(self.get(|s| s.type_id())?) - .cloned() - }; - - if let Some(ud) = proxyable { - return ud.apply_lua(self, ctx, v); - } else if let Value::UserData(v) = &v { - if v.is::() { - let b = v.take::().unwrap(); - self.apply(&b.into())?; - return Ok(()); - } - } - - Err(mlua::Error::RuntimeError(self.get(|s| - format!("Attempted to assign `{}` = {v:?}. Did you forget to call `app.register_foreign_lua_type::<{}>`?", - self.path, - s.get_represented_type_info().unwrap().type_path() - ))?) - ) - } -} - -impl<'lua> IntoLua<'lua> for ReflectReference { - /// 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 into_lua(self, ctx: &'lua Lua) -> mlua::Result> { - let world = self.world_ptr.clone(); - let world = world.read(); - - let typedata = &world.resource::(); - let g = typedata.read(); - - let type_id = self.get(|s| s.type_id())?; - if let Some(v) = g.get_type_data::(type_id) { - v.ref_to_lua(self, ctx) - } else { - ReflectedValue { ref_: self }.into_lua(ctx) - } - } -} - -impl ToTypename for ReflectReference { - 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."); - methods.document_type("If you know the reflected value converts to a LuaType (via LuaProxyable), use the `as` operator to convert to said type."); - - methods.add_meta_method(MetaMethod::ToString, |_, val, ()| { - val.ref_.get(|s| Ok(format!("{:?}", &s)))? - }); - - methods.add_meta_method_mut(MetaMethod::Index, |_, val, field: Value| { - let r = val.ref_.index(field)?; - Ok(r) - }); - - methods.add_meta_method_mut( - MetaMethod::NewIndex, - |ctx, val, (field, new_val): (Value, Value)| { - val.ref_.index(field)?.apply_lua(ctx, new_val)?; - Ok(()) - }, - ); - } -} -/// A higher level trait for allowing types to be interpreted as custom lua proxy types (or just normal types, this interface is flexible). -/// Types implementing this trait can have [`ReflectLuaProxyable`] type data registrations inserted into the reflection API. -/// -/// Types registered via the reflection API this way can be accessed from Lua via [`ReflectReference`] objects (via field access). -pub trait LuaProxyable { - /// a version of [`mlua::ToLua::to_lua`] which does not consume the object. - /// - /// Note: The self reference is sourced from the given ReflectReference, attempting to get another mutable reference from the ReflectReference might - /// cause a runtime error to prevent breaking of aliasing rules - fn ref_to_lua(self_: ReflectReference, lua: &Lua) -> mlua::Result; - - /// similar to [`Reflect::apply`] - /// - /// Note: - /// The self reference is sourced from the given ReflectReference, attempting to get another reference from the ReflectReference might - /// cause a runtime error to prevent breaking of aliasing rules - fn apply_lua<'lua>( - self_: &mut ReflectReference, - lua: &'lua Lua, - new_val: Value<'lua>, - ) -> mlua::Result<()>; -} - -/// Exactly alike to [`mlua::ToLua`] -pub trait FromLuaProxy<'lua>: Sized { - fn from_lua_proxy(new_val: Value<'lua>, lua: &'lua Lua) -> mlua::Result; -} - -/// Exactly alike to [`mlua::FromLua`] -pub trait IntoLuaProxy<'lua> { - fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result>; -} - -/// A struct providing type data for the `LuaProxyable` trait. -/// -/// This allows casting static methods from the `LuaProxyable trait`. -#[derive(Clone)] -pub struct ReflectLuaProxyable { - ref_to_lua: for<'lua> fn(ref_: ReflectReference, lua: &'lua Lua) -> mlua::Result>, - apply_lua: for<'lua> fn( - ref_: &mut ReflectReference, - lua: &'lua Lua, - new_val: Value<'lua>, - ) -> mlua::Result<()>, -} - -impl ReflectLuaProxyable { - pub fn ref_to_lua<'lua>( - &self, - ref_: ReflectReference, - lua: &'lua Lua, - ) -> mlua::Result> { - (self.ref_to_lua)(ref_, lua) - } - - pub fn apply_lua<'lua>( - &self, - ref_: &mut ReflectReference, - lua: &'lua Lua, - new_val: Value<'lua>, - ) -> mlua::Result<()> { - (self.apply_lua)(ref_, lua, new_val) - } -} - -impl ::bevy::reflect::FromType - for ReflectLuaProxyable -{ - fn from_type() -> Self { - Self { - ref_to_lua: T::ref_to_lua, - apply_lua: T::apply_lua, - } - } -} - -/// A dummy trait used to combat rust's orphan rules -/// -/// In the future when trait specialization is a thing, this might be a companion trait -/// to `RefLuaType` which allows non Clone types to be used -pub trait ValueLuaType {} - -impl LuaProxyable for T { - fn ref_to_lua(self_: ReflectReference, lua: &Lua) -> mlua::Result { - self_.get_typed(|s: &Self| s.clone().into_lua(lua))? - } - - fn apply_lua<'lua>( - self_: &mut ReflectReference, - _: &'lua Lua, - new_val: Value<'lua>, - ) -> mlua::Result<()> { - if let Value::UserData(v) = new_val { - let o = v.borrow::()?; - - self_.get_mut_typed(|s| *s = o.clone())?; - - Ok(()) - } else { - Err(mlua::Error::RuntimeError( - "Error in assigning to custom user data".to_owned(), - )) - } - } -} - -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) - } -} - -impl<'lua, T: Clone + UserData + Send + ValueLuaType + Reflect + 'static> IntoLuaProxy<'lua> for T { - fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result> { - self.into_lua(lua) - } -} - -impl GetWorld for Lua { - type Error = mlua::Error; - fn get_world(&self) -> Result { - self.globals().get::<_, LuaWorld>("world").map(Into::into) - } -} diff --git a/crates/bevy_script_api/src/lua/std.rs b/crates/bevy_script_api/src/lua/std.rs deleted file mode 100644 index fc36faec..00000000 --- a/crates/bevy_script_api/src/lua/std.rs +++ /dev/null @@ -1,474 +0,0 @@ -use std::sync::Arc; - -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, IntoLua, Lua, UserData, Value}, - TealData, TealDataMethods, -}; -use tealr::TypeBody; - -use paste::paste; - -use crate::common::std::ScriptVec; -use crate::{ - error::ReflectionError, - script_ref::{ReflectReference, ValueIndex}, - sub_reflect::ReflectionPathElement, -}; - -use super::util::to_lua_idx; -use super::util::LuaIndex; -use super::ApplyLua; -use super::FromLuaProxy; -use super::IntoLuaProxy; -use super::LuaProxyable; - -/// Implements custom user data for simple copy types which implement to and from lua -macro_rules! impl_proxyable_by_copy( - ( $($num_ty:ty),*) => { - paste! { - $( - impl $crate::lua::LuaProxyable for $num_ty { - fn ref_to_lua(self_: $crate::script_ref::ReflectReference,lua: & tealr::mlu::mlua::Lua) -> tealr::mlu::mlua::Result > { - self_.get_typed(|self_ : &Self| self_.into_lua(lua))? - } - - fn apply_lua< 'lua>(self_: &mut $crate::script_ref::ReflectReference,lua: & 'lua tealr::mlu::mlua::Lua,new_val:tealr::mlu::mlua::Value< 'lua>) -> tealr::mlu::mlua::Result<()> { - self_.set_val(Self::from_lua(new_val,lua)?)?; - Ok(()) - } - } - - impl <'lua>$crate::lua::FromLuaProxy<'lua> for $num_ty { - #[inline(always)] - fn from_lua_proxy(new_value: Value<'lua>, lua: &'lua Lua) -> tealr::mlu::mlua::Result { - Self::from_lua(new_value,lua) - } - } - - impl <'lua>$crate::lua::IntoLuaProxy<'lua> for $num_ty { - #[inline(always)] - fn to_lua_proxy(self, lua: &'lua Lua) -> tealr::mlu::mlua::Result> { - self.into_lua(lua) - } - } - )* - } - } -); - -impl_proxyable_by_copy!(bool); -impl_proxyable_by_copy!(f32, f64); -impl_proxyable_by_copy!(i8, i16, i32, i64, i128, isize); -impl_proxyable_by_copy!(u8, u16, u32, u64, u128, usize); - -impl LuaProxyable for String { - fn ref_to_lua(self_: ReflectReference, lua: &Lua) -> mlua::Result { - self_.get_typed(|self_: &String| self_.as_str().into_lua(lua))? - } - - fn apply_lua<'lua>( - self_: &mut ReflectReference, - lua: &'lua Lua, - new_val: Value<'lua>, - ) -> mlua::Result<()> { - self_.get_mut_typed(|self_| { - *self_ = Self::from_lua(new_val, lua)?; - Ok(()) - })? - } -} - -impl<'lua> FromLuaProxy<'lua> for String { - fn from_lua_proxy(new_val: Value<'lua>, lua: &'lua Lua) -> mlua::Result { - Self::from_lua(new_val, lua) - } -} - -impl<'lua> IntoLuaProxy<'lua> for String { - fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result> { - self.into_lua(lua) - } -} - -impl FromLuaProxy<'a> + Clone> - LuaProxyable for Option -{ - fn ref_to_lua(self_: ReflectReference, lua: &Lua) -> mlua::Result { - self_.get_typed(|s: &Option| match s { - Some(_) => T::ref_to_lua( - self_.sub_ref(ReflectionPathElement::SubReflection { - label: "as_ref", - get: Arc::new(|ref_| { - ref_.downcast_ref::>() - .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.get_represented_type_info().unwrap().type_path().into(), - to: stringify!(Option).into(), - })? - .as_ref() - .map(|t| t as &dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - }), - get_mut: Arc::new(|ref_| { - ref_.downcast_mut::>() - // TODO: there is some weird borrow checker fuckery going on here - // i tried having from: ref_.get_represented_type_info().unwrap().type_path().into() instead of "Reflect" - // and lying this out in an if let expression, but nothing will satisfy the borrow checker here, so leaving this for now - .ok_or_else(|| ReflectionError::CannotDowncast { - from: "Reflect".into(), - to: stringify!(Option).into(), - })? - .as_mut() - .map(|t| t as &mut dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - }), - }), - lua, - ), - None => Ok(Value::Nil), - })? - } - - fn apply_lua<'lua>( - self_: &mut ReflectReference, - lua: &'lua Lua, - new_val: Value<'lua>, - ) -> mlua::Result<()> { - if let Value::Nil = new_val { - self_.get_mut_typed(|s: &mut Option| { - *s = None; - Ok(()) - })? - } else { - // we need to do this in two passes, first - // ensure that the target type is the 'some' variant to allow a sub reference - let is_none = self_.get_typed(|s: &Option| s.is_none())?; - - if is_none { - return self_.get_mut_typed(|s: &mut Option| { - *s = Some(T::from_lua_proxy(new_val, lua)?); - Ok::<_, mlua::Error>(()) - })?; - } - - T::apply_lua( - &mut self_.sub_ref(ReflectionPathElement::SubReflection { - label: "", - get: Arc::new(|ref_| { - ref_.downcast_ref::>() - .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.get_represented_type_info().unwrap().type_path().into(), - to: stringify!(Option).into(), - })? - .as_ref() - .map(|t| t as &dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - }), - get_mut: Arc::new(|ref_| { - if ref_.is::>() { - ref_.downcast_mut::>() - .unwrap() - .as_mut() - .map(|t| t as &mut dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - } else { - Err(ReflectionError::CannotDowncast { - from: ref_.get_represented_type_info().unwrap().type_path().into(), - to: stringify!(Option).into(), - }) - } - }), - }), - lua, - new_val, - ) - } - } -} - -impl<'lua, T: for<'a> FromLuaProxy<'a>> FromLuaProxy<'lua> for Option { - fn from_lua_proxy(new_val: Value<'lua>, lua: &'lua Lua) -> mlua::Result { - if let Value::Nil = new_val { - Ok(None) - } else { - T::from_lua_proxy(new_val, lua).map(Option::Some) - } - } -} - -impl<'lua, T: for<'a> IntoLuaProxy<'a>> IntoLuaProxy<'lua> for Option { - fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result> { - match self { - Some(v) => v.to_lua_proxy(lua), - None => Ok(Value::Nil), - } - } -} - -/// A reference to a rust vec (vec reference proxy), does not need an owned variant since -/// lua can natively represent lists of things -pub type LuaVec = ScriptVec; - -impl< - T: ToTypename - + FromReflect - + TypePath - + LuaProxyable - + for<'a> FromLuaProxy<'a> - + for<'a> IntoLuaProxy<'a> - + std::fmt::Debug, - > UserData for LuaVec -{ - fn add_methods<'lua, M: tealr::mlu::mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { - let mut x = tealr::mlu::UserDataWrapper::from_user_data_methods(methods); - ::add_methods(&mut x); - } - fn add_fields<'lua, F: tealr::mlu::mlua::UserDataFields<'lua, Self>>(fields: &mut F) { - let mut wrapper = tealr::mlu::UserDataWrapper::from_user_data_fields(fields); - ::add_fields(&mut wrapper) - } -} - -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: ToTypename - + FromReflect - + TypePath - + LuaProxyable - + for<'a> FromLuaProxy<'a> - + for<'a> IntoLuaProxy<'a> - + std::fmt::Debug, - > TypeBody for LuaVec -{ - fn get_type_body() -> tealr::TypeGenerator { - let mut gen = tealr::RecordGenerator::new::(false); - gen.is_user_data = true; - ::add_fields(&mut gen); - ::add_methods(&mut gen); - gen.into() - } -} - -impl< - T: ToTypename - + FromReflect - + TypePath - + LuaProxyable - + for<'a> FromLuaProxy<'a> - + for<'a> IntoLuaProxy<'a>, - > TealData for LuaVec -{ - fn add_methods<'lua, M: TealDataMethods<'lua, Self>>(methods: &mut M) { - methods.document_type("A reference to the Vec Rust type."); - methods.document_type("All indexing begins at 1."); - - methods.add_meta_method(MetaMethod::ToString, |_, s, ()| { - Ok(s.ref_.get(|s| format!("{:?}", s))?) - }); - - methods.add_meta_method(MetaMethod::Index, |_, s, index: LuaIndex| { - Ok(s.index(*index)) - }); - - methods.add_meta_method_mut( - MetaMethod::NewIndex, - |ctx, s, (index, value): (LuaIndex, Value)| s.index(*index).apply_lua(ctx, value), - ); - - 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_: ReflectReference = s.clone().into(); - TypedFunction::from_rust_mut( - move |ctx, ()| { - let o = if curr_idx < len { - ( - to_lua_idx(curr_idx).into_lua(ctx)?, - ref_.index(curr_idx).into_lua(ctx)?, - ) - } else { - (Value::Nil, Value::Nil) - }; - curr_idx += 1; - Ok(o) - }, - ctx, - ) - }, - ); - ); - methods.add_meta_method(MetaMethod::Len, |_, s, ()| Ok(s.len()?)); - - methods.add_method("to_table", |ctx, s, ()| { - let table = ctx.create_table()?; - let len = s.len()?; - - for i in 0..len { - table.raw_set(to_lua_idx(i), s.index(i).into_lua(ctx)?)?; - } - - Ok(table) - }); - - methods.add_method_mut("push", |ctx, s, v: Value| { - let new_val = T::from_lua_proxy(v, ctx)?; - s.push(new_val)?; - Ok(()) - }); - - methods.add_method_mut("pop", |ctx, s, ()| s.pop().map(|v| v.to_lua_proxy(ctx))?); - - methods.add_method_mut("clear", |_, s, ()| { - s.clear()?; - Ok(()) - }); - - methods.add_method_mut("insert", |ctx, s, (idx, v): (LuaIndex, Value<'lua>)| { - s.insert(*idx, T::from_lua_proxy(v, ctx)?)?; - Ok(()) - }); - - methods.add_method_mut("remove", |ctx, s, idx: LuaIndex| { - let removed = s.remove(*idx)?; - removed.to_lua_proxy(ctx) - }); - } -} - -impl< - T: ToTypename - + FromReflect - + TypePath - + LuaProxyable - + for<'a> FromLuaProxy<'a> - + for<'a> IntoLuaProxy<'a> - + std::fmt::Debug, - > LuaProxyable for Vec -{ - fn ref_to_lua(self_: ReflectReference, lua: &Lua) -> mlua::Result { - LuaVec::::new_ref(self_).into_lua(lua) - } - - fn apply_lua<'lua>( - self_: &mut ReflectReference, - lua: &'lua Lua, - new_val: Value<'lua>, - ) -> mlua::Result<()> { - match &new_val { - Value::UserData(ud) => { - let lua_vec = ud.borrow::>()?; - self_.apply(&lua_vec.ref_)?; - } - Value::Table(table) => { - let last_target_idx = self_.get_typed(|s: &Vec| s.len())? - 1; - // there is also another case to consider, Vec has a lua representation available as well (table) - // if we receive one of those, we should also apply it - for entry in table.clone().pairs::() { - let (lua_idx, v) = entry?; - let idx = lua_idx - 1; - if idx > last_target_idx { - // here we don't need to do anything special just use LuaProxyable impl - T::apply_lua(&mut self_.index(idx), lua, v)?; - } else { - // here we don't have anything to apply this to - // use FromLua impl - self_.get_mut_typed(|s: &mut Vec| { - s[idx] = T::from_lua_proxy(v, lua)?; - Ok::<_, mlua::Error>(()) - })??; - } - } - } - _ => { - return Err(mlua::Error::FromLuaConversionError { - from: new_val.type_name(), - to: "userdata or table", - message: Some("LuaVec can only be assigned with itself or a table".to_owned()), - }) - } - } - - Ok(()) - } -} - -impl< - 'lua, - T: ToTypename - + for<'a> FromLuaProxy<'a> - + for<'a> IntoLuaProxy<'a> - + Clone - + FromReflect - + TypePath - + LuaProxyable - + std::fmt::Debug, - > FromLuaProxy<'lua> for Vec -{ - fn from_lua_proxy(new_val: Value<'lua>, lua: &'lua Lua) -> mlua::Result { - match new_val { - Value::UserData(ud) => { - let lua_vec = ud.borrow::>()?; - lua_vec.ref_.get_typed(|s: &Vec| Ok(s.clone()))? - } - Value::Table(table) => { - // there is also another case to consider, Vec has a lua representation available as well (table) - // if we receive one of those, we should clone it one by one - table - .pairs::() - .map(|v| v.and_then(|(_, v)| T::from_lua_proxy(v, lua))) - .collect::, _>>() - } - _ => Err(mlua::Error::FromLuaConversionError { - from: new_val.type_name(), - to: "userdata or table", - message: Some("LuaVec can only be assigned with itself or a table".to_owned()), - }), - } - } -} - -impl<'lua, T: for<'a> IntoLuaProxy<'a> + Clone + FromReflect + LuaProxyable> IntoLuaProxy<'lua> - for Vec -{ - fn to_lua_proxy(self, lua: &'lua Lua) -> mlua::Result> { - let proxies = lua.create_table()?; - for (idx, elem) in self.into_iter().enumerate() { - proxies.raw_set(idx, elem.to_lua_proxy(lua)?)?; - } - - proxies.into_lua(lua) - } -} diff --git a/crates/bevy_script_api/src/lua/util.rs b/crates/bevy_script_api/src/lua/util.rs deleted file mode 100644 index 09ecadb6..00000000 --- a/crates/bevy_script_api/src/lua/util.rs +++ /dev/null @@ -1,300 +0,0 @@ -use bevy_mod_scripting_lua::{ - prelude::{FromLua, IntoLua, Lua, LuaError, LuaValue}, - tealr::{self, ToTypename}, -}; -use std::{ - marker::PhantomData, - ops::{Deref, DerefMut}, -}; - -/// 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 ToTypename for LuaIndex { - fn to_typename() -> tealr::Type { - ::to_typename() - } -} - -impl Deref for LuaIndex { - type Target = usize; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for LuaIndex { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl IntoLua<'_> for LuaIndex { - fn into_lua(self, lua: &Lua) -> Result { - to_lua_idx(self.0).into_lua(lua) - } -} - -impl FromLua<'_> for LuaIndex { - fn from_lua(value: LuaValue, lua: &Lua) -> Result { - Ok(LuaIndex(to_host_idx(usize::from_lua(value, lua)?))) - } -} - -/// Converts lua index to host index (Lua is 1 based, host is 0 based) -pub fn to_host_idx(lua_idx: usize) -> usize { - lua_idx - 1 -} - -/// Converts host index to lua index (Lua is 1 based, host is 0 based) -pub fn to_lua_idx(host_idx: usize) -> usize { - host_idx + 1 -} - -/// forwards the TypeName implementation of T, useful for internal 'fake' global instances -pub struct DummyTypeName { - _ph: PhantomData, -} - -impl DummyTypeName { - pub fn new( - _: &bevy_mod_scripting_lua::tealr::mlu::mlua::Lua, - ) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result { - Ok(Self { - _ph: PhantomData::, - }) - } -} - -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< - bevy_mod_scripting_lua::tealr::mlu::mlua::Value<'lua>, - > { - Ok(bevy_mod_scripting_lua::tealr::mlu::mlua::Value::Nil) - } -} - -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::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) - } - } - - impl bevy_mod_scripting_lua::tealr::mlu::mlua::UserData for $v { - fn add_fields<'lua, F: bevy_mod_scripting_lua::tealr::mlu::mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) { - let mut wrapper = ::bevy_mod_scripting_lua::tealr::mlu::UserDataWrapper::from_user_data_fields(fields); - ::add_fields(&mut wrapper) - } - - fn add_methods<'lua, M: bevy_mod_scripting_lua::tealr::mlu::mlua::prelude::LuaUserDataMethods<'lua, Self>>( - methods: &mut M, - ) { - let mut x = ::bevy_mod_scripting_lua::tealr::mlu::UserDataWrapper::from_user_data_methods(methods); - ::add_methods(&mut x); - } - } - - impl bevy_mod_scripting_lua::tealr::TypeBody for $v { - fn get_type_body() -> bevy_mod_scripting_lua::tealr::TypeGenerator { - let mut gen = ::bevy_mod_scripting_lua::tealr::RecordGenerator::new::(false); - gen.is_user_data = true; - ::add_fields(&mut gen); - ::add_methods(&mut gen); - <_ as ::std::convert::From<_>>::from(gen) - } - } - }; -} - -/// like create_bevy_mod_scripting_lua::tealr_union but translates to `any` in the lua declaration file, -/// a fill in to allow multiple userdata types -#[macro_export] -macro_rules! impl_tealr_any_union { - ($visibility:vis $(Derives($($derives:ident), +))? enum $type_name:ident = $($sub_types_ident:ident: $sub_types_type:ty) | +) => { - #[derive($($($derives ,)*)*)] - #[allow(non_camel_case_types)] - $visibility enum $type_name { - $($sub_types_ident($sub_types_type) ,)* - } - 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_ident(x) => x.into_lua(lua),)* - } - } - } - impl<'lua> ::bevy_mod_scripting_lua::tealr::mlu::mlua::FromLua<'lua> for $type_name { - fn from_lua(value: ::bevy_mod_scripting_lua::tealr::mlu::mlua::Value<'lua>, lua: &'lua ::bevy_mod_scripting_lua::tealr::mlu::mlua::Lua) -> ::std::result::Result { - $(match $sub_types_ident::from_lua(value.clone(),lua) { - Ok(x) => return Ok($type_name::$sub_types_ident(x)), - Err(::bevy_mod_scripting_lua::tealr::mlu::mlua::Error::FromLuaConversionError{from:_,to:_,message:_}) => {} - Err(x) => return Err(x) - };)* - Err(::bevy_mod_scripting_lua::tealr::mlu::mlua::Error::FromLuaConversionError{ - to: stringify!( $($sub_types_ident)|* ), - from: value.type_name(), - message: None - }) - } - } - 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) - } - } - }; -} - -#[macro_export] -macro_rules! impl_tealr_generic{ - { - $vis:vis struct $name:ident - } => { - #[derive(Default,Clone,Debug)] - $vis struct $name; - - impl $crate::lua::ValueLuaType for $name {} - - impl ::bevy_mod_scripting_lua::tealr::mlu::TealData for $name { - - } - - impl ::bevy::reflect::TypePath for $name { - fn short_type_path() -> &'static str{ - panic!("This should never be called, I am a dummy implementation") - } - - fn type_path() -> &'static str{ - panic!("This should never be called, I am a dummy implementation") - } - } - - impl ::bevy::reflect::Reflect for $name { - - fn into_any(self: Box) -> Box { - panic!("This should never be called, I am a dummy implementation"); - } - - fn as_any(&self) -> &dyn std::any::Any { - panic!("This should never be called, I am a dummy implementation"); - } - - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - panic!("This should never be called, I am a dummy implementation"); - } - - fn as_reflect(&self) -> &dyn ::bevy::reflect::Reflect { - panic!("This should never be called, I am a dummy implementation"); - } - - fn as_reflect_mut(&mut self) -> &mut dyn ::bevy::reflect::Reflect { - panic!("This should never be called, I am a dummy implementation"); - } - - fn apply(&mut self, _: &dyn ::bevy::reflect::Reflect) { - panic!("This should never be called, I am a dummy implementation"); - } - - fn set(&mut self, _: Box) -> Result<(), Box> { - panic!("This should never be called, I am a dummy implementation"); - } - - fn reflect_ref(&self) -> bevy::reflect::ReflectRef { - panic!("This should never be called, I am a dummy implementation"); - } - - fn reflect_mut(&mut self) -> bevy::reflect::ReflectMut { - panic!("This should never be called, I am a dummy implementation"); - } - - fn clone_value(&self) -> Box { - panic!("This should never be called, I am a dummy implementation"); - } - - fn into_reflect(self: Box) -> Box { - panic!("This should never be called, I am a dummy implementation"); - } - - fn reflect_owned(self: Box) -> ::bevy::reflect::ReflectOwned { - panic!("This should never be called, I am a dummy implementation"); - } - - fn get_represented_type_info(&self) -> std::option::Option<&'static bevy::reflect::TypeInfo> { - panic!("This should never be called, I am a dummy implementation"); - } - } - - impl ::bevy::reflect::FromReflect for $name { - fn from_reflect(_: &(dyn bevy::prelude::Reflect + 'static)) -> std::option::Option { - panic!("This should never be called, I am a dummy implementation"); - } - } - - $crate::impl_tealr_type!($name); - $crate::impl_from_lua_with_clone!($name); - } -} - -// /// Implements UserData for type which implements TealData, can handle generics after the type name: -// /// ```rust,ignore -// /// impl_user_data!(MyType<'a,T : Debug>); -// /// ``` -// macro_rules! impl_user_data { -// ($v:ident $(< $( $lt:tt $( : $clt:tt $(+ $dlt:tt $(<'a>)? )* )? ),+ >)? ) => { -// impl $(< $( $lt $( : $clt $(+ $dlt $(<'a>)?)* )? ),+ >)? ::bevy_mod_scripting_lua::tealr::mlu::mlua::UserData for $v $(< $( $lt ),+ >)? { -// fn add_methods<'lua, M: ::bevy_mod_scripting_lua::tealr::mlu::mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { -// let mut x = ::bevy_mod_scripting_lua::tealr::mlu::UserDataWrapper::from_user_data_methods(methods); -// ::add_methods(&mut x); -// } -// fn add_fields<'lua, F: ::bevy_mod_scripting_lua::tealr::mlu::mlua::UserDataFields<'lua, Self>>(fields: &mut F) { -// let mut wrapper = ::bevy_mod_scripting_lua::tealr::mlu::UserDataWrapper::from_user_data_fields(fields); -// ::add_fields(&mut wrapper) -// } -// } - -// } -// } - -// pub(crate) use impl_user_data; diff --git a/crates/bevy_script_api/src/providers/bevy_core.rs b/crates/bevy_script_api/src/providers/bevy_core.rs deleted file mode 100644 index 2b74a658..00000000 --- a/crates/bevy_script_api/src/providers/bevy_core.rs +++ /dev/null @@ -1,95 +0,0 @@ -// @generated by cargo bevy-api-gen generate, modify the templates not this file -#![allow(clippy::all)] -#![allow(unused, deprecated, dead_code)] -#![cfg_attr(rustfmt, rustfmt_skip)] -use super::bevy_ecs::*; -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::core::prelude::Name", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::core::prelude::Name; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &name::Name) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct Name {} -#[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<()> { - Ok(()) - } -} -pub struct BevyCoreAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyCoreAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "BevyCoreAPI", - |tw| { - tw.document_global_instance::() - .expect("Something went wrong documenting globals") - .process_type::() - }, - ), - ) - } - 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::(); - } -} diff --git a/crates/bevy_script_api/src/providers/bevy_ecs.rs b/crates/bevy_script_api/src/providers/bevy_ecs.rs deleted file mode 100644 index 4e188b17..00000000 --- a/crates/bevy_script_api/src/providers/bevy_ecs.rs +++ /dev/null @@ -1,390 +0,0 @@ -// @generated by cargo bevy-api-gen generate, modify the templates not this file -#![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#" -/// 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::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &entity::Entity) -> bool; - -"#, - 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) -} -"#] -)] -pub struct Entity {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::ecs::component::ComponentId", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - 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(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct ComponentId(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::ecs::component::Tick", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &component::Tick) -> bool; - -"#, - 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(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::component::Tick; - -"#, - 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) -} -"#] -)] -pub 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. - - #[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. - - #[lua(kind = "Method")] - fn is_changed( - &self, - #[proxy] - last_run: bevy::ecs::component::Tick, - #[proxy] - this_run: bevy::ecs::component::Tick, - ) -> bool; - -"#, - r#" -/// Returns the tick recording the time this component or resource was most recently changed. - - #[lua(kind = "Method", output(proxy))] - fn last_changed_tick(&self) -> bevy::ecs::component::Tick; - -"#, - r#" -/// Returns the tick recording the time this component or resource was added. - - #[lua(kind = "Method", output(proxy))] - fn added_tick(&self) -> bevy::ecs::component::Tick; - -"#, - r#" -/// Manually sets the change tick. -/// This is normally done automatically via the [`DerefMut`](std::ops::DerefMut) implementation -/// on [`Mut`](crate::change_detection::Mut), [`ResMut`](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) -} -"#] -)] -pub struct ComponentTicks {} -#[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; - -"#] -)] -pub struct EntityHash {} -#[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::::new, - )?; - instances - .add_instance( - "ComponentId", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Tick", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - Ok(()) - } -} -pub struct BevyEcsAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyEcsAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "BevyEcsAPI", - |tw| { - tw.document_global_instance::() - .expect("Something went wrong documenting globals") - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaComponentId, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::() - }, - ), - ) - } - 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::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - } -} diff --git a/crates/bevy_script_api/src/providers/bevy_hierarchy.rs b/crates/bevy_script_api/src/providers/bevy_hierarchy.rs deleted file mode 100644 index ad20f27d..00000000 --- a/crates/bevy_script_api/src/providers/bevy_hierarchy.rs +++ /dev/null @@ -1,124 +0,0 @@ -// @generated by cargo bevy-api-gen generate, modify the templates not this file -#![allow(clippy::all)] -#![allow(unused, deprecated, dead_code)] -#![cfg_attr(rustfmt, rustfmt_skip)] -use super::bevy_ecs::*; -use super::bevy_reflect::*; -use super::bevy_core::*; -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(), - remote = "bevy::hierarchy::prelude::Children", - functions[r#" -/// Swaps the child at `a_index` with the child at `b_index`. - - #[lua(kind = "MutatingMethod")] - fn swap(&mut self, a_index: usize, b_index: usize) -> (); - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Children(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(), - remote = "bevy::hierarchy::prelude::Parent", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &components::parent::Parent) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Gets the [`Entity`] ID of the parent. - - #[lua(kind = "Method", output(proxy))] - fn get(&self) -> bevy::ecs::entity::Entity; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Parent(); -#[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<()> { - Ok(()) - } -} -pub struct BevyHierarchyAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyHierarchyAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "BevyHierarchyAPI", - |tw| { - tw.document_global_instance::() - .expect("Something went wrong documenting globals") - .process_type::() - .process_type::() - }, - ), - ) - } - 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::(); - app.register_foreign_lua_type::(); - } -} diff --git a/crates/bevy_script_api/src/providers/bevy_input.rs b/crates/bevy_script_api/src/providers/bevy_input.rs deleted file mode 100644 index 30c24657..00000000 --- a/crates/bevy_script_api/src/providers/bevy_input.rs +++ /dev/null @@ -1,1545 +0,0 @@ -// @generated by cargo bevy-api-gen generate, modify the templates not this file -#![allow(clippy::all)] -#![allow(unused, deprecated, dead_code)] -#![cfg_attr(rustfmt, rustfmt_skip)] -use super::bevy_ecs::*; -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::input::gamepad::Gamepad", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a new [`Gamepad`]. - - #[lua(kind = "Function", output(proxy))] - fn new(id: usize) -> bevy::input::gamepad::Gamepad; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::Gamepad; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::Gamepad) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Gamepad { - id: usize, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadAxis", - functions[r#" -/// Creates a new [`GamepadAxis`]. -/// # Examples -/// ``` -/// # use bevy_input::gamepad::{GamepadAxis, GamepadAxisType, Gamepad}; -/// # -/// let gamepad_axis = GamepadAxis::new( -/// Gamepad::new(1), -/// GamepadAxisType::LeftStickX, -/// ); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::input::gamepad::Gamepad, - #[proxy] - axis_type: bevy::input::gamepad::GamepadAxisType, - ) -> bevy::input::gamepad::GamepadAxis; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadAxis) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadAxis; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadAxis { - #[lua(output(proxy))] - gamepad: bevy::input::gamepad::Gamepad, - #[lua(output(proxy))] - axis_type: bevy::input::gamepad::GamepadAxisType, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadAxisType", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadAxisType) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadAxisType; - -"#, - 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) -} -"#] -)] -pub struct GamepadAxisType {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadButton", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadButton) -> bool; - -"#, - r#" -/// Creates a new [`GamepadButton`]. -/// # Examples -/// ``` -/// # use bevy_input::gamepad::{GamepadButton, GamepadButtonType, Gamepad}; -/// # -/// let gamepad_button = GamepadButton::new( -/// Gamepad::new(1), -/// GamepadButtonType::South, -/// ); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::input::gamepad::Gamepad, - #[proxy] - button_type: bevy::input::gamepad::GamepadButtonType, - ) -> bevy::input::gamepad::GamepadButton; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadButton; - -"#, - 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) -} -"#] -)] -pub struct GamepadButton { - #[lua(output(proxy))] - gamepad: bevy::input::gamepad::Gamepad, - #[lua(output(proxy))] - button_type: bevy::input::gamepad::GamepadButtonType, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadButtonType", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadButtonType) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadButtonType; - -"#, - 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) -} -"#] -)] -pub struct GamepadButtonType {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::keyboard::KeyCode", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::KeyCode; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &keyboard::KeyCode) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct KeyCode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::mouse::MouseButton", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseButton; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &mouse::MouseButton) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct MouseButton {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::touch::TouchInput", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &touch::TouchInput) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touch::TouchInput; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct TouchInput { - #[lua(output(proxy))] - phase: bevy::input::touch::TouchPhase, - #[lua(output(proxy))] - position: bevy::math::Vec2, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - force: ReflectedValue, - id: u64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::keyboard::Key", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &keyboard::Key) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::Key; - -"#, - 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) -} -"#] -)] -pub struct Key {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::keyboard::KeyboardInput", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::KeyboardInput; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &keyboard::KeyboardInput) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct KeyboardInput { - #[lua(output(proxy))] - key_code: bevy::input::keyboard::KeyCode, - #[lua(output(proxy))] - logical_key: bevy::input::keyboard::Key, - #[lua(output(proxy))] - state: bevy::input::ButtonState, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::keyboard::NativeKey", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::NativeKey; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &keyboard::NativeKey) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct NativeKey {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::keyboard::NativeKeyCode", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::NativeKeyCode; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &keyboard::NativeKeyCode) -> 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) -} -"#] -)] -pub struct NativeKeyCode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::mouse::MouseButtonInput", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &mouse::MouseButtonInput) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseButtonInput; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct MouseButtonInput { - #[lua(output(proxy))] - button: bevy::input::mouse::MouseButton, - #[lua(output(proxy))] - state: bevy::input::ButtonState, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::mouse::MouseMotion", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseMotion; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &mouse::MouseMotion) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct MouseMotion { - #[lua(output(proxy))] - delta: bevy::math::Vec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::mouse::MouseScrollUnit", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &mouse::MouseScrollUnit) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseScrollUnit; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct MouseScrollUnit {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::mouse::MouseWheel", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &mouse::MouseWheel) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseWheel; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct MouseWheel { - #[lua(output(proxy))] - unit: bevy::input::mouse::MouseScrollUnit, - x: f32, - y: f32, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::touch::ForceTouch", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &touch::ForceTouch) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touch::ForceTouch; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct ForceTouch {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::touch::TouchPhase", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &touch::TouchPhase) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touch::TouchPhase; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct TouchPhase {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::touchpad::TouchpadMagnify", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touchpad::TouchpadMagnify; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &touchpad::TouchpadMagnify) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct TouchpadMagnify(f32); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::touchpad::TouchpadRotate", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &touchpad::TouchpadRotate) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touchpad::TouchpadRotate; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct TouchpadRotate(f32); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::AxisSettings", - functions[r#" -/// Get the value above which inputs will be rounded up to 1.0. - - #[lua(kind = "Method")] - fn livezone_upperbound(&self) -> f32; - -"#, - r#" -/// Try to set the value above which inputs will be rounded up to 1.0. -/// If the value passed is negative or less than `deadzone_upperbound`, -/// the value will not be changed. -/// Returns the new value of `livezone_upperbound`. - - #[lua(kind = "MutatingMethod")] - fn set_livezone_upperbound(&mut self, value: f32) -> f32; - -"#, - r#" -/// Get the value below which positive inputs will be rounded down to 0.0. - - #[lua(kind = "Method")] - fn deadzone_upperbound(&self) -> f32; - -"#, - r#" -/// Try to set the value below which positive inputs will be rounded down to 0.0. -/// If the value passed is negative or greater than `livezone_upperbound`, -/// the value will not be changed. -/// Returns the new value of `deadzone_upperbound`. - - #[lua(kind = "MutatingMethod")] - fn set_deadzone_upperbound(&mut self, value: f32) -> f32; - -"#, - r#" -/// Get the value below which negative inputs will be rounded down to -1.0. - - #[lua(kind = "Method")] - fn livezone_lowerbound(&self) -> f32; - -"#, - r#" -/// Try to set the value below which negative inputs will be rounded down to -1.0. -/// If the value passed is positive or greater than `deadzone_lowerbound`, -/// the value will not be changed. -/// Returns the new value of `livezone_lowerbound`. - - #[lua(kind = "MutatingMethod")] - fn set_livezone_lowerbound(&mut self, value: f32) -> f32; - -"#, - r#" -/// Get the value above which inputs will be rounded up to 0.0. - - #[lua(kind = "Method")] - fn deadzone_lowerbound(&self) -> f32; - -"#, - r#" -/// Try to set the value above which inputs will be rounded up to 0.0. -/// If the value passed is less than -1.0 or less than `livezone_lowerbound`, -/// the value will not be changed. -/// Returns the new value of `deadzone_lowerbound`. - - #[lua(kind = "MutatingMethod")] - fn set_deadzone_lowerbound(&mut self, value: f32) -> f32; - -"#, - r#" -/// Get the minimum value by which input must change before the change is registered. - - #[lua(kind = "Method")] - fn threshold(&self) -> f32; - -"#, - r#" -/// Try to set the minimum value by which input must change before the changes will be applied. -/// If the value passed is not within [0.0..=2.0], the value will not be changed. -/// Returns the new value of threshold. - - #[lua(kind = "MutatingMethod")] - fn set_threshold(&mut self, value: f32) -> f32; - -"#, - r#" -/// Clamps the `raw_value` according to the `AxisSettings`. - - #[lua(kind = "Method")] - fn clamp(&self, new_value: f32) -> f32; - -"#, - r#" -/// Filters the `new_value` based on the `old_value`, according to the [`AxisSettings`]. -/// Returns the clamped `new_value` if the change exceeds the settings threshold, -/// and `None` otherwise. - - #[lua(kind = "Method")] - fn filter( - &self, - new_value: f32, - old_value: std::option::Option, - ) -> std::option::Option; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::AxisSettings; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::AxisSettings) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct AxisSettings {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::ButtonAxisSettings", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::ButtonAxisSettings; - -"#, - r#" -/// Filters the `new_value` based on the `old_value`, according to the [`ButtonAxisSettings`]. -/// Returns the clamped `new_value`, according to the [`ButtonAxisSettings`], if the change -/// exceeds the settings threshold, and `None` otherwise. - - #[lua(kind = "Method")] - fn filter( - &self, - new_value: f32, - old_value: std::option::Option, - ) -> std::option::Option; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct ButtonAxisSettings { - high: f32, - low: f32, - threshold: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::ButtonSettings", - functions[r#" -/// Returns `true` if the button is pressed. -/// A button is considered pressed if the `value` passed is greater than or equal to the press threshold. - - #[lua(kind = "Method")] - fn is_pressed(&self, value: f32) -> bool; - -"#, - r#" -/// Returns `true` if the button is released. -/// A button is considered released if the `value` passed is lower than or equal to the release threshold. - - #[lua(kind = "Method")] - fn is_released(&self, value: f32) -> bool; - -"#, - r#" -/// Get the button input threshold above which the button is considered pressed. - - #[lua(kind = "Method")] - fn press_threshold(&self) -> f32; - -"#, - r#" -/// Try to set the button input threshold above which the button is considered pressed. -/// If the value passed is outside the range [release threshold..=1.0], the value will not be changed. -/// Returns the new value of the press threshold. - - #[lua(kind = "MutatingMethod")] - fn set_press_threshold(&mut self, value: f32) -> f32; - -"#, - r#" -/// Get the button input threshold below which the button is considered released. - - #[lua(kind = "Method")] - fn release_threshold(&self) -> f32; - -"#, - r#" -/// Try to set the button input threshold below which the button is considered released. If the -/// value passed is outside the range [0.0..=press threshold], the value will not be changed. -/// Returns the new value of the release threshold. - - #[lua(kind = "MutatingMethod")] - fn set_release_threshold(&mut self, value: f32) -> f32; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::ButtonSettings; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct ButtonSettings {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadAxisChangedEvent", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadAxisChangedEvent; - -"#, - r#" -/// Creates a [`GamepadAxisChangedEvent`]. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::input::gamepad::Gamepad, - #[proxy] - axis_type: bevy::input::gamepad::GamepadAxisType, - value: f32, - ) -> bevy::input::gamepad::GamepadAxisChangedEvent; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadAxisChangedEvent) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadAxisChangedEvent { - #[lua(output(proxy))] - gamepad: bevy::input::gamepad::Gamepad, - #[lua(output(proxy))] - axis_type: bevy::input::gamepad::GamepadAxisType, - value: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadButtonChangedEvent", - functions[r#" -/// Creates a [`GamepadButtonChangedEvent`]. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::input::gamepad::Gamepad, - #[proxy] - button_type: bevy::input::gamepad::GamepadButtonType, - value: f32, - ) -> bevy::input::gamepad::GamepadButtonChangedEvent; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadButtonChangedEvent) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadButtonChangedEvent; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadButtonChangedEvent { - #[lua(output(proxy))] - gamepad: bevy::input::gamepad::Gamepad, - #[lua(output(proxy))] - button_type: bevy::input::gamepad::GamepadButtonType, - value: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadButtonInput", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadButtonInput; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadButtonInput) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadButtonInput { - #[lua(output(proxy))] - button: bevy::input::gamepad::GamepadButton, - #[lua(output(proxy))] - state: bevy::input::ButtonState, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadConnection", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadConnection; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadConnection) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadConnection {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadConnectionEvent", - functions[r#" -/// Creates a [`GamepadConnectionEvent`]. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::input::gamepad::Gamepad, - #[proxy] - connection: bevy::input::gamepad::GamepadConnection, - ) -> bevy::input::gamepad::GamepadConnectionEvent; - -"#, - r#" -/// Is the gamepad connected? - - #[lua(kind = "Method")] - fn connected(&self) -> bool; - -"#, - r#" -/// Is the gamepad disconnected? - - #[lua(kind = "Method")] - fn disconnected(&self) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadConnectionEvent; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadConnectionEvent) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadConnectionEvent { - #[lua(output(proxy))] - gamepad: bevy::input::gamepad::Gamepad, - #[lua(output(proxy))] - connection: bevy::input::gamepad::GamepadConnection, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadEvent", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadEvent; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadEvent) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadEvent {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(), - remote = "bevy::input::gamepad::GamepadSettings", - functions[r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadSettings { - #[lua(output(proxy))] - default_button_settings: bevy::input::gamepad::ButtonSettings, - #[lua(output(proxy))] - default_axis_settings: bevy::input::gamepad::AxisSettings, - #[lua(output(proxy))] - default_button_axis_settings: bevy::input::gamepad::ButtonAxisSettings, - button_settings: ReflectedValue, - axis_settings: ReflectedValue, - button_axis_settings: ReflectedValue, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::ButtonState", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &ButtonState) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::ButtonState; - -"#, - r#" -/// Is this button pressed? - - #[lua(kind = "Method")] - fn is_pressed(&self) -> 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) -} -"#] -)] -pub struct ButtonState {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::input::gamepad::GamepadInfo", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadInfo; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &gamepad::GamepadInfo) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GamepadInfo { - name: std::string::String, -} -#[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( - "Gamepad", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "GamepadAxis", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "GamepadButton", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadButton, - >::new, - )?; - instances - .add_instance( - "GamepadAxisChangedEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadAxisChangedEvent, - >::new, - )?; - instances - .add_instance( - "GamepadButtonChangedEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadButtonChangedEvent, - >::new, - )?; - instances - .add_instance( - "GamepadConnectionEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadConnectionEvent, - >::new, - )?; - Ok(()) - } -} -pub struct BevyInputAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyInputAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "BevyInputAPI", - |tw| { - tw.document_global_instance::() - .expect("Something went wrong documenting globals") - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadAxis, - >, - >() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadButton, - >, - >() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadAxisChangedEvent, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadButtonChangedEvent, - >, - >() - .process_type::() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadConnectionEvent, - >, - >() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - }, - ), - ) - } - 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::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::< - bevy::input::gamepad::GamepadButtonChangedEvent, - >(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - } -} diff --git a/crates/bevy_script_api/src/providers/bevy_reflect.rs b/crates/bevy_script_api/src/providers/bevy_reflect.rs deleted file mode 100644 index bd5f61d0..00000000 --- a/crates/bevy_script_api/src/providers/bevy_reflect.rs +++ /dev/null @@ -1,24764 +0,0 @@ -// @generated by cargo bevy-api-gen generate, modify the templates not this file -#![allow(clippy::all)] -#![allow(unused, deprecated, dead_code)] -#![cfg_attr(rustfmt, rustfmt_skip)] -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::utils::Duration", - functions[r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::utils::Duration) -> bevy::utils::Duration; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::utils::Duration; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::utils::Duration; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::utils::Duration) -> bevy::utils::Duration; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_utils::Duration) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::utils::Duration; - -"#, - r#" -/// Creates a new `Duration` from the specified number of whole seconds and -/// additional nanoseconds. -/// If the number of nanoseconds is greater than 1 billion (the number of -/// nanoseconds in a second), then it will carry over into the seconds provided. -/// # Panics -/// This constructor will panic if the carry from the nanoseconds overflows -/// the seconds counter. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let five_seconds = Duration::new(5, 0); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new(secs: u64, nanos: u32) -> bevy::utils::Duration; - -"#, - r#" -/// Creates a new `Duration` from the specified number of whole seconds. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::from_secs(5); -/// assert_eq!(5, duration.as_secs()); -/// assert_eq!(0, duration.subsec_nanos()); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_secs(secs: u64) -> bevy::utils::Duration; - -"#, - r#" -/// Creates a new `Duration` from the specified number of milliseconds. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::from_millis(2569); -/// assert_eq!(2, duration.as_secs()); -/// assert_eq!(569_000_000, duration.subsec_nanos()); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_millis(millis: u64) -> bevy::utils::Duration; - -"#, - r#" -/// Creates a new `Duration` from the specified number of microseconds. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::from_micros(1_000_002); -/// assert_eq!(1, duration.as_secs()); -/// assert_eq!(2000, duration.subsec_nanos()); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_micros(micros: u64) -> bevy::utils::Duration; - -"#, - r#" -/// Creates a new `Duration` from the specified number of nanoseconds. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::from_nanos(1_000_000_123); -/// assert_eq!(1, duration.as_secs()); -/// assert_eq!(123, duration.subsec_nanos()); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_nanos(nanos: u64) -> bevy::utils::Duration; - -"#, - r#" -/// Returns true if this `Duration` spans no time. -/// # Examples -/// ``` -/// use std::time::Duration; -/// assert!(Duration::ZERO.is_zero()); -/// assert!(Duration::new(0, 0).is_zero()); -/// assert!(Duration::from_nanos(0).is_zero()); -/// assert!(Duration::from_secs(0).is_zero()); -/// assert!(!Duration::new(1, 1).is_zero()); -/// assert!(!Duration::from_nanos(1).is_zero()); -/// assert!(!Duration::from_secs(1).is_zero()); -/// ``` - - #[lua(kind = "Method")] - fn is_zero(&self) -> bool; - -"#, - r#" -/// Returns the number of _whole_ seconds contained by this `Duration`. -/// The returned value does not include the fractional (nanosecond) part of the -/// duration, which can be obtained using [`subsec_nanos`]. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::new(5, 730023852); -/// assert_eq!(duration.as_secs(), 5); -/// ``` -/// To determine the total number of seconds represented by the `Duration` -/// including the fractional part, use [`as_secs_f64`] or [`as_secs_f32`] -/// [`as_secs_f64`]: Duration::as_secs_f64 -/// [`as_secs_f32`]: Duration::as_secs_f32 -/// [`subsec_nanos`]: Duration::subsec_nanos - - #[lua(kind = "Method")] - fn as_secs(&self) -> u64; - -"#, - r#" -/// Returns the fractional part of this `Duration`, in whole milliseconds. -/// This method does **not** return the length of the duration when -/// represented by milliseconds. The returned number always represents a -/// fractional portion of a second (i.e., it is less than one thousand). -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::from_millis(5432); -/// assert_eq!(duration.as_secs(), 5); -/// assert_eq!(duration.subsec_millis(), 432); -/// ``` - - #[lua(kind = "Method")] - fn subsec_millis(&self) -> u32; - -"#, - r#" -/// Returns the fractional part of this `Duration`, in whole microseconds. -/// This method does **not** return the length of the duration when -/// represented by microseconds. The returned number always represents a -/// fractional portion of a second (i.e., it is less than one million). -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::from_micros(1_234_567); -/// assert_eq!(duration.as_secs(), 1); -/// assert_eq!(duration.subsec_micros(), 234_567); -/// ``` - - #[lua(kind = "Method")] - fn subsec_micros(&self) -> u32; - -"#, - r#" -/// Returns the fractional part of this `Duration`, in nanoseconds. -/// This method does **not** return the length of the duration when -/// represented by nanoseconds. The returned number always represents a -/// fractional portion of a second (i.e., it is less than one billion). -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::from_millis(5010); -/// assert_eq!(duration.as_secs(), 5); -/// assert_eq!(duration.subsec_nanos(), 10_000_000); -/// ``` - - #[lua(kind = "Method")] - fn subsec_nanos(&self) -> u32; - -"#, - r#" -/// Returns the total number of whole milliseconds contained by this `Duration`. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::new(5, 730023852); -/// assert_eq!(duration.as_millis(), 5730); -/// ``` - - #[lua(kind = "Method")] - fn as_millis(&self) -> u128; - -"#, - r#" -/// Returns the total number of whole microseconds contained by this `Duration`. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::new(5, 730023852); -/// assert_eq!(duration.as_micros(), 5730023); -/// ``` - - #[lua(kind = "Method")] - fn as_micros(&self) -> u128; - -"#, - r#" -/// Returns the total number of nanoseconds contained by this `Duration`. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let duration = Duration::new(5, 730023852); -/// assert_eq!(duration.as_nanos(), 5730023852); -/// ``` - - #[lua(kind = "Method")] - fn as_nanos(&self) -> u128; - -"#, - r#" -/// Saturating `Duration` addition. Computes `self + other`, returning [`Duration::MAX`] -/// if overflow occurred. -/// # Examples -/// ``` -/// #![feature(duration_constants)] -/// use std::time::Duration; -/// assert_eq!(Duration::new(0, 0).saturating_add(Duration::new(0, 1)), Duration::new(0, 1)); -/// assert_eq!(Duration::new(1, 0).saturating_add(Duration::new(u64::MAX, 0)), Duration::MAX); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_add( - self, - #[proxy] - rhs: bevy::utils::Duration, - ) -> bevy::utils::Duration; - -"#, - r#" -/// Saturating `Duration` subtraction. Computes `self - other`, returning [`Duration::ZERO`] -/// if the result would be negative or if overflow occurred. -/// # Examples -/// ``` -/// use std::time::Duration; -/// assert_eq!(Duration::new(0, 1).saturating_sub(Duration::new(0, 0)), Duration::new(0, 1)); -/// assert_eq!(Duration::new(0, 0).saturating_sub(Duration::new(0, 1)), Duration::ZERO); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub( - self, - #[proxy] - rhs: bevy::utils::Duration, - ) -> bevy::utils::Duration; - -"#, - r#" -/// Saturating `Duration` multiplication. Computes `self * other`, returning -/// [`Duration::MAX`] if overflow occurred. -/// # Examples -/// ``` -/// #![feature(duration_constants)] -/// use std::time::Duration; -/// assert_eq!(Duration::new(0, 500_000_001).saturating_mul(2), Duration::new(1, 2)); -/// assert_eq!(Duration::new(u64::MAX - 1, 0).saturating_mul(2), Duration::MAX); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, rhs: u32) -> bevy::utils::Duration; - -"#, - r#" -/// Returns the number of seconds contained by this `Duration` as `f64`. -/// The returned value does include the fractional (nanosecond) part of the duration. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let dur = Duration::new(2, 700_000_000); -/// assert_eq!(dur.as_secs_f64(), 2.7); -/// ``` - - #[lua(kind = "Method")] - fn as_secs_f64(&self) -> f64; - -"#, - r#" -/// Returns the number of seconds contained by this `Duration` as `f32`. -/// The returned value does include the fractional (nanosecond) part of the duration. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let dur = Duration::new(2, 700_000_000); -/// assert_eq!(dur.as_secs_f32(), 2.7); -/// ``` - - #[lua(kind = "Method")] - fn as_secs_f32(&self) -> f32; - -"#, - r#" -/// Creates a new `Duration` from the specified number of seconds represented -/// as `f64`. -/// # Panics -/// This constructor will panic if `secs` is negative, overflows `Duration` or not finite. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let res = Duration::from_secs_f64(0.0); -/// assert_eq!(res, Duration::new(0, 0)); -/// let res = Duration::from_secs_f64(1e-20); -/// assert_eq!(res, Duration::new(0, 0)); -/// let res = Duration::from_secs_f64(4.2e-7); -/// assert_eq!(res, Duration::new(0, 420)); -/// let res = Duration::from_secs_f64(2.7); -/// assert_eq!(res, Duration::new(2, 700_000_000)); -/// let res = Duration::from_secs_f64(3e10); -/// assert_eq!(res, Duration::new(30_000_000_000, 0)); -/// // subnormal float -/// let res = Duration::from_secs_f64(f64::from_bits(1)); -/// assert_eq!(res, Duration::new(0, 0)); -/// // conversion uses rounding -/// let res = Duration::from_secs_f64(0.999e-9); -/// assert_eq!(res, Duration::new(0, 1)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_secs_f64(secs: f64) -> bevy::utils::Duration; - -"#, - r#" -/// Creates a new `Duration` from the specified number of seconds represented -/// as `f32`. -/// # Panics -/// This constructor will panic if `secs` is negative, overflows `Duration` or not finite. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let res = Duration::from_secs_f32(0.0); -/// assert_eq!(res, Duration::new(0, 0)); -/// let res = Duration::from_secs_f32(1e-20); -/// assert_eq!(res, Duration::new(0, 0)); -/// let res = Duration::from_secs_f32(4.2e-7); -/// assert_eq!(res, Duration::new(0, 420)); -/// let res = Duration::from_secs_f32(2.7); -/// assert_eq!(res, Duration::new(2, 700_000_048)); -/// let res = Duration::from_secs_f32(3e10); -/// assert_eq!(res, Duration::new(30_000_001_024, 0)); -/// // subnormal float -/// let res = Duration::from_secs_f32(f32::from_bits(1)); -/// assert_eq!(res, Duration::new(0, 0)); -/// // conversion uses rounding -/// let res = Duration::from_secs_f32(0.999e-9); -/// assert_eq!(res, Duration::new(0, 1)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_secs_f32(secs: f32) -> bevy::utils::Duration; - -"#, - r#" -/// Multiplies `Duration` by `f64`. -/// # Panics -/// This method will panic if result is negative, overflows `Duration` or not finite. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let dur = Duration::new(2, 700_000_000); -/// assert_eq!(dur.mul_f64(3.14), Duration::new(8, 478_000_000)); -/// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn mul_f64(self, rhs: f64) -> bevy::utils::Duration; - -"#, - r#" -/// Multiplies `Duration` by `f32`. -/// # Panics -/// This method will panic if result is negative, overflows `Duration` or not finite. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let dur = Duration::new(2, 700_000_000); -/// assert_eq!(dur.mul_f32(3.14), Duration::new(8, 478_000_641)); -/// assert_eq!(dur.mul_f32(3.14e5), Duration::new(847800, 0)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn mul_f32(self, rhs: f32) -> bevy::utils::Duration; - -"#, - r#" -/// Divide `Duration` by `f64`. -/// # Panics -/// This method will panic if result is negative, overflows `Duration` or not finite. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let dur = Duration::new(2, 700_000_000); -/// assert_eq!(dur.div_f64(3.14), Duration::new(0, 859_872_611)); -/// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_599)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn div_f64(self, rhs: f64) -> bevy::utils::Duration; - -"#, - r#" -/// Divide `Duration` by `f32`. -/// # Panics -/// This method will panic if result is negative, overflows `Duration` or not finite. -/// # Examples -/// ``` -/// use std::time::Duration; -/// let dur = Duration::new(2, 700_000_000); -/// // note that due to rounding errors result is slightly -/// // different from 0.859_872_611 -/// assert_eq!(dur.div_f32(3.14), Duration::new(0, 859_872_580)); -/// assert_eq!(dur.div_f32(3.14e5), Duration::new(0, 8_599)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn div_f32(self, rhs: f32) -> bevy::utils::Duration; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Duration {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::utils::Instant", - functions[r#" -/// # Panics -/// This function may panic if the resulting point in time cannot be represented by the -/// underlying data structure. See [`Instant::checked_add`] for a version without panic. - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Instant; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_utils::Instant) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Instant; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::utils::Instant; - -"#, - r#" -/// Returns an instant corresponding to "now". -/// # Examples -/// ``` -/// use std::time::Instant; -/// let now = Instant::now(); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn now() -> bevy::utils::Instant; - -"#, - r#" -/// Returns the amount of time elapsed from another instant to this one, -/// or zero duration if that instant is later than this one. -/// # Panics -/// Previous rust versions panicked when `earlier` was later than `self`. Currently this -/// method saturates. Future versions may reintroduce the panic in some circumstances. -/// See [Monotonicity]. -/// [Monotonicity]: Instant#monotonicity -/// # Examples -/// ```no_run -/// use std::time::{Duration, Instant}; -/// use std::thread::sleep; -/// let now = Instant::now(); -/// sleep(Duration::new(1, 0)); -/// let new_now = Instant::now(); -/// println!("{:?}", new_now.duration_since(now)); -/// println!("{:?}", now.duration_since(new_now)); // 0ns -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn duration_since( - &self, - #[proxy] - earlier: bevy::utils::Instant, - ) -> bevy::utils::Duration; - -"#, - r#" -/// Returns the amount of time elapsed from another instant to this one, -/// or zero duration if that instant is later than this one. -/// # Examples -/// ```no_run -/// use std::time::{Duration, Instant}; -/// use std::thread::sleep; -/// let now = Instant::now(); -/// sleep(Duration::new(1, 0)); -/// let new_now = Instant::now(); -/// println!("{:?}", new_now.saturating_duration_since(now)); -/// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_duration_since( - &self, - #[proxy] - earlier: bevy::utils::Instant, - ) -> bevy::utils::Duration; - -"#, - r#" -/// Returns the amount of time elapsed since this instant. -/// # Panics -/// Previous rust versions panicked when the current time was earlier than self. Currently this -/// method returns a Duration of zero in that case. Future versions may reintroduce the panic. -/// See [Monotonicity]. -/// [Monotonicity]: Instant#monotonicity -/// # Examples -/// ```no_run -/// use std::thread::sleep; -/// use std::time::{Duration, Instant}; -/// let instant = Instant::now(); -/// let three_secs = Duration::from_secs(3); -/// sleep(three_secs); -/// assert!(instant.elapsed() >= three_secs); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn elapsed(&self) -> bevy::utils::Duration; - -"#, - r#" -/// Returns the amount of time elapsed from another instant to this one, -/// or zero duration if that instant is later than this one. -/// # Panics -/// Previous rust versions panicked when `other` was later than `self`. Currently this -/// method saturates. Future versions may reintroduce the panic in some circumstances. -/// See [Monotonicity]. -/// [Monotonicity]: Instant#monotonicity - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] other: bevy::utils::Instant) -> bevy::utils::Duration; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Instant(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroI128", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroI128; - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: i128) -> std::num::NonZeroI128; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> i128; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI128::new(-1i128).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI128::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Computes the absolute value of self. -///See [`i128::abs`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI128::new(1)?; -///let neg = NonZeroI128::new(-1)?; -/// assert_eq!(pos, pos.abs()); -/// assert_eq!(pos, neg.abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> std::num::NonZeroI128; - -"#, - r#" -/// Saturating absolute value, see -///[`i128::saturating_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI128::new(1)?; -///let neg = NonZeroI128::new(-1)?; -///let min = NonZeroI128::new(i128::MIN)?; -///let min_plus = NonZeroI128::new(i128::MIN + 1)?; -///let max = NonZeroI128::new(i128::MAX)?; -/// assert_eq!(pos, pos.saturating_abs()); -/// assert_eq!(pos, neg.saturating_abs()); -/// assert_eq!(max, min.saturating_abs()); -/// assert_eq!(max, min_plus.saturating_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_abs(self) -> std::num::NonZeroI128; - -"#, - r#" -/// Wrapping absolute value, see -///[`i128::wrapping_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI128::new(1)?; -///let neg = NonZeroI128::new(-1)?; -///let min = NonZeroI128::new(i128::MIN)?; -///# let max = NonZeroI128::new(i128::MAX)?; -/// assert_eq!(pos, pos.wrapping_abs()); -/// assert_eq!(pos, neg.wrapping_abs()); -/// assert_eq!(min, min.wrapping_abs()); -/// assert_eq!(max, (-max).wrapping_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_abs(self) -> std::num::NonZeroI128; - -"#, - r#" -/// Computes the absolute value of self -/// without any wrapping or panicking. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -///# use std::num::NonZeroU128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let u_pos = NonZeroU128::new(1)?; -///let i_pos = NonZeroI128::new(1)?; -///let i_neg = NonZeroI128::new(-1)?; -///let i_min = NonZeroI128::new(i128::MIN)?; -///let u_max = NonZeroU128::new(u128::MAX / 2 + 1)?; -/// assert_eq!(u_pos, i_pos.unsigned_abs()); -/// assert_eq!(u_pos, i_neg.unsigned_abs()); -/// assert_eq!(u_max, i_min.unsigned_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn unsigned_abs(self) -> std::num::NonZeroU128; - -"#, - r#" -/// Returns `true` if `self` is positive and `false` if the -/// number is negative. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI128::new(5)?; -///let neg_five = NonZeroI128::new(-5)?; -/// assert!(pos_five.is_positive()); -/// assert!(!neg_five.is_positive()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_positive(self) -> bool; - -"#, - r#" -/// Returns `true` if `self` is negative and `false` if the -/// number is positive. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI128::new(5)?; -///let neg_five = NonZeroI128::new(-5)?; -/// assert!(neg_five.is_negative()); -/// assert!(!pos_five.is_negative()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_negative(self) -> bool; - -"#, - r#" -/// Saturating negation. Computes `-self`, -///returning [`NonZeroI128::MAX`] -///if `self == NonZeroI128::MIN` -/// instead of overflowing. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI128::new(5)?; -///let neg_five = NonZeroI128::new(-5)?; -///let min = NonZeroI128::new(i128::MIN)?; -///let min_plus_one = NonZeroI128::new(i128::MIN + 1)?; -///let max = NonZeroI128::new(i128::MAX)?; -/// assert_eq!(pos_five.saturating_neg(), neg_five); -/// assert_eq!(min.saturating_neg(), max); -/// assert_eq!(max.saturating_neg(), min_plus_one); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_neg(self) -> std::num::NonZeroI128; - -"#, - r#" -/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary -/// of the type. -///See [`i128::wrapping_neg`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI128::new(5)?; -///let neg_five = NonZeroI128::new(-5)?; -///let min = NonZeroI128::new(i128::MIN)?; -/// assert_eq!(pos_five.wrapping_neg(), neg_five); -/// assert_eq!(min.wrapping_neg(), min); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_neg(self) -> std::num::NonZeroI128; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroI128::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroI128::new(2)?; -///let four = NonZeroI128::new(4)?; -///let max = NonZeroI128::new(i128::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroI128, - ) -> std::num::NonZeroI128; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroI128::MIN`] or [`NonZeroI128::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroI128::new(3)?; -///let twenty_seven = NonZeroI128::new(27)?; -///let max = NonZeroI128::new(i128::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroI128; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroI128) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> std::num::NonZeroI128; - -"#, - 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) -} -"#] -)] -pub struct NonZeroI128(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroI16", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroI16) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroI16; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: i16) -> std::num::NonZeroI16; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> i16; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI16::new(-1i16).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI16::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Computes the absolute value of self. -///See [`i16::abs`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI16::new(1)?; -///let neg = NonZeroI16::new(-1)?; -/// assert_eq!(pos, pos.abs()); -/// assert_eq!(pos, neg.abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> std::num::NonZeroI16; - -"#, - r#" -/// Saturating absolute value, see -///[`i16::saturating_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI16::new(1)?; -///let neg = NonZeroI16::new(-1)?; -///let min = NonZeroI16::new(i16::MIN)?; -///let min_plus = NonZeroI16::new(i16::MIN + 1)?; -///let max = NonZeroI16::new(i16::MAX)?; -/// assert_eq!(pos, pos.saturating_abs()); -/// assert_eq!(pos, neg.saturating_abs()); -/// assert_eq!(max, min.saturating_abs()); -/// assert_eq!(max, min_plus.saturating_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_abs(self) -> std::num::NonZeroI16; - -"#, - r#" -/// Wrapping absolute value, see -///[`i16::wrapping_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI16::new(1)?; -///let neg = NonZeroI16::new(-1)?; -///let min = NonZeroI16::new(i16::MIN)?; -///# let max = NonZeroI16::new(i16::MAX)?; -/// assert_eq!(pos, pos.wrapping_abs()); -/// assert_eq!(pos, neg.wrapping_abs()); -/// assert_eq!(min, min.wrapping_abs()); -/// assert_eq!(max, (-max).wrapping_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_abs(self) -> std::num::NonZeroI16; - -"#, - r#" -/// Computes the absolute value of self -/// without any wrapping or panicking. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -///# use std::num::NonZeroU16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let u_pos = NonZeroU16::new(1)?; -///let i_pos = NonZeroI16::new(1)?; -///let i_neg = NonZeroI16::new(-1)?; -///let i_min = NonZeroI16::new(i16::MIN)?; -///let u_max = NonZeroU16::new(u16::MAX / 2 + 1)?; -/// assert_eq!(u_pos, i_pos.unsigned_abs()); -/// assert_eq!(u_pos, i_neg.unsigned_abs()); -/// assert_eq!(u_max, i_min.unsigned_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn unsigned_abs(self) -> std::num::NonZeroU16; - -"#, - r#" -/// Returns `true` if `self` is positive and `false` if the -/// number is negative. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI16::new(5)?; -///let neg_five = NonZeroI16::new(-5)?; -/// assert!(pos_five.is_positive()); -/// assert!(!neg_five.is_positive()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_positive(self) -> bool; - -"#, - r#" -/// Returns `true` if `self` is negative and `false` if the -/// number is positive. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI16::new(5)?; -///let neg_five = NonZeroI16::new(-5)?; -/// assert!(neg_five.is_negative()); -/// assert!(!pos_five.is_negative()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_negative(self) -> bool; - -"#, - r#" -/// Saturating negation. Computes `-self`, -///returning [`NonZeroI16::MAX`] -///if `self == NonZeroI16::MIN` -/// instead of overflowing. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI16::new(5)?; -///let neg_five = NonZeroI16::new(-5)?; -///let min = NonZeroI16::new(i16::MIN)?; -///let min_plus_one = NonZeroI16::new(i16::MIN + 1)?; -///let max = NonZeroI16::new(i16::MAX)?; -/// assert_eq!(pos_five.saturating_neg(), neg_five); -/// assert_eq!(min.saturating_neg(), max); -/// assert_eq!(max.saturating_neg(), min_plus_one); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_neg(self) -> std::num::NonZeroI16; - -"#, - r#" -/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary -/// of the type. -///See [`i16::wrapping_neg`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI16::new(5)?; -///let neg_five = NonZeroI16::new(-5)?; -///let min = NonZeroI16::new(i16::MIN)?; -/// assert_eq!(pos_five.wrapping_neg(), neg_five); -/// assert_eq!(min.wrapping_neg(), min); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_neg(self) -> std::num::NonZeroI16; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroI16::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroI16::new(2)?; -///let four = NonZeroI16::new(4)?; -///let max = NonZeroI16::new(i16::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroI16, - ) -> std::num::NonZeroI16; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroI16::MIN`] or [`NonZeroI16::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroI16::new(3)?; -///let twenty_seven = NonZeroI16::new(27)?; -///let max = NonZeroI16::new(i16::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroI16; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> std::num::NonZeroI16; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroI16(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroI32", - functions[r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> std::num::NonZeroI32; - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: i32) -> std::num::NonZeroI32; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> i32; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI32::new(-1i32).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI32::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Computes the absolute value of self. -///See [`i32::abs`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI32::new(1)?; -///let neg = NonZeroI32::new(-1)?; -/// assert_eq!(pos, pos.abs()); -/// assert_eq!(pos, neg.abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> std::num::NonZeroI32; - -"#, - r#" -/// Saturating absolute value, see -///[`i32::saturating_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI32::new(1)?; -///let neg = NonZeroI32::new(-1)?; -///let min = NonZeroI32::new(i32::MIN)?; -///let min_plus = NonZeroI32::new(i32::MIN + 1)?; -///let max = NonZeroI32::new(i32::MAX)?; -/// assert_eq!(pos, pos.saturating_abs()); -/// assert_eq!(pos, neg.saturating_abs()); -/// assert_eq!(max, min.saturating_abs()); -/// assert_eq!(max, min_plus.saturating_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_abs(self) -> std::num::NonZeroI32; - -"#, - r#" -/// Wrapping absolute value, see -///[`i32::wrapping_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI32::new(1)?; -///let neg = NonZeroI32::new(-1)?; -///let min = NonZeroI32::new(i32::MIN)?; -///# let max = NonZeroI32::new(i32::MAX)?; -/// assert_eq!(pos, pos.wrapping_abs()); -/// assert_eq!(pos, neg.wrapping_abs()); -/// assert_eq!(min, min.wrapping_abs()); -/// assert_eq!(max, (-max).wrapping_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_abs(self) -> std::num::NonZeroI32; - -"#, - r#" -/// Computes the absolute value of self -/// without any wrapping or panicking. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -///# use std::num::NonZeroU32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let u_pos = NonZeroU32::new(1)?; -///let i_pos = NonZeroI32::new(1)?; -///let i_neg = NonZeroI32::new(-1)?; -///let i_min = NonZeroI32::new(i32::MIN)?; -///let u_max = NonZeroU32::new(u32::MAX / 2 + 1)?; -/// assert_eq!(u_pos, i_pos.unsigned_abs()); -/// assert_eq!(u_pos, i_neg.unsigned_abs()); -/// assert_eq!(u_max, i_min.unsigned_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn unsigned_abs(self) -> std::num::NonZeroU32; - -"#, - r#" -/// Returns `true` if `self` is positive and `false` if the -/// number is negative. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI32::new(5)?; -///let neg_five = NonZeroI32::new(-5)?; -/// assert!(pos_five.is_positive()); -/// assert!(!neg_five.is_positive()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_positive(self) -> bool; - -"#, - r#" -/// Returns `true` if `self` is negative and `false` if the -/// number is positive. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI32::new(5)?; -///let neg_five = NonZeroI32::new(-5)?; -/// assert!(neg_five.is_negative()); -/// assert!(!pos_five.is_negative()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_negative(self) -> bool; - -"#, - r#" -/// Saturating negation. Computes `-self`, -///returning [`NonZeroI32::MAX`] -///if `self == NonZeroI32::MIN` -/// instead of overflowing. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI32::new(5)?; -///let neg_five = NonZeroI32::new(-5)?; -///let min = NonZeroI32::new(i32::MIN)?; -///let min_plus_one = NonZeroI32::new(i32::MIN + 1)?; -///let max = NonZeroI32::new(i32::MAX)?; -/// assert_eq!(pos_five.saturating_neg(), neg_five); -/// assert_eq!(min.saturating_neg(), max); -/// assert_eq!(max.saturating_neg(), min_plus_one); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_neg(self) -> std::num::NonZeroI32; - -"#, - r#" -/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary -/// of the type. -///See [`i32::wrapping_neg`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI32::new(5)?; -///let neg_five = NonZeroI32::new(-5)?; -///let min = NonZeroI32::new(i32::MIN)?; -/// assert_eq!(pos_five.wrapping_neg(), neg_five); -/// assert_eq!(min.wrapping_neg(), min); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_neg(self) -> std::num::NonZeroI32; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroI32::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroI32::new(2)?; -///let four = NonZeroI32::new(4)?; -///let max = NonZeroI32::new(i32::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroI32, - ) -> std::num::NonZeroI32; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroI32::MIN`] or [`NonZeroI32::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroI32::new(3)?; -///let twenty_seven = NonZeroI32::new(27)?; -///let max = NonZeroI32::new(i32::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroI32; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroI32; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroI32) -> 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) -} -"#] -)] -pub struct NonZeroI32(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroI64", - functions[r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: i64) -> std::num::NonZeroI64; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> i64; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI64::new(-1i64).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI64::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Computes the absolute value of self. -///See [`i64::abs`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI64::new(1)?; -///let neg = NonZeroI64::new(-1)?; -/// assert_eq!(pos, pos.abs()); -/// assert_eq!(pos, neg.abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> std::num::NonZeroI64; - -"#, - r#" -/// Saturating absolute value, see -///[`i64::saturating_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI64::new(1)?; -///let neg = NonZeroI64::new(-1)?; -///let min = NonZeroI64::new(i64::MIN)?; -///let min_plus = NonZeroI64::new(i64::MIN + 1)?; -///let max = NonZeroI64::new(i64::MAX)?; -/// assert_eq!(pos, pos.saturating_abs()); -/// assert_eq!(pos, neg.saturating_abs()); -/// assert_eq!(max, min.saturating_abs()); -/// assert_eq!(max, min_plus.saturating_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_abs(self) -> std::num::NonZeroI64; - -"#, - r#" -/// Wrapping absolute value, see -///[`i64::wrapping_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI64::new(1)?; -///let neg = NonZeroI64::new(-1)?; -///let min = NonZeroI64::new(i64::MIN)?; -///# let max = NonZeroI64::new(i64::MAX)?; -/// assert_eq!(pos, pos.wrapping_abs()); -/// assert_eq!(pos, neg.wrapping_abs()); -/// assert_eq!(min, min.wrapping_abs()); -/// assert_eq!(max, (-max).wrapping_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_abs(self) -> std::num::NonZeroI64; - -"#, - r#" -/// Computes the absolute value of self -/// without any wrapping or panicking. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -///# use std::num::NonZeroU64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let u_pos = NonZeroU64::new(1)?; -///let i_pos = NonZeroI64::new(1)?; -///let i_neg = NonZeroI64::new(-1)?; -///let i_min = NonZeroI64::new(i64::MIN)?; -///let u_max = NonZeroU64::new(u64::MAX / 2 + 1)?; -/// assert_eq!(u_pos, i_pos.unsigned_abs()); -/// assert_eq!(u_pos, i_neg.unsigned_abs()); -/// assert_eq!(u_max, i_min.unsigned_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn unsigned_abs(self) -> std::num::NonZeroU64; - -"#, - r#" -/// Returns `true` if `self` is positive and `false` if the -/// number is negative. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI64::new(5)?; -///let neg_five = NonZeroI64::new(-5)?; -/// assert!(pos_five.is_positive()); -/// assert!(!neg_five.is_positive()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_positive(self) -> bool; - -"#, - r#" -/// Returns `true` if `self` is negative and `false` if the -/// number is positive. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI64::new(5)?; -///let neg_five = NonZeroI64::new(-5)?; -/// assert!(neg_five.is_negative()); -/// assert!(!pos_five.is_negative()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_negative(self) -> bool; - -"#, - r#" -/// Saturating negation. Computes `-self`, -///returning [`NonZeroI64::MAX`] -///if `self == NonZeroI64::MIN` -/// instead of overflowing. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI64::new(5)?; -///let neg_five = NonZeroI64::new(-5)?; -///let min = NonZeroI64::new(i64::MIN)?; -///let min_plus_one = NonZeroI64::new(i64::MIN + 1)?; -///let max = NonZeroI64::new(i64::MAX)?; -/// assert_eq!(pos_five.saturating_neg(), neg_five); -/// assert_eq!(min.saturating_neg(), max); -/// assert_eq!(max.saturating_neg(), min_plus_one); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_neg(self) -> std::num::NonZeroI64; - -"#, - r#" -/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary -/// of the type. -///See [`i64::wrapping_neg`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI64::new(5)?; -///let neg_five = NonZeroI64::new(-5)?; -///let min = NonZeroI64::new(i64::MIN)?; -/// assert_eq!(pos_five.wrapping_neg(), neg_five); -/// assert_eq!(min.wrapping_neg(), min); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_neg(self) -> std::num::NonZeroI64; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroI64::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroI64::new(2)?; -///let four = NonZeroI64::new(4)?; -///let max = NonZeroI64::new(i64::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroI64, - ) -> std::num::NonZeroI64; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroI64::MIN`] or [`NonZeroI64::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroI64::new(3)?; -///let twenty_seven = NonZeroI64::new(27)?; -///let max = NonZeroI64::new(i64::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroI64; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> std::num::NonZeroI64; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroI64) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroI64; - -"#, - 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) -} -"#] -)] -pub struct NonZeroI64(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroI8", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> std::num::NonZeroI8; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroI8) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroI8; - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: i8) -> std::num::NonZeroI8; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> i8; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI8::new(-1i8).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroI8::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Computes the absolute value of self. -///See [`i8::abs`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI8::new(1)?; -///let neg = NonZeroI8::new(-1)?; -/// assert_eq!(pos, pos.abs()); -/// assert_eq!(pos, neg.abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> std::num::NonZeroI8; - -"#, - r#" -/// Saturating absolute value, see -///[`i8::saturating_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI8::new(1)?; -///let neg = NonZeroI8::new(-1)?; -///let min = NonZeroI8::new(i8::MIN)?; -///let min_plus = NonZeroI8::new(i8::MIN + 1)?; -///let max = NonZeroI8::new(i8::MAX)?; -/// assert_eq!(pos, pos.saturating_abs()); -/// assert_eq!(pos, neg.saturating_abs()); -/// assert_eq!(max, min.saturating_abs()); -/// assert_eq!(max, min_plus.saturating_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_abs(self) -> std::num::NonZeroI8; - -"#, - r#" -/// Wrapping absolute value, see -///[`i8::wrapping_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroI8::new(1)?; -///let neg = NonZeroI8::new(-1)?; -///let min = NonZeroI8::new(i8::MIN)?; -///# let max = NonZeroI8::new(i8::MAX)?; -/// assert_eq!(pos, pos.wrapping_abs()); -/// assert_eq!(pos, neg.wrapping_abs()); -/// assert_eq!(min, min.wrapping_abs()); -/// assert_eq!(max, (-max).wrapping_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_abs(self) -> std::num::NonZeroI8; - -"#, - r#" -/// Computes the absolute value of self -/// without any wrapping or panicking. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -///# use std::num::NonZeroU8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let u_pos = NonZeroU8::new(1)?; -///let i_pos = NonZeroI8::new(1)?; -///let i_neg = NonZeroI8::new(-1)?; -///let i_min = NonZeroI8::new(i8::MIN)?; -///let u_max = NonZeroU8::new(u8::MAX / 2 + 1)?; -/// assert_eq!(u_pos, i_pos.unsigned_abs()); -/// assert_eq!(u_pos, i_neg.unsigned_abs()); -/// assert_eq!(u_max, i_min.unsigned_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn unsigned_abs(self) -> std::num::NonZeroU8; - -"#, - r#" -/// Returns `true` if `self` is positive and `false` if the -/// number is negative. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI8::new(5)?; -///let neg_five = NonZeroI8::new(-5)?; -/// assert!(pos_five.is_positive()); -/// assert!(!neg_five.is_positive()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_positive(self) -> bool; - -"#, - r#" -/// Returns `true` if `self` is negative and `false` if the -/// number is positive. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI8::new(5)?; -///let neg_five = NonZeroI8::new(-5)?; -/// assert!(neg_five.is_negative()); -/// assert!(!pos_five.is_negative()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_negative(self) -> bool; - -"#, - r#" -/// Saturating negation. Computes `-self`, -///returning [`NonZeroI8::MAX`] -///if `self == NonZeroI8::MIN` -/// instead of overflowing. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI8::new(5)?; -///let neg_five = NonZeroI8::new(-5)?; -///let min = NonZeroI8::new(i8::MIN)?; -///let min_plus_one = NonZeroI8::new(i8::MIN + 1)?; -///let max = NonZeroI8::new(i8::MAX)?; -/// assert_eq!(pos_five.saturating_neg(), neg_five); -/// assert_eq!(min.saturating_neg(), max); -/// assert_eq!(max.saturating_neg(), min_plus_one); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_neg(self) -> std::num::NonZeroI8; - -"#, - r#" -/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary -/// of the type. -///See [`i8::wrapping_neg`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroI8::new(5)?; -///let neg_five = NonZeroI8::new(-5)?; -///let min = NonZeroI8::new(i8::MIN)?; -/// assert_eq!(pos_five.wrapping_neg(), neg_five); -/// assert_eq!(min.wrapping_neg(), min); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_neg(self) -> std::num::NonZeroI8; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroI8::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroI8::new(2)?; -///let four = NonZeroI8::new(4)?; -///let max = NonZeroI8::new(i8::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] other: std::num::NonZeroI8) -> std::num::NonZeroI8; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroI8::MIN`] or [`NonZeroI8::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroI8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroI8::new(3)?; -///let twenty_seven = NonZeroI8::new(27)?; -///let max = NonZeroI8::new(i8::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroI8; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroI8(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroU128", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroU128; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroU128) -> bool; - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: u128) -> std::num::NonZeroU128; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> u128; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU128::new(u128::MAX).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU128::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Adds an unsigned integer to a non-zero value. -///Return [`NonZeroU128::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let one = NonZeroU128::new(1)?; -///let two = NonZeroU128::new(2)?; -///let max = NonZeroU128::new(u128::MAX)?; -/// assert_eq!(two, one.saturating_add(1)); -/// assert_eq!(max, max.saturating_add(1)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, other: u128) -> std::num::NonZeroU128; - -"#, - r#" -/// Returns the base 2 logarithm of the number, rounded down. -/// This is the same operation as -///[`u128::ilog2`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU128; -///assert_eq!(NonZeroU128::new(7).unwrap().ilog2(), 2); -///assert_eq!(NonZeroU128::new(8).unwrap().ilog2(), 3); -///assert_eq!(NonZeroU128::new(9).unwrap().ilog2(), 3); -/// ``` - - #[lua(kind = "Method")] - fn ilog2(self) -> u32; - -"#, - r#" -/// Returns the base 10 logarithm of the number, rounded down. -/// This is the same operation as -///[`u128::ilog10`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU128; -///assert_eq!(NonZeroU128::new(99).unwrap().ilog10(), 1); -///assert_eq!(NonZeroU128::new(100).unwrap().ilog10(), 2); -///assert_eq!(NonZeroU128::new(101).unwrap().ilog10(), 2); -/// ``` - - #[lua(kind = "Method")] - fn ilog10(self) -> u32; - -"#, - r#" -/// Returns `true` if and only if `self == (1 << k)` for some `k`. -/// On many architectures, this function can perform better than `is_power_of_two()` -/// on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let eight = std::num::NonZeroU128::new(8).unwrap(); -/// assert!(eight.is_power_of_two()); -///let ten = std::num::NonZeroU128::new(10).unwrap(); -/// assert!(!ten.is_power_of_two()); -/// ``` - - #[lua(kind = "Method")] - fn is_power_of_two(self) -> bool; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroU128::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroU128::new(2)?; -///let four = NonZeroU128::new(4)?; -///let max = NonZeroU128::new(u128::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroU128, - ) -> std::num::NonZeroU128; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroU128::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU128; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroU128::new(3)?; -///let twenty_seven = NonZeroU128::new(27)?; -///let max = NonZeroU128::new(u128::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroU128; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroU128(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroU16", - functions[r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: u16) -> std::num::NonZeroU16; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> u16; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU16::new(u16::MAX).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU16::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Adds an unsigned integer to a non-zero value. -///Return [`NonZeroU16::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let one = NonZeroU16::new(1)?; -///let two = NonZeroU16::new(2)?; -///let max = NonZeroU16::new(u16::MAX)?; -/// assert_eq!(two, one.saturating_add(1)); -/// assert_eq!(max, max.saturating_add(1)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, other: u16) -> std::num::NonZeroU16; - -"#, - r#" -/// Returns the base 2 logarithm of the number, rounded down. -/// This is the same operation as -///[`u16::ilog2`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU16; -///assert_eq!(NonZeroU16::new(7).unwrap().ilog2(), 2); -///assert_eq!(NonZeroU16::new(8).unwrap().ilog2(), 3); -///assert_eq!(NonZeroU16::new(9).unwrap().ilog2(), 3); -/// ``` - - #[lua(kind = "Method")] - fn ilog2(self) -> u32; - -"#, - r#" -/// Returns the base 10 logarithm of the number, rounded down. -/// This is the same operation as -///[`u16::ilog10`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU16; -///assert_eq!(NonZeroU16::new(99).unwrap().ilog10(), 1); -///assert_eq!(NonZeroU16::new(100).unwrap().ilog10(), 2); -///assert_eq!(NonZeroU16::new(101).unwrap().ilog10(), 2); -/// ``` - - #[lua(kind = "Method")] - fn ilog10(self) -> u32; - -"#, - r#" -/// Returns `true` if and only if `self == (1 << k)` for some `k`. -/// On many architectures, this function can perform better than `is_power_of_two()` -/// on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let eight = std::num::NonZeroU16::new(8).unwrap(); -/// assert!(eight.is_power_of_two()); -///let ten = std::num::NonZeroU16::new(10).unwrap(); -/// assert!(!ten.is_power_of_two()); -/// ``` - - #[lua(kind = "Method")] - fn is_power_of_two(self) -> bool; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroU16::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroU16::new(2)?; -///let four = NonZeroU16::new(4)?; -///let max = NonZeroU16::new(u16::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroU16, - ) -> std::num::NonZeroU16; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroU16::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU16; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroU16::new(3)?; -///let twenty_seven = NonZeroU16::new(27)?; -///let max = NonZeroU16::new(u16::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroU16; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroU16) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroU16; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroU16(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroU32", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroU32) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: u32) -> std::num::NonZeroU32; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> u32; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU32::new(u32::MAX).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU32::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Adds an unsigned integer to a non-zero value. -///Return [`NonZeroU32::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let one = NonZeroU32::new(1)?; -///let two = NonZeroU32::new(2)?; -///let max = NonZeroU32::new(u32::MAX)?; -/// assert_eq!(two, one.saturating_add(1)); -/// assert_eq!(max, max.saturating_add(1)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, other: u32) -> std::num::NonZeroU32; - -"#, - r#" -/// Returns the base 2 logarithm of the number, rounded down. -/// This is the same operation as -///[`u32::ilog2`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU32; -///assert_eq!(NonZeroU32::new(7).unwrap().ilog2(), 2); -///assert_eq!(NonZeroU32::new(8).unwrap().ilog2(), 3); -///assert_eq!(NonZeroU32::new(9).unwrap().ilog2(), 3); -/// ``` - - #[lua(kind = "Method")] - fn ilog2(self) -> u32; - -"#, - r#" -/// Returns the base 10 logarithm of the number, rounded down. -/// This is the same operation as -///[`u32::ilog10`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU32; -///assert_eq!(NonZeroU32::new(99).unwrap().ilog10(), 1); -///assert_eq!(NonZeroU32::new(100).unwrap().ilog10(), 2); -///assert_eq!(NonZeroU32::new(101).unwrap().ilog10(), 2); -/// ``` - - #[lua(kind = "Method")] - fn ilog10(self) -> u32; - -"#, - r#" -/// Returns `true` if and only if `self == (1 << k)` for some `k`. -/// On many architectures, this function can perform better than `is_power_of_two()` -/// on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let eight = std::num::NonZeroU32::new(8).unwrap(); -/// assert!(eight.is_power_of_two()); -///let ten = std::num::NonZeroU32::new(10).unwrap(); -/// assert!(!ten.is_power_of_two()); -/// ``` - - #[lua(kind = "Method")] - fn is_power_of_two(self) -> bool; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroU32::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroU32::new(2)?; -///let four = NonZeroU32::new(4)?; -///let max = NonZeroU32::new(u32::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroU32, - ) -> std::num::NonZeroU32; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroU32::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU32; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroU32::new(3)?; -///let twenty_seven = NonZeroU32::new(27)?; -///let max = NonZeroU32::new(u32::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroU32; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroU32; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroU32(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroU64", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroU64) -> bool; - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: u64) -> std::num::NonZeroU64; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> u64; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU64::new(u64::MAX).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU64::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Adds an unsigned integer to a non-zero value. -///Return [`NonZeroU64::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let one = NonZeroU64::new(1)?; -///let two = NonZeroU64::new(2)?; -///let max = NonZeroU64::new(u64::MAX)?; -/// assert_eq!(two, one.saturating_add(1)); -/// assert_eq!(max, max.saturating_add(1)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, other: u64) -> std::num::NonZeroU64; - -"#, - r#" -/// Returns the base 2 logarithm of the number, rounded down. -/// This is the same operation as -///[`u64::ilog2`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU64; -///assert_eq!(NonZeroU64::new(7).unwrap().ilog2(), 2); -///assert_eq!(NonZeroU64::new(8).unwrap().ilog2(), 3); -///assert_eq!(NonZeroU64::new(9).unwrap().ilog2(), 3); -/// ``` - - #[lua(kind = "Method")] - fn ilog2(self) -> u32; - -"#, - r#" -/// Returns the base 10 logarithm of the number, rounded down. -/// This is the same operation as -///[`u64::ilog10`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU64; -///assert_eq!(NonZeroU64::new(99).unwrap().ilog10(), 1); -///assert_eq!(NonZeroU64::new(100).unwrap().ilog10(), 2); -///assert_eq!(NonZeroU64::new(101).unwrap().ilog10(), 2); -/// ``` - - #[lua(kind = "Method")] - fn ilog10(self) -> u32; - -"#, - r#" -/// Returns `true` if and only if `self == (1 << k)` for some `k`. -/// On many architectures, this function can perform better than `is_power_of_two()` -/// on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let eight = std::num::NonZeroU64::new(8).unwrap(); -/// assert!(eight.is_power_of_two()); -///let ten = std::num::NonZeroU64::new(10).unwrap(); -/// assert!(!ten.is_power_of_two()); -/// ``` - - #[lua(kind = "Method")] - fn is_power_of_two(self) -> bool; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroU64::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroU64::new(2)?; -///let four = NonZeroU64::new(4)?; -///let max = NonZeroU64::new(u64::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroU64, - ) -> std::num::NonZeroU64; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroU64::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU64; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroU64::new(3)?; -///let twenty_seven = NonZeroU64::new(27)?; -///let max = NonZeroU64::new(u64::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroU64; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroU64; - -"#, - 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) -} -"#] -)] -pub struct NonZeroU64(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroU8", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroU8; - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: u8) -> std::num::NonZeroU8; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> u8; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU8::new(u8::MAX).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroU8::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Adds an unsigned integer to a non-zero value. -///Return [`NonZeroU8::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let one = NonZeroU8::new(1)?; -///let two = NonZeroU8::new(2)?; -///let max = NonZeroU8::new(u8::MAX)?; -/// assert_eq!(two, one.saturating_add(1)); -/// assert_eq!(max, max.saturating_add(1)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, other: u8) -> std::num::NonZeroU8; - -"#, - r#" -/// Returns the base 2 logarithm of the number, rounded down. -/// This is the same operation as -///[`u8::ilog2`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU8; -///assert_eq!(NonZeroU8::new(7).unwrap().ilog2(), 2); -///assert_eq!(NonZeroU8::new(8).unwrap().ilog2(), 3); -///assert_eq!(NonZeroU8::new(9).unwrap().ilog2(), 3); -/// ``` - - #[lua(kind = "Method")] - fn ilog2(self) -> u32; - -"#, - r#" -/// Returns the base 10 logarithm of the number, rounded down. -/// This is the same operation as -///[`u8::ilog10`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroU8; -///assert_eq!(NonZeroU8::new(99).unwrap().ilog10(), 1); -///assert_eq!(NonZeroU8::new(100).unwrap().ilog10(), 2); -///assert_eq!(NonZeroU8::new(101).unwrap().ilog10(), 2); -/// ``` - - #[lua(kind = "Method")] - fn ilog10(self) -> u32; - -"#, - r#" -/// Returns `true` if and only if `self == (1 << k)` for some `k`. -/// On many architectures, this function can perform better than `is_power_of_two()` -/// on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let eight = std::num::NonZeroU8::new(8).unwrap(); -/// assert!(eight.is_power_of_two()); -///let ten = std::num::NonZeroU8::new(10).unwrap(); -/// assert!(!ten.is_power_of_two()); -/// ``` - - #[lua(kind = "Method")] - fn is_power_of_two(self) -> bool; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroU8::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroU8::new(2)?; -///let four = NonZeroU8::new(4)?; -///let max = NonZeroU8::new(u8::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] other: std::num::NonZeroU8) -> std::num::NonZeroU8; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroU8::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroU8; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroU8::new(3)?; -///let twenty_seven = NonZeroU8::new(27)?; -///let max = NonZeroU8::new(u8::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroU8; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroU8) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroU8(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroUsize", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: usize) -> std::num::NonZeroUsize; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> usize; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroUsize::new(usize::MAX).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroUsize::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Adds an unsigned integer to a non-zero value. -///Return [`NonZeroUsize::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroUsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let one = NonZeroUsize::new(1)?; -///let two = NonZeroUsize::new(2)?; -///let max = NonZeroUsize::new(usize::MAX)?; -/// assert_eq!(two, one.saturating_add(1)); -/// assert_eq!(max, max.saturating_add(1)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, other: usize) -> std::num::NonZeroUsize; - -"#, - r#" -/// Returns the base 2 logarithm of the number, rounded down. -/// This is the same operation as -///[`usize::ilog2`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroUsize; -///assert_eq!(NonZeroUsize::new(7).unwrap().ilog2(), 2); -///assert_eq!(NonZeroUsize::new(8).unwrap().ilog2(), 3); -///assert_eq!(NonZeroUsize::new(9).unwrap().ilog2(), 3); -/// ``` - - #[lua(kind = "Method")] - fn ilog2(self) -> u32; - -"#, - r#" -/// Returns the base 10 logarithm of the number, rounded down. -/// This is the same operation as -///[`usize::ilog10`], -/// except that it has no failure cases to worry about -/// since this value can never be zero. -/// # Examples -/// ``` -///# use std::num::NonZeroUsize; -///assert_eq!(NonZeroUsize::new(99).unwrap().ilog10(), 1); -///assert_eq!(NonZeroUsize::new(100).unwrap().ilog10(), 2); -///assert_eq!(NonZeroUsize::new(101).unwrap().ilog10(), 2); -/// ``` - - #[lua(kind = "Method")] - fn ilog10(self) -> u32; - -"#, - r#" -/// Returns `true` if and only if `self == (1 << k)` for some `k`. -/// On many architectures, this function can perform better than `is_power_of_two()` -/// on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let eight = std::num::NonZeroUsize::new(8).unwrap(); -/// assert!(eight.is_power_of_two()); -///let ten = std::num::NonZeroUsize::new(10).unwrap(); -/// assert!(!ten.is_power_of_two()); -/// ``` - - #[lua(kind = "Method")] - fn is_power_of_two(self) -> bool; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroUsize::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroUsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroUsize::new(2)?; -///let four = NonZeroUsize::new(4)?; -///let max = NonZeroUsize::new(usize::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroUsize, - ) -> std::num::NonZeroUsize; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroUsize::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroUsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroUsize::new(3)?; -///let twenty_seven = NonZeroUsize::new(27)?; -///let max = NonZeroUsize::new(usize::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroUsize; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroUsize) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroUsize; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroUsize(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::path::PathBuf", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::path::PathBuf) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::path::PathBuf; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "MutatingMethod", - )] - fn clone_from(&mut self, #[proxy] source: &std::path::PathBuf) -> (); - -"#, - r#" -/// Allocates an empty `PathBuf`. -/// # Examples -/// ``` -/// use std::path::PathBuf; -/// let path = PathBuf::new(); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new() -> std::path::PathBuf; - -"#, - r#" -/// Creates a new `PathBuf` with a given capacity used to create the -/// internal [`OsString`]. See [`with_capacity`] defined on [`OsString`]. -/// # Examples -/// ``` -/// use std::path::PathBuf; -/// let mut path = PathBuf::with_capacity(10); -/// let capacity = path.capacity(); -/// // This push is done without reallocating -/// path.push(r"C:\"); -/// assert_eq!(capacity, path.capacity()); -/// ``` -/// [`with_capacity`]: OsString::with_capacity - - #[lua(kind = "Function", output(proxy))] - fn with_capacity(capacity: usize) -> std::path::PathBuf; - -"#, - r#" -/// Truncates `self` to [`self.parent`]. -/// Returns `false` and does nothing if [`self.parent`] is [`None`]. -/// Otherwise, returns `true`. -/// [`self.parent`]: Path::parent -/// # Examples -/// ``` -/// use std::path::{Path, PathBuf}; -/// let mut p = PathBuf::from("/spirited/away.rs"); -/// p.pop(); -/// assert_eq!(Path::new("/spirited"), p); -/// p.pop(); -/// assert_eq!(Path::new("/"), p); -/// ``` - - #[lua(kind = "MutatingMethod")] - fn pop(&mut self) -> bool; - -"#, - r#" -/// Invokes [`capacity`] on the underlying instance of [`OsString`]. -/// [`capacity`]: OsString::capacity - - #[lua(kind = "Method")] - fn capacity(&self) -> usize; - -"#, - r#" -/// Invokes [`clear`] on the underlying instance of [`OsString`]. -/// [`clear`]: OsString::clear - - #[lua(kind = "MutatingMethod")] - fn clear(&mut self) -> (); - -"#, - r#" -/// Invokes [`reserve`] on the underlying instance of [`OsString`]. -/// [`reserve`]: OsString::reserve - - #[lua(kind = "MutatingMethod")] - fn reserve(&mut self, additional: usize) -> (); - -"#, - r#" -/// Invokes [`reserve_exact`] on the underlying instance of [`OsString`]. -/// [`reserve_exact`]: OsString::reserve_exact - - #[lua(kind = "MutatingMethod")] - fn reserve_exact(&mut self, additional: usize) -> (); - -"#, - r#" -/// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`]. -/// [`shrink_to_fit`]: OsString::shrink_to_fit - - #[lua(kind = "MutatingMethod")] - fn shrink_to_fit(&mut self) -> (); - -"#, - r#" -/// Invokes [`shrink_to`] on the underlying instance of [`OsString`]. -/// [`shrink_to`]: OsString::shrink_to - - #[lua(kind = "MutatingMethod")] - fn shrink_to(&mut self, min_capacity: usize) -> (); - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct PathBuf {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::ops::RangeFull", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::ops::RangeFull; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::ops::RangeFull) -> 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) -} -"#] -)] -pub struct RangeFull {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Quat", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Quat) -> bool; - -"#, - r#" -/// Subtracts the `rhs` quaternion from `self`. -/// The difference is not guaranteed to be normalized. - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; - -"#, - r#" -/// Divides a quaternion by a scalar value. -/// The quotient is not guaranteed to be normalized. - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Quat; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Multiplies two quaternions. If they each represent a rotation, the result will -/// represent the combined rotation. -/// Note that due to floating point rounding the result may not be perfectly -/// normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; - -"#, - r#" -/// Adds two quaternions. -/// The sum is not guaranteed to be normalized. -/// Note that addition is not the same as combining the rotations represented by the -/// two quaternions! That corresponds to multiplication. - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; - -"#, - r#" -/// Multiplies a quaternion by a scalar value. -/// The product is not guaranteed to be normalized. - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Quat; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Quat; - -"#, - r#" -/// Multiplies a quaternion and a 3D vector, returning the rotated vector. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Creates a new rotation quaternion. -/// This should generally not be called manually unless you know what you are doing. -/// Use one of the other constructors instead such as `identity` or `from_axis_angle`. -/// `from_xyzw` is mostly used by unit tests and `serde` deserialization. -/// # Preconditions -/// This function does not check if the input is normalized, it is up to the user to -/// provide normalized input or to normalized the resulting quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_xyzw(x: f32, y: f32, z: f32, w: f32) -> bevy::math::Quat; - -"#, - r#" -/// Creates a rotation quaternion from an array. -/// # Preconditions -/// This function does not check if the input is normalized, it is up to the user to -/// provide normalized input or to normalized the resulting quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 4]) -> bevy::math::Quat; - -"#, - r#" -/// Creates a new rotation quaternion from a 4D vector. -/// # Preconditions -/// This function does not check if the input is normalized, it is up to the user to -/// provide normalized input or to normalized the resulting quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_vec4(#[proxy] v: bevy::math::Vec4) -> bevy::math::Quat; - -"#, - r#" -/// Create a quaternion for a normalized rotation `axis` and `angle` (in radians). -/// The axis must be a unit vector. -/// # Panics -/// Will panic if `axis` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Quat; - -"#, - r#" -/// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. -/// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_scaled_axis(#[proxy] v: bevy::math::Vec3) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from the `angle` (in radians) around the x axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from the `angle` (in radians) around the y axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from the `angle` (in radians) around the z axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_euler( - #[proxy] - euler: bevy::math::EulerRot, - a: f32, - b: f32, - c: f32, - ) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from a 3x3 rotation matrix. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat: &glam::Mat3) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from a 3x3 SIMD aligned rotation matrix. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] mat: &glam::Mat3A) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. - - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] mat: &glam::Mat4) -> bevy::math::Quat; - -"#, - r#" -/// Gets the minimal rotation for transforming `from` to `to`. The rotation is in the -/// plane spanned by the two vectors. Will rotate at most 180 degrees. -/// The inputs must be unit vectors. -/// `from_rotation_arc(from, to) * from ≈ to`. -/// For near-singular cases (from≈to and from≈-to) the current implementation -/// is only accurate to about 0.001 (for `f32`). -/// # Panics -/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_arc( - #[proxy] - from: bevy::math::Vec3, - #[proxy] - to: bevy::math::Vec3, - ) -> bevy::math::Quat; - -"#, - r#" -/// Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means -/// that the resulting quaternion will rotate `from` so that it is colinear with `to`. -/// The rotation is in the plane spanned by the two vectors. Will rotate at most 90 -/// degrees. -/// The inputs must be unit vectors. -/// `to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. -/// # Panics -/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_arc_colinear( - #[proxy] - from: bevy::math::Vec3, - #[proxy] - to: bevy::math::Vec3, - ) -> bevy::math::Quat; - -"#, - r#" -/// Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is -/// around the z axis. Will rotate at most 180 degrees. -/// The inputs must be unit vectors. -/// `from_rotation_arc_2d(from, to) * from ≈ to`. -/// For near-singular cases (from≈to and from≈-to) the current implementation -/// is only accurate to about 0.001 (for `f32`). -/// # Panics -/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_arc_2d( - #[proxy] - from: bevy::math::Vec2, - #[proxy] - to: bevy::math::Vec2, - ) -> bevy::math::Quat; - -"#, - r#" -/// Returns the rotation axis scaled by the rotation in radians. - - #[lua(kind = "Method", output(proxy))] - fn to_scaled_axis(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the rotation angles for the given euler rotation sequence. - - #[lua(kind = "Method")] - fn to_euler(self, #[proxy] euler: bevy::math::EulerRot) -> (f32, f32, f32); - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 4]; - -"#, - r#" -/// Returns the vector part of the quaternion. - - #[lua(kind = "Method", output(proxy))] - fn xyz(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the quaternion conjugate of `self`. For a unit quaternion the -/// conjugate is also the inverse. - - #[lua(kind = "Method", output(proxy))] - fn conjugate(self) -> bevy::math::Quat; - -"#, - r#" -/// Returns the inverse of a normalized quaternion. -/// Typically quaternion inverse returns the conjugate of a normalized quaternion. -/// Because `self` is assumed to already be unit length this method *does not* normalize -/// before returning the conjugate. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(self) -> bevy::math::Quat; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. The dot product is -/// equal to the cosine of the angle between two quaternion rotations. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Quat) -> f32; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f32; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is generally faster than `length()` as it avoids a square -/// root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f32; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f32; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Quat; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Returns whether `self` of length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" - - #[lua(kind = "Method")] - fn is_near_identity(self) -> bool; - -"#, - r#" -/// Returns the angle (in radians) for the minimal rotation -/// for transforming this quaternion into another. -/// Both quaternions must be normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Quat) -> f32; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two quaternions contain similar elements. It works -/// best when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Quat, max_abs_diff: f32) -> bool; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on -/// the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` -/// is `1.0`, the result will be equal to `rhs`. -/// # Panics -/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] end: bevy::math::Quat, s: f32) -> bevy::math::Quat; - -"#, - r#" -/// Performs a spherical linear interpolation between `self` and `end` -/// based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` -/// is `1.0`, the result will be equal to `end`. -/// # Panics -/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn slerp(self, #[proxy] end: bevy::math::Quat, s: f32) -> bevy::math::Quat; - -"#, - r#" -/// Multiplies a quaternion and a 3D vector, returning the rotated vector. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Multiplies two quaternions. If they each represent a rotation, the result will -/// represent the combined rotation. -/// Note that due to floating point rounding the result may not be perfectly normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn mul_quat(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; - -"#, - r#" -/// Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. - - #[lua(kind = "Function", output(proxy))] - fn from_affine3(#[proxy] a: &glam::Affine3A) -> bevy::math::Quat; - -"#, - r#" -/// Multiplies a quaternion and a 3D vector, returning the rotated vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3a(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_dquat(self) -> bevy::math::DQuat; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_f64(self) -> bevy::math::DQuat; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Quat; - -"#, - r#" -/// Rotates the [`Direction3d`] using a [`Quat`]. - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul( - self, - #[proxy] - direction: bevy::math::primitives::Direction3d, - ) -> bevy::math::primitives::Direction3d; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct Quat(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Vec3", - functions[r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::Vec3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32, z: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::Vec3, - #[proxy] - if_false: bevy::math::Vec3, - ) -> bevy::math::Vec3; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 3]) -> bevy::math::Vec3; - -"#, - r#" -/// `[x, y, z]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::Vec2; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec3) -> f32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Component-wise clamping of values, similar to [`f32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::Vec3, - #[proxy] - max: bevy::math::Vec3, - ) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> f32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> f32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `1.0` if the number is positive, `+0.0` or `INFINITY` -/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` -/// - `NAN` if the number is `NAN` - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector with signs of `rhs` and the magnitudes of `self`. - - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. If any element is either -/// `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Performs `is_nan` on each element of self, returning a vector mask of the results. -/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. - - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec3; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f32; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is faster than `length()` as it avoids a square root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f32; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f32; - -"#, - r#" -/// Computes the Euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec3) -> f32; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec3) -> f32; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// [Euclidean division]: f32::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero, nor very close to zero. -/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns `self` normalized to length 1.0 if possible, else returns zero. -/// In particular, if the input is zero (or very close to zero), or non-finite, -/// the result of this operation will be zero. -/// See also [`Self::try_normalize()`]. - - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns whether `self` is length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the nearest integer to a number for each element of `self`. -/// Round half-way cases away from 0.0. - - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the largest integer less than or equal to a number for each -/// element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the smallest integer greater than or equal to a number for -/// each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the integer part each element of `self`. This means numbers are -/// always truncated towards zero. - - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the fractional part of the vector, e.g. `self - -/// self.floor()`. -/// Note that this is fast but not precise for large numbers. - - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing `e^self` (the exponential function) for each element of -/// `self`. - - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing each element of `self` raised to the power of `n`. - - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec3; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result -/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly -/// extrapolated. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec3, s: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` is -/// less than or equal to `max_abs_diff`. -/// This can be used to compare if two vectors contain similar elements. It works best when -/// comparing with a known value. The `max_abs_diff` that should be used used depends on -/// the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec3, max_abs_diff: f32) -> bool; - -"#, - r#" -/// Returns a vector with a length no less than `min` and no more than `max` -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector with a length no more than `max` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Returns a vector with a length no less than `min` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding -/// error, yielding a more accurate result than an unfused multiply-add. -/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target -/// architecture has a dedicated fma CPU instruction. However, this is not always true, -/// and will be heavily dependant on designing algorithms with specific target hardware in -/// mind. - - #[lua(kind = "Method", output(proxy))] - fn mul_add( - self, - #[proxy] - a: bevy::math::Vec3, - #[proxy] - b: bevy::math::Vec3, - ) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the angle (in radians) between two vectors. -/// The inputs do not need to be unit vectors however they must be non-zero. - - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Vec3) -> f32; - -"#, - r#" -/// Returns some vector that is orthogonal to the given one. -/// The input vector must be finite and non-zero. -/// The output vector is not necessarily unit length. For that use -/// [`Self::any_orthonormal_vector()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn any_orthogonal_vector(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Returns any unit vector that is orthogonal to the given one. -/// The input vector must be unit length. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn any_orthonormal_vector(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct Vec3 { - x: f32, - y: f32, - z: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::IVec2", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::IVec2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i32) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: i32, y: i32) -> bevy::math::IVec2; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: i32) -> bevy::math::IVec2; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::IVec2, - #[proxy] - if_false: bevy::math::IVec2, - ) -> bevy::math::IVec2; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i32; 2]) -> bevy::math::IVec2; - -"#, - r#" -/// `[x, y]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [i32; 2]; - -"#, - r#" -/// Creates a 3D vector from `self` and the given `z` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: i32) -> bevy::math::IVec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::IVec2) -> i32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Component-wise clamping of values, similar to [`i32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::IVec2, - #[proxy] - max: bevy::math::IVec2, - ) -> bevy::math::IVec2; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> i32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> i32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `0` if the number is zero -/// - `1` if the number is positive -/// - `-1` if the number is negative - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> i32; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::IVec2) -> i32; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. -/// [Euclidean division]: i32::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector that is equal to `self` rotated by 90 degrees. - - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::IVec2; - -"#, - r#" -/// The perpendicular dot product of `self` and `rhs`. -/// Also known as the wedge product, 2D cross product, and determinant. - - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::IVec2) -> i32; - -"#, - r#" -/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, -/// then this just rotation. This is what you usually want. Otherwise, -/// it will be like a rotation with a multiplication by `self`'s length. - - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i32) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i32) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i32) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i32) -> bevy::math::IVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct IVec2 { - x: i32, - y: i32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::IVec3", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i32) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i32) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::IVec3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i32) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i32) -> bevy::math::IVec3; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: i32, y: i32, z: i32) -> bevy::math::IVec3; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: i32) -> bevy::math::IVec3; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::IVec3, - #[proxy] - if_false: bevy::math::IVec3, - ) -> bevy::math::IVec3; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i32; 3]) -> bevy::math::IVec3; - -"#, - r#" -/// `[x, y, z]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [i32; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: i32) -> bevy::math::IVec4; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::IVec2; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::IVec3) -> i32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Component-wise clamping of values, similar to [`i32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::IVec3, - #[proxy] - max: bevy::math::IVec3, - ) -> bevy::math::IVec3; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> i32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> i32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `0` if the number is zero -/// - `1` if the number is positive -/// - `-1` if the number is negative - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> i32; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::IVec3) -> i32; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. -/// [Euclidean division]: i32::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i32) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::IVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct IVec3 { - x: i32, - y: i32, - z: i32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::IVec4", - functions[r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: i32, y: i32, z: i32, w: i32) -> bevy::math::IVec4; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: i32) -> bevy::math::IVec4; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::IVec4, - #[proxy] - if_false: bevy::math::IVec4, - ) -> bevy::math::IVec4; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i32; 4]) -> bevy::math::IVec4; - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [i32; 4]; - -"#, - r#" -/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. -/// Truncation to [`IVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::IVec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::IVec4) -> i32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Component-wise clamping of values, similar to [`i32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::IVec4, - #[proxy] - max: bevy::math::IVec4, - ) -> bevy::math::IVec4; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> i32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> i32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `0` if the number is zero -/// - `1` if the number is positive -/// - `-1` if the number is negative - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> i32; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::IVec4) -> i32; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. -/// [Euclidean division]: i32::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i32) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i32) -> bevy::math::IVec4; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i32) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i32) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i32) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::IVec4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::IVec4) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct IVec4 { - x: i32, - y: i32, - z: i32, - w: i32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::I64Vec2", - functions[r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i64) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::I64Vec2) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i64) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i64) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i64) -> bevy::math::I64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i64) -> bevy::math::I64Vec2; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: i64, y: i64) -> bevy::math::I64Vec2; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: i64) -> bevy::math::I64Vec2; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::I64Vec2, - #[proxy] - if_false: bevy::math::I64Vec2, - ) -> bevy::math::I64Vec2; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i64; 2]) -> bevy::math::I64Vec2; - -"#, - r#" -/// `[x, y]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [i64; 2]; - -"#, - r#" -/// Creates a 3D vector from `self` and the given `z` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: i64) -> bevy::math::I64Vec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Component-wise clamping of values, similar to [`i64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::I64Vec2, - #[proxy] - max: bevy::math::I64Vec2, - ) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> i64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> i64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `0` if the number is zero -/// - `1` if the number is positive -/// - `-1` if the number is negative - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> i64; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. -/// [Euclidean division]: i64::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector that is equal to `self` rotated by 90 degrees. - - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::I64Vec2; - -"#, - r#" -/// The perpendicular dot product of `self` and `rhs`. -/// Also known as the wedge product, 2D cross product, and determinant. - - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; - -"#, - r#" -/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, -/// then this just rotation. This is what you usually want. Otherwise, -/// it will be like a rotation with a multiplication by `self`'s length. - - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct I64Vec2 { - x: i64, - y: i64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::I64Vec3", - functions[r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i64) -> bevy::math::I64Vec3; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: i64, y: i64, z: i64) -> bevy::math::I64Vec3; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: i64) -> bevy::math::I64Vec3; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::I64Vec3, - #[proxy] - if_false: bevy::math::I64Vec3, - ) -> bevy::math::I64Vec3; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i64; 3]) -> bevy::math::I64Vec3; - -"#, - r#" -/// `[x, y, z]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [i64; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: i64) -> bevy::math::I64Vec4; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::I64Vec3) -> i64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Component-wise clamping of values, similar to [`i64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::I64Vec3, - #[proxy] - max: bevy::math::I64Vec3, - ) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> i64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> i64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `0` if the number is zero -/// - `1` if the number is positive -/// - `-1` if the number is negative - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> i64; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec3) -> i64; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. -/// [Euclidean division]: i64::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i64) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::I64Vec3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i64) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i64) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i64) -> bevy::math::I64Vec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct I64Vec3 { - x: i64, - y: i64, - z: i64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::I64Vec4", - functions[r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i64) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i64) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i64) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::I64Vec4) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i64) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i64) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::I64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: i64, y: i64, z: i64, w: i64) -> bevy::math::I64Vec4; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: i64) -> bevy::math::I64Vec4; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::I64Vec4, - #[proxy] - if_false: bevy::math::I64Vec4, - ) -> bevy::math::I64Vec4; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i64; 4]) -> bevy::math::I64Vec4; - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [i64; 4]; - -"#, - r#" -/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. -/// Truncation to [`I64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::I64Vec4) -> i64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Component-wise clamping of values, similar to [`i64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::I64Vec4, - #[proxy] - max: bevy::math::I64Vec4, - ) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> i64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> i64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `0` if the number is zero -/// - `1` if the number is positive -/// - `-1` if the number is negative - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> i64; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec4) -> i64; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// # Panics -/// This function will panic if any `rhs` element is 0 or the division results in overflow. -/// [Euclidean division]: i64::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct I64Vec4 { - x: i64, - y: i64, - z: i64, - w: i64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::UVec2", - functions[r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::UVec2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: u32, y: u32) -> bevy::math::UVec2; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: u32) -> bevy::math::UVec2; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::UVec2, - #[proxy] - if_false: bevy::math::UVec2, - ) -> bevy::math::UVec2; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u32; 2]) -> bevy::math::UVec2; - -"#, - r#" -/// `[x, y]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [u32; 2]; - -"#, - r#" -/// Creates a 3D vector from `self` and the given `z` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: u32) -> bevy::math::UVec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::UVec2) -> u32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Component-wise clamping of values, similar to [`u32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::UVec2, - #[proxy] - max: bevy::math::UVec2, - ) -> bevy::math::UVec2; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> u32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> u32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> u32; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u32) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u32) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u32) -> bevy::math::UVec2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::UVec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct UVec2 { - x: u32, - y: u32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::UVec3", - functions[r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u32) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::UVec3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: u32, y: u32, z: u32) -> bevy::math::UVec3; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: u32) -> bevy::math::UVec3; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::UVec3, - #[proxy] - if_false: bevy::math::UVec3, - ) -> bevy::math::UVec3; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u32; 3]) -> bevy::math::UVec3; - -"#, - r#" -/// `[x, y, z]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [u32; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: u32) -> bevy::math::UVec4; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::UVec2; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::UVec3) -> u32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Component-wise clamping of values, similar to [`u32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::UVec3, - #[proxy] - max: bevy::math::UVec3, - ) -> bevy::math::UVec3; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> u32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> u32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> u32; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u32) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u32) -> bevy::math::UVec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct UVec3 { - x: u32, - y: u32, - z: u32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::UVec4", - functions[r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u32) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u32) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: u32, y: u32, z: u32, w: u32) -> bevy::math::UVec4; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: u32) -> bevy::math::UVec4; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::UVec4, - #[proxy] - if_false: bevy::math::UVec4, - ) -> bevy::math::UVec4; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u32; 4]) -> bevy::math::UVec4; - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [u32; 4]; - -"#, - r#" -/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. -/// Truncation to [`UVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::UVec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::UVec4) -> u32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Component-wise clamping of values, similar to [`u32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::UVec4, - #[proxy] - max: bevy::math::UVec4, - ) -> bevy::math::UVec4; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> u32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> u32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> u32; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::UVec4; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u32) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::math::UVec4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::UVec4) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct UVec4 { - x: u32, - y: u32, - z: u32, - w: u32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::U64Vec2", - functions[r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u64) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u64) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u64) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u64) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::U64Vec2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u64) -> bevy::math::U64Vec2; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: u64, y: u64) -> bevy::math::U64Vec2; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: u64) -> bevy::math::U64Vec2; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::U64Vec2, - #[proxy] - if_false: bevy::math::U64Vec2, - ) -> bevy::math::U64Vec2; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u64; 2]) -> bevy::math::U64Vec2; - -"#, - r#" -/// `[x, y]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [u64; 2]; - -"#, - r#" -/// Creates a 3D vector from `self` and the given `z` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: u64) -> bevy::math::U64Vec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::U64Vec2) -> u64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Component-wise clamping of values, similar to [`u64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::U64Vec2, - #[proxy] - max: bevy::math::U64Vec2, - ) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> u64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> u64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> u64; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct U64Vec2 { - x: u64, - y: u64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::U64Vec3", - functions[r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u64) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::U64Vec3) -> bool; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: u64, y: u64, z: u64) -> bevy::math::U64Vec3; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: u64) -> bevy::math::U64Vec3; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::U64Vec3, - #[proxy] - if_false: bevy::math::U64Vec3, - ) -> bevy::math::U64Vec3; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u64; 3]) -> bevy::math::U64Vec3; - -"#, - r#" -/// `[x, y, z]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [u64; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: u64) -> bevy::math::U64Vec4; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::U64Vec2; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::U64Vec3) -> u64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Component-wise clamping of values, similar to [`u64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::U64Vec3, - #[proxy] - max: bevy::math::U64Vec3, - ) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> u64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> u64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> u64; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u64) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u64) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u64) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u64) -> bevy::math::U64Vec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct U64Vec3 { - x: u64, - y: u64, - z: u64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::U64Vec4", - functions[r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u64) -> bevy::math::U64Vec4; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: u64, y: u64, z: u64, w: u64) -> bevy::math::U64Vec4; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: u64) -> bevy::math::U64Vec4; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::U64Vec4, - #[proxy] - if_false: bevy::math::U64Vec4, - ) -> bevy::math::U64Vec4; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u64; 4]) -> bevy::math::U64Vec4; - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [u64; 4]; - -"#, - r#" -/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. -/// Truncation to [`U64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::U64Vec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::U64Vec4) -> u64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Component-wise clamping of values, similar to [`u64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::U64Vec4, - #[proxy] - max: bevy::math::U64Vec4, - ) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> u64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> u64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; - -"#, - r#" -/// Computes the squared length of `self`. - - #[lua(kind = "Method")] - fn length_squared(self) -> u64; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the wrapping division of `self` and `rhs`. -/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating subtraction of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating multiplication of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::U64Vec4) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u64) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u64) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u64) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u64) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct U64Vec4 { - x: u64, - y: u64, - z: u64, - w: u64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Vec2", - functions[r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::Vec2, - #[proxy] - if_false: bevy::math::Vec2, - ) -> bevy::math::Vec2; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 2]) -> bevy::math::Vec2; - -"#, - r#" -/// `[x, y]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 2]; - -"#, - r#" -/// Creates a 3D vector from `self` and the given `z` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: f32) -> bevy::math::Vec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec2) -> f32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Component-wise clamping of values, similar to [`f32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::Vec2, - #[proxy] - max: bevy::math::Vec2, - ) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> f32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> f32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `1.0` if the number is positive, `+0.0` or `INFINITY` -/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` -/// - `NAN` if the number is `NAN` - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector with signs of `rhs` and the magnitudes of `self`. - - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. If any element is either -/// `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Performs `is_nan` on each element of self, returning a vector mask of the results. -/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. - - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec2; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f32; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is faster than `length()` as it avoids a square root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f32; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f32; - -"#, - r#" -/// Computes the Euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec2) -> f32; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec2) -> f32; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// [Euclidean division]: f32::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero, nor very close to zero. -/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns `self` normalized to length 1.0 if possible, else returns zero. -/// In particular, if the input is zero (or very close to zero), or non-finite, -/// the result of this operation will be zero. -/// See also [`Self::try_normalize()`]. - - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns whether `self` is length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the nearest integer to a number for each element of `self`. -/// Round half-way cases away from 0.0. - - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the largest integer less than or equal to a number for each -/// element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the smallest integer greater than or equal to a number for -/// each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the integer part each element of `self`. This means numbers are -/// always truncated towards zero. - - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the fractional part of the vector, e.g. `self - -/// self.floor()`. -/// Note that this is fast but not precise for large numbers. - - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing `e^self` (the exponential function) for each element of -/// `self`. - - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing each element of `self` raised to the power of `n`. - - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec2; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result -/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly -/// extrapolated. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec2, s: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` is -/// less than or equal to `max_abs_diff`. -/// This can be used to compare if two vectors contain similar elements. It works best when -/// comparing with a known value. The `max_abs_diff` that should be used used depends on -/// the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec2, max_abs_diff: f32) -> bool; - -"#, - r#" -/// Returns a vector with a length no less than `min` and no more than `max` -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector with a length no more than `max` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Returns a vector with a length no less than `min` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding -/// error, yielding a more accurate result than an unfused multiply-add. -/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target -/// architecture has a dedicated fma CPU instruction. However, this is not always true, -/// and will be heavily dependant on designing algorithms with specific target hardware in -/// mind. - - #[lua(kind = "Method", output(proxy))] - fn mul_add( - self, - #[proxy] - a: bevy::math::Vec2, - #[proxy] - b: bevy::math::Vec2, - ) -> bevy::math::Vec2; - -"#, - r#" -/// Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in -/// conjunction with the [`rotate()`][Self::rotate()] method, e.g. -/// `Vec2::from_angle(PI).rotate(Vec2::Y)` will create the vector `[-1, 0]` -/// and rotate [`Vec2::Y`] around it returning `-Vec2::Y`. - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the angle (in radians) of this vector in the range `[-Ï€, +Ï€]`. -/// The input does not need to be a unit vector however it must be non-zero. - - #[lua(kind = "Method")] - fn to_angle(self) -> f32; - -"#, - r#" -/// Returns the angle (in radians) between `self` and `rhs` in the range `[-Ï€, +Ï€]`. -/// The inputs do not need to be unit vectors however they must be non-zero. - - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Vec2) -> f32; - -"#, - r#" -/// Returns a vector that is equal to `self` rotated by 90 degrees. - - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::Vec2; - -"#, - r#" -/// The perpendicular dot product of `self` and `rhs`. -/// Also known as the wedge product, 2D cross product, and determinant. - - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::Vec2) -> f32; - -"#, - r#" -/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, -/// then this just rotation. This is what you usually want. Otherwise, -/// it will be like a rotation with a multiplication by `self`'s length. - - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::Vec2) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct Vec2 { - x: f32, - y: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Vec3A", - functions[r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Vec3A) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32, z: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec3A, - #[proxy] - if_true: bevy::math::Vec3A, - #[proxy] - if_false: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 3]) -> bevy::math::Vec3A; - -"#, - r#" -/// `[x, y, z]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::Vec2; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Component-wise clamping of values, similar to [`f32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::Vec3A, - #[proxy] - max: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> f32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> f32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `1.0` if the number is positive, `+0.0` or `INFINITY` -/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` -/// - `NAN` if the number is `NAN` - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector with signs of `rhs` and the magnitudes of `self`. - - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. If any element is either -/// `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Performs `is_nan` on each element of self, returning a vector mask of the results. -/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. - - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec3A; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f32; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is faster than `length()` as it avoids a square root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f32; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f32; - -"#, - r#" -/// Computes the Euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// [Euclidean division]: f32::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero, nor very close to zero. -/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns `self` normalized to length 1.0 if possible, else returns zero. -/// In particular, if the input is zero (or very close to zero), or non-finite, -/// the result of this operation will be zero. -/// See also [`Self::try_normalize()`]. - - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns whether `self` is length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the nearest integer to a number for each element of `self`. -/// Round half-way cases away from 0.0. - - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the largest integer less than or equal to a number for each -/// element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the smallest integer greater than or equal to a number for -/// each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the integer part each element of `self`. This means numbers are -/// always truncated towards zero. - - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the fractional part of the vector, e.g. `self - -/// self.floor()`. -/// Note that this is fast but not precise for large numbers. - - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing `e^self` (the exponential function) for each element of -/// `self`. - - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing each element of `self` raised to the power of `n`. - - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec3A; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result -/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly -/// extrapolated. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec3A, s: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` is -/// less than or equal to `max_abs_diff`. -/// This can be used to compare if two vectors contain similar elements. It works best when -/// comparing with a known value. The `max_abs_diff` that should be used used depends on -/// the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec3A, max_abs_diff: f32) -> bool; - -"#, - r#" -/// Returns a vector with a length no less than `min` and no more than `max` -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector with a length no more than `max` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns a vector with a length no less than `min` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec3A; - -"#, - r#" -/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding -/// error, yielding a more accurate result than an unfused multiply-add. -/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target -/// architecture has a dedicated fma CPU instruction. However, this is not always true, -/// and will be heavily dependant on designing algorithms with specific target hardware in -/// mind. - - #[lua(kind = "Method", output(proxy))] - fn mul_add( - self, - #[proxy] - a: bevy::math::Vec3A, - #[proxy] - b: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns the angle (in radians) between two vectors. -/// The inputs do not need to be unit vectors however they must be non-zero. - - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; - -"#, - r#" -/// Returns some vector that is orthogonal to the given one. -/// The input vector must be finite and non-zero. -/// The output vector is not necessarily unit length. For that use -/// [`Self::any_orthonormal_vector()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn any_orthogonal_vector(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns any unit vector that is orthogonal to the given one. -/// The input vector must be unit length. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn any_orthonormal_vector(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct Vec3A(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Vec4", - functions[r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Vec4) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32, z: f32, w: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec4A, - #[proxy] - if_true: bevy::math::Vec4, - #[proxy] - if_false: bevy::math::Vec4, - ) -> bevy::math::Vec4; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 4]) -> bevy::math::Vec4; - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 4]; - -"#, - r#" -/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. -/// Truncation to [`Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. -/// To truncate to [`Vec3A`] use [`Vec3A::from()`]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::Vec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec4) -> f32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Component-wise clamping of values, similar to [`f32::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::Vec4, - #[proxy] - max: bevy::math::Vec4, - ) -> bevy::math::Vec4; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> f32; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> f32; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `1.0` if the number is positive, `+0.0` or `INFINITY` -/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` -/// - `NAN` if the number is `NAN` - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector with signs of `rhs` and the magnitudes of `self`. - - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. If any element is either -/// `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Performs `is_nan` on each element of self, returning a vector mask of the results. -/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. - - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec4A; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f32; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is faster than `length()` as it avoids a square root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f32; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f32; - -"#, - r#" -/// Computes the Euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec4) -> f32; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec4) -> f32; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// [Euclidean division]: f32::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero, nor very close to zero. -/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns `self` normalized to length 1.0 if possible, else returns zero. -/// In particular, if the input is zero (or very close to zero), or non-finite, -/// the result of this operation will be zero. -/// See also [`Self::try_normalize()`]. - - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns whether `self` is length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the nearest integer to a number for each element of `self`. -/// Round half-way cases away from 0.0. - - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the largest integer less than or equal to a number for each -/// element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the smallest integer greater than or equal to a number for -/// each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the integer part each element of `self`. This means numbers are -/// always truncated towards zero. - - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the fractional part of the vector, e.g. `self - -/// self.floor()`. -/// Note that this is fast but not precise for large numbers. - - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing `e^self` (the exponential function) for each element of -/// `self`. - - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing each element of `self` raised to the power of `n`. - - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec4; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result -/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly -/// extrapolated. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec4, s: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` is -/// less than or equal to `max_abs_diff`. -/// This can be used to compare if two vectors contain similar elements. It works best when -/// comparing with a known value. The `max_abs_diff` that should be used used depends on -/// the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec4, max_abs_diff: f32) -> bool; - -"#, - r#" -/// Returns a vector with a length no less than `min` and no more than `max` -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector with a length no more than `max` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Returns a vector with a length no less than `min` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec4; - -"#, - r#" -/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding -/// error, yielding a more accurate result than an unfused multiply-add. -/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target -/// architecture has a dedicated fma CPU instruction. However, this is not always true, -/// and will be heavily dependant on designing algorithms with specific target hardware in -/// mind. - - #[lua(kind = "Method", output(proxy))] - fn mul_add( - self, - #[proxy] - a: bevy::math::Vec4, - #[proxy] - b: bevy::math::Vec4, - ) -> bevy::math::Vec4; - -"#, - r#" -/// Casts all elements of `self` to `f64`. - - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct Vec4(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::BVec2", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a new vector mask. - - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool) -> bevy::math::BVec2; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a bitmask with the lowest 2 bits set from the elements of `self`. -/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn bitmask(self) -> u32; - -"#, - r#" -/// Returns true if any of the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn any(self) -> bool; - -"#, - r#" -/// Returns true if all the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn all(self) -> bool; - -"#, - r#" -/// Tests the value at `index`. -/// Panics if `index` is greater than 1. - - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; - -"#, - r#" -/// Sets the element at `index`. -/// Panics if `index` is greater than 1. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::BVec2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct BVec2 { - x: bool, - y: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::BVec3", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::BVec3) -> bool; - -"#, - r#" -/// Creates a new vector mask. - - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool) -> bevy::math::BVec3; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a bitmask with the lowest 3 bits set from the elements of `self`. -/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn bitmask(self) -> u32; - -"#, - r#" -/// Returns true if any of the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn any(self) -> bool; - -"#, - r#" -/// Returns true if all the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn all(self) -> bool; - -"#, - r#" -/// Tests the value at `index`. -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; - -"#, - r#" -/// Sets the element at `index`. -/// Panics if `index` is greater than 2. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct BVec3 { - x: bool, - y: bool, - z: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::BVec4", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec4; - -"#, - r#" -/// Creates a new vector mask. - - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool, w: bool) -> bevy::math::BVec4; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a bitmask with the lowest 4 bits set from the elements of `self`. -/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn bitmask(self) -> u32; - -"#, - r#" -/// Returns true if any of the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn any(self) -> bool; - -"#, - r#" -/// Returns true if all the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn all(self) -> bool; - -"#, - r#" -/// Tests the value at `index`. -/// Panics if `index` is greater than 3. - - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; - -"#, - r#" -/// Sets the element at `index`. -/// Panics if `index` is greater than 3. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::BVec4) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct BVec4 { - x: bool, - y: bool, - z: bool, - w: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DVec2", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::DVec2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f64) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: f64, y: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::DVec2, - #[proxy] - if_false: bevy::math::DVec2, - ) -> bevy::math::DVec2; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 2]) -> bevy::math::DVec2; - -"#, - r#" -/// `[x, y]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 2]; - -"#, - r#" -/// Creates a 3D vector from `self` and the given `z` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DVec2) -> f64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Component-wise clamping of values, similar to [`f64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::DVec2, - #[proxy] - max: bevy::math::DVec2, - ) -> bevy::math::DVec2; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> f64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> f64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `1.0` if the number is positive, `+0.0` or `INFINITY` -/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` -/// - `NAN` if the number is `NAN` - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector with signs of `rhs` and the magnitudes of `self`. - - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. If any element is either -/// `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Performs `is_nan` on each element of self, returning a vector mask of the results. -/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. - - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec2; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f64; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is faster than `length()` as it avoids a square root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f64; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f64; - -"#, - r#" -/// Computes the Euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::DVec2) -> f64; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::DVec2) -> f64; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// [Euclidean division]: f64::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero, nor very close to zero. -/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns `self` normalized to length 1.0 if possible, else returns zero. -/// In particular, if the input is zero (or very close to zero), or non-finite, -/// the result of this operation will be zero. -/// See also [`Self::try_normalize()`]. - - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns whether `self` is length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::DVec2, - ) -> bevy::math::DVec2; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::DVec2, - ) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the nearest integer to a number for each element of `self`. -/// Round half-way cases away from 0.0. - - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the largest integer less than or equal to a number for each -/// element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the smallest integer greater than or equal to a number for -/// each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the integer part each element of `self`. This means numbers are -/// always truncated towards zero. - - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the fractional part of the vector, e.g. `self - -/// self.floor()`. -/// Note that this is fast but not precise for large numbers. - - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing `e^self` (the exponential function) for each element of -/// `self`. - - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing each element of `self` raised to the power of `n`. - - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::DVec2; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result -/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly -/// extrapolated. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::DVec2, s: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` is -/// less than or equal to `max_abs_diff`. -/// This can be used to compare if two vectors contain similar elements. It works best when -/// comparing with a known value. The `max_abs_diff` that should be used used depends on -/// the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec2, max_abs_diff: f64) -> bool; - -"#, - r#" -/// Returns a vector with a length no less than `min` and no more than `max` -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector with a length no more than `max` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Returns a vector with a length no less than `min` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding -/// error, yielding a more accurate result than an unfused multiply-add. -/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target -/// architecture has a dedicated fma CPU instruction. However, this is not always true, -/// and will be heavily dependant on designing algorithms with specific target hardware in -/// mind. - - #[lua(kind = "Method", output(proxy))] - fn mul_add( - self, - #[proxy] - a: bevy::math::DVec2, - #[proxy] - b: bevy::math::DVec2, - ) -> bevy::math::DVec2; - -"#, - r#" -/// Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in -/// conjunction with the [`rotate()`][Self::rotate()] method, e.g. -/// `DVec2::from_angle(PI).rotate(DVec2::Y)` will create the vector `[-1, 0]` -/// and rotate [`DVec2::Y`] around it returning `-DVec2::Y`. - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DVec2; - -"#, - r#" -/// Returns the angle (in radians) of this vector in the range `[-Ï€, +Ï€]`. -/// The input does not need to be a unit vector however it must be non-zero. - - #[lua(kind = "Method")] - fn to_angle(self) -> f64; - -"#, - r#" -/// Returns the angle (in radians) between `self` and `rhs` in the range `[-Ï€, +Ï€]`. -/// The inputs do not need to be unit vectors however they must be non-zero. - - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::DVec2) -> f64; - -"#, - r#" -/// Returns a vector that is equal to `self` rotated by 90 degrees. - - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::DVec2; - -"#, - r#" -/// The perpendicular dot product of `self` and `rhs`. -/// Also known as the wedge product, 2D cross product, and determinant. - - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::DVec2) -> f64; - -"#, - r#" -/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, -/// then this just rotation. This is what you usually want. Otherwise, -/// it will be like a rotation with a multiplication by `self`'s length. - - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f64) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f64) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct DVec2 { - x: f64, - y: f64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DVec3", - functions[r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: f64, y: f64, z: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::DVec3, - #[proxy] - if_false: bevy::math::DVec3, - ) -> bevy::math::DVec3; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 3]) -> bevy::math::DVec3; - -"#, - r#" -/// `[x, y, z]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::DVec2; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DVec3) -> f64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Component-wise clamping of values, similar to [`f64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::DVec3, - #[proxy] - max: bevy::math::DVec3, - ) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> f64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> f64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `1.0` if the number is positive, `+0.0` or `INFINITY` -/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` -/// - `NAN` if the number is `NAN` - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector with signs of `rhs` and the magnitudes of `self`. - - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. If any element is either -/// `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Performs `is_nan` on each element of self, returning a vector mask of the results. -/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. - - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec3; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f64; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is faster than `length()` as it avoids a square root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f64; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f64; - -"#, - r#" -/// Computes the Euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::DVec3) -> f64; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::DVec3) -> f64; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// [Euclidean division]: f64::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero, nor very close to zero. -/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns `self` normalized to length 1.0 if possible, else returns zero. -/// In particular, if the input is zero (or very close to zero), or non-finite, -/// the result of this operation will be zero. -/// See also [`Self::try_normalize()`]. - - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns whether `self` is length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::DVec3, - ) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::DVec3, - ) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the nearest integer to a number for each element of `self`. -/// Round half-way cases away from 0.0. - - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the largest integer less than or equal to a number for each -/// element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the smallest integer greater than or equal to a number for -/// each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the integer part each element of `self`. This means numbers are -/// always truncated towards zero. - - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the fractional part of the vector, e.g. `self - -/// self.floor()`. -/// Note that this is fast but not precise for large numbers. - - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing `e^self` (the exponential function) for each element of -/// `self`. - - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing each element of `self` raised to the power of `n`. - - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::DVec3; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result -/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly -/// extrapolated. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::DVec3, s: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` is -/// less than or equal to `max_abs_diff`. -/// This can be used to compare if two vectors contain similar elements. It works best when -/// comparing with a known value. The `max_abs_diff` that should be used used depends on -/// the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec3, max_abs_diff: f64) -> bool; - -"#, - r#" -/// Returns a vector with a length no less than `min` and no more than `max` -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector with a length no more than `max` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Returns a vector with a length no less than `min` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f64) -> bevy::math::DVec3; - -"#, - r#" -/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding -/// error, yielding a more accurate result than an unfused multiply-add. -/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target -/// architecture has a dedicated fma CPU instruction. However, this is not always true, -/// and will be heavily dependant on designing algorithms with specific target hardware in -/// mind. - - #[lua(kind = "Method", output(proxy))] - fn mul_add( - self, - #[proxy] - a: bevy::math::DVec3, - #[proxy] - b: bevy::math::DVec3, - ) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the angle (in radians) between two vectors. -/// The inputs do not need to be unit vectors however they must be non-zero. - - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::DVec3) -> f64; - -"#, - r#" -/// Returns some vector that is orthogonal to the given one. -/// The input vector must be finite and non-zero. -/// The output vector is not necessarily unit length. For that use -/// [`Self::any_orthonormal_vector()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn any_orthogonal_vector(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns any unit vector that is orthogonal to the given one. -/// The input vector must be unit length. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn any_orthonormal_vector(&self) -> bevy::math::DVec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::DVec3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f64) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f64) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f64) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct DVec3 { - x: f64, - y: f64, - z: f64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DVec4", - functions[r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f64) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f64) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f64) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::DVec4) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Creates a new vector. - - #[lua(kind = "Function", output(proxy))] - fn new(x: f64, y: f64, z: f64, w: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua(kind = "Function", output(proxy))] - fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::DVec4, - #[proxy] - if_false: bevy::math::DVec4, - ) -> bevy::math::DVec4; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 4]) -> bevy::math::DVec4; - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 4]; - -"#, - r#" -/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. -/// Truncation to [`DVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::DVec3; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DVec4) -> f64; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the maximum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Component-wise clamping of values, similar to [`f64::clamp`]. -/// Each element in `min` must be less-or-equal to the corresponding element in `max`. -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp( - self, - #[proxy] - min: bevy::math::DVec4, - #[proxy] - max: bevy::math::DVec4, - ) -> bevy::math::DVec4; - -"#, - r#" -/// Returns the horizontal minimum of `self`. -/// In other words this computes `min(x, y, ..)`. - - #[lua(kind = "Method")] - fn min_element(self) -> f64; - -"#, - r#" -/// Returns the horizontal maximum of `self`. -/// In other words this computes `max(x, y, ..)`. - - #[lua(kind = "Method")] - fn max_element(self) -> f64; - -"#, - r#" -/// Returns a vector mask containing the result of a `==` comparison for each element of -/// `self` and `rhs`. -/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `!=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `>` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<=` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector mask containing the result of a `<` comparison for each element of -/// `self` and `rhs`. -/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all -/// elements. - - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; - -"#, - r#" -/// Returns a vector containing the absolute value of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector with elements representing the sign of `self`. -/// - `1.0` if the number is positive, `+0.0` or `INFINITY` -/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` -/// - `NAN` if the number is `NAN` - - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector with signs of `rhs` and the magnitudes of `self`. - - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. -/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. If any element is either -/// `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Performs `is_nan` on each element of self, returning a vector mask of the results. -/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. - - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec4; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f64; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is faster than `length()` as it avoids a square root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f64; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f64; - -"#, - r#" -/// Computes the Euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::DVec4) -> f64; - -"#, - r#" -/// Compute the squared euclidean distance between two points in space. - - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::DVec4) -> f64; - -"#, - r#" -/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. -/// [Euclidean division]: f64::rem_euclid - - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero, nor very close to zero. -/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns `self` normalized to length 1.0 if possible, else returns zero. -/// In particular, if the input is zero (or very close to zero), or non-finite, -/// the result of this operation will be zero. -/// See also [`Self::try_normalize()`]. - - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns whether `self` is length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be of non-zero length. -/// # Panics -/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Returns the vector projection of `self` onto `rhs`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::DVec4, - ) -> bevy::math::DVec4; - -"#, - r#" -/// Returns the vector rejection of `self` from `rhs`. -/// The vector rejection is the vector perpendicular to the projection of `self` onto -/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. -/// `rhs` must be normalized. -/// # Panics -/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::DVec4, - ) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the nearest integer to a number for each element of `self`. -/// Round half-way cases away from 0.0. - - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the largest integer less than or equal to a number for each -/// element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the smallest integer greater than or equal to a number for -/// each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the integer part each element of `self`. This means numbers are -/// always truncated towards zero. - - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the fractional part of the vector, e.g. `self - -/// self.floor()`. -/// Note that this is fast but not precise for large numbers. - - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing `e^self` (the exponential function) for each element of -/// `self`. - - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing each element of `self` raised to the power of `n`. - - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::DVec4; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result -/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly -/// extrapolated. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::DVec4, s: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` is -/// less than or equal to `max_abs_diff`. -/// This can be used to compare if two vectors contain similar elements. It works best when -/// comparing with a known value. The `max_abs_diff` that should be used used depends on -/// the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec4, max_abs_diff: f64) -> bool; - -"#, - r#" -/// Returns a vector with a length no less than `min` and no more than `max` -/// # Panics -/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector with a length no more than `max` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Returns a vector with a length no less than `min` - - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f64) -> bevy::math::DVec4; - -"#, - r#" -/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding -/// error, yielding a more accurate result than an unfused multiply-add. -/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target -/// architecture has a dedicated fma CPU instruction. However, this is not always true, -/// and will be heavily dependant on designing algorithms with specific target hardware in -/// mind. - - #[lua(kind = "Method", output(proxy))] - fn mul_add( - self, - #[proxy] - a: bevy::math::DVec4, - #[proxy] - b: bevy::math::DVec4, - ) -> bevy::math::DVec4; - -"#, - r#" -/// Casts all elements of `self` to `f32`. - - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; - -"#, - r#" -/// Casts all elements of `self` to `i32`. - - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; - -"#, - r#" -/// Casts all elements of `self` to `u32`. - - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; - -"#, - r#" -/// Casts all elements of `self` to `i64`. - - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; - -"#, - r#" -/// Casts all elements of `self` to `u64`. - - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DVec4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) -} -"#, - r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? -} -"#] -)] -pub struct DVec4 { - x: f64, - y: f64, - z: f64, - w: f64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Mat2", - functions[r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; - -"#, - r#" -/// Creates a 2x2 matrix from two column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::Vec2, - #[proxy] - y_axis: bevy::math::Vec2, - ) -> bevy::math::Mat2; - -"#, - r#" -/// Creates a `[f32; 4]` array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 4]; - -"#, - r#" -/// Creates a `[[f32; 2]; 2]` 2D array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 2]; 2]; - -"#, - r#" -/// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. - - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec2) -> bevy::math::Mat2; - -"#, - r#" -/// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_scale_angle( - #[proxy] - scale: bevy::math::Vec2, - angle: f32, - ) -> bevy::math::Mat2; - -"#, - r#" -/// Creates a 2x2 matrix containing a rotation of `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Mat2; - -"#, - r#" -/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Mat2; - -"#, - r#" -/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Mat2; - -"#, - r#" -/// Returns the matrix column for the given `index`. -/// # Panics -/// Panics if `index` is greater than 1. - - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the matrix row for the given `index`. -/// # Panics -/// Panics if `index` is greater than 1. - - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec2; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns the transpose of `self`. - - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat2; - -"#, - r#" -/// Returns the determinant of `self`. - - #[lua(kind = "Method")] - fn determinant(&self) -> f32; - -"#, - r#" -/// Returns the inverse of `self`. -/// If the matrix is not invertible the returned matrix will be invalid. -/// # Panics -/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat2; - -"#, - r#" -/// Transforms a 2D vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Multiplies two 2x2 matrices. - - #[lua(kind = "Method", output(proxy))] - fn mul_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; - -"#, - r#" -/// Adds two 2x2 matrices. - - #[lua(kind = "Method", output(proxy))] - fn add_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; - -"#, - r#" -/// Subtracts two 2x2 matrices. - - #[lua(kind = "Method", output(proxy))] - fn sub_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; - -"#, - r#" -/// Multiplies a 2x2 matrix by a scalar. - - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat2; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two matrices contain similar elements. It works best -/// when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat2, max_abs_diff: f32) -> bool; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_dmat2(&self) -> bevy::math::DMat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec2::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) -} -"#] -)] -pub struct Mat2(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Mat3", - functions[r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3x3 matrix from three column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::Vec3, - #[proxy] - y_axis: bevy::math::Vec3, - #[proxy] - z_axis: bevy::math::Vec3, - ) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a `[f32; 9]` array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 9]; - -"#, - r#" -/// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 3]; 3]; - -"#, - r#" -/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. - - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec3) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. - - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3D rotation matrix from the given quaternion. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in -/// radians). -/// # Panics -/// Will panic if `axis` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in -/// radians). - - #[lua(kind = "Function", output(proxy))] - fn from_euler( - #[proxy] - order: bevy::math::EulerRot, - a: f32, - b: f32, - c: f32, - ) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Mat3; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Mat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D `translation`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Mat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D rotation `angle` (in -/// radians). -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Mat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in -/// radians) and `translation`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::Vec2, - angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Mat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. -/// # Panics -/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Mat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2x2 matrix. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] m: bevy::math::Mat2) -> bevy::math::Mat3; - -"#, - r#" -/// Returns the matrix column for the given `index`. -/// # Panics -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec3; - -"#, - r#" -/// Returns the matrix row for the given `index`. -/// # Panics -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec3; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns the transpose of `self`. - - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat3; - -"#, - r#" -/// Returns the determinant of `self`. - - #[lua(kind = "Method")] - fn determinant(&self) -> f32; - -"#, - r#" -/// Returns the inverse of `self`. -/// If the matrix is not invertible the returned matrix will be invalid. -/// # Panics -/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat3; - -"#, - r#" -/// Transforms the given 2D vector as a point. -/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Rotates the given 2D vector. -/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Transforms a 3D vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Transforms a [`Vec3A`]. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Multiplies two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn mul_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; - -"#, - r#" -/// Adds two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn add_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; - -"#, - r#" -/// Subtracts two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn sub_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; - -"#, - r#" -/// Multiplies a 3x3 matrix by a scalar. - - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat3; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two matrices contain similar elements. It works best -/// when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat3, max_abs_diff: f32) -> bool; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_dmat3(&self) -> bevy::math::DMat3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec3::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) -} -"#] -)] -pub struct Mat3 { - #[lua(output(proxy))] - x_axis: bevy::math::Vec3, - #[lua(output(proxy))] - y_axis: bevy::math::Vec3, - #[lua(output(proxy))] - z_axis: bevy::math::Vec3, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Mat3A", - functions[r#" -/// Creates a 3x3 matrix from three column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::Vec3A, - #[proxy] - y_axis: bevy::math::Vec3A, - #[proxy] - z_axis: bevy::math::Vec3A, - ) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a `[f32; 9]` array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 9]; - -"#, - r#" -/// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 3]; 3]; - -"#, - r#" -/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. - - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec3) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. - - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a 3D rotation matrix from the given quaternion. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in -/// radians). -/// # Panics -/// Will panic if `axis` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in -/// radians). - - #[lua(kind = "Function", output(proxy))] - fn from_euler( - #[proxy] - order: bevy::math::EulerRot, - a: f32, - b: f32, - c: f32, - ) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D `translation`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D rotation `angle` (in -/// radians). -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in -/// radians) and `translation`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::Vec2, - angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. -/// # Panics -/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Mat3A; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2x2 matrix. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] m: bevy::math::Mat2) -> bevy::math::Mat3A; - -"#, - r#" -/// Returns the matrix column for the given `index`. -/// # Panics -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns the matrix row for the given `index`. -/// # Panics -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns the transpose of `self`. - - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat3A; - -"#, - r#" -/// Returns the determinant of `self`. - - #[lua(kind = "Method")] - fn determinant(&self) -> f32; - -"#, - r#" -/// Returns the inverse of `self`. -/// If the matrix is not invertible the returned matrix will be invalid. -/// # Panics -/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat3A; - -"#, - r#" -/// Transforms the given 2D vector as a point. -/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Rotates the given 2D vector. -/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Transforms a 3D vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Transforms a [`Vec3A`]. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Multiplies two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn mul_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; - -"#, - r#" -/// Adds two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn add_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; - -"#, - r#" -/// Subtracts two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn sub_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; - -"#, - r#" -/// Multiplies a 3x3 matrix by a scalar. - - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat3A; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two matrices contain similar elements. It works best -/// when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat3A, max_abs_diff: f32) -> bool; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_dmat3(&self) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat3A; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat3A) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Mat3A; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec3A::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) -} -"#] -)] -pub struct Mat3A { - #[lua(output(proxy))] - x_axis: bevy::math::Vec3A, - #[lua(output(proxy))] - y_axis: bevy::math::Vec3A, - #[lua(output(proxy))] - z_axis: bevy::math::Vec3A, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Mat4", - functions[r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat4; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat4) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a 4x4 matrix from four column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::Vec4, - #[proxy] - y_axis: bevy::math::Vec4, - #[proxy] - z_axis: bevy::math::Vec4, - #[proxy] - w_axis: bevy::math::Vec4, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a `[f32; 16]` array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 16]; - -"#, - r#" -/// Creates a `[[f32; 4]; 4]` 4D array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 4]; 4]; - -"#, - r#" -/// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. - - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec4) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3D `scale`, `rotation` and -/// `translation`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3D `translation`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_translation( - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given `rotation` quaternion. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3x3 linear transformation -/// matrix. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3x3 linear transformation -/// matrix. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3D `translation`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec3) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around a normalized -/// rotation `axis` of `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `axis` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a affine transformation matrix containing a rotation from the given euler -/// rotation sequence and angles (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_euler( - #[proxy] - order: bevy::math::EulerRot, - a: f32, - b: f32, - c: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around the x axis of -/// `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around the y axis of -/// `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around the z axis of -/// `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an affine transformation matrix containing the given 3D non-uniform `scale`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec3) -> bevy::math::Mat4; - -"#, - r#" -/// Returns the matrix column for the given `index`. -/// # Panics -/// Panics if `index` is greater than 3. - - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec4; - -"#, - r#" -/// Returns the matrix row for the given `index`. -/// # Panics -/// Panics if `index` is greater than 3. - - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec4; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns the transpose of `self`. - - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat4; - -"#, - r#" -/// Returns the determinant of `self`. - - #[lua(kind = "Method")] - fn determinant(&self) -> f32; - -"#, - r#" -/// Returns the inverse of `self`. -/// If the matrix is not invertible the returned matrix will be invalid. -/// # Panics -/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a left-handed view matrix using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a right-handed view matrix using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a left-handed view matrix using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a right-handed view matrix using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a right-handed perspective projection matrix with [-1,1] depth range. -/// This is the same as the OpenGL `gluPerspective` function. -/// See - - #[lua(kind = "Function", output(proxy))] - fn perspective_rh_gl( - fov_y_radians: f32, - aspect_ratio: f32, - z_near: f32, - z_far: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a left-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is -/// enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_lh( - fov_y_radians: f32, - aspect_ratio: f32, - z_near: f32, - z_far: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a right-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is -/// enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_rh( - fov_y_radians: f32, - aspect_ratio: f32, - z_near: f32, - z_far: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_lh( - fov_y_radians: f32, - aspect_ratio: f32, - z_near: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_reverse_lh( - fov_y_radians: f32, - aspect_ratio: f32, - z_near: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an infinite right-handed perspective projection matrix with -/// `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_rh( - fov_y_radians: f32, - aspect_ratio: f32, - z_near: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates an infinite reverse right-handed perspective projection matrix -/// with `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_reverse_rh( - fov_y_radians: f32, - aspect_ratio: f32, - z_near: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a right-handed orthographic projection matrix with `[-1,1]` depth -/// range. This is the same as the OpenGL `glOrtho` function in OpenGL. -/// See -/// - - #[lua(kind = "Function", output(proxy))] - fn orthographic_rh_gl( - left: f32, - right: f32, - bottom: f32, - top: f32, - near: f32, - far: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn orthographic_lh( - left: f32, - right: f32, - bottom: f32, - top: f32, - near: f32, - far: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn orthographic_rh( - left: f32, - right: f32, - bottom: f32, - top: f32, - near: f32, - far: f32, - ) -> bevy::math::Mat4; - -"#, - r#" -/// Transforms the given 3D vector as a point, applying perspective correction. -/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. -/// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. -/// This method assumes that `self` contains a projective transform. - - #[lua(kind = "Method", output(proxy))] - fn project_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Transforms the given 3D vector as a point. -/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is -/// `1.0`. -/// This method assumes that `self` contains a valid affine transform. It does not perform -/// a persective divide, if `self` contains a perspective transform, or if you are unsure, -/// the [`Self::project_point3()`] method should be used instead. -/// # Panics -/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Transforms the give 3D vector as a direction. -/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is -/// `0.0`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Transforms the given [`Vec3A`] as 3D point. -/// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `1.0`. - - #[lua(kind = "Method", output(proxy))] - fn transform_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Transforms the give [`Vec3A`] as 3D vector. -/// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `0.0`. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Transforms a 4D vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec4(&self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; - -"#, - r#" -/// Multiplies two 4x4 matrices. - - #[lua(kind = "Method", output(proxy))] - fn mul_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; - -"#, - r#" -/// Adds two 4x4 matrices. - - #[lua(kind = "Method", output(proxy))] - fn add_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; - -"#, - r#" -/// Subtracts two 4x4 matrices. - - #[lua(kind = "Method", output(proxy))] - fn sub_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; - -"#, - r#" -/// Multiplies a 4x4 matrix by a scalar. - - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat4; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two matrices contain similar elements. It works best -/// when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat4, max_abs_diff: f32) -> bool; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_dmat4(&self) -> bevy::math::DMat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine3A) -> bevy::math::Mat4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec4::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) -} -"#] -)] -pub struct Mat4 { - #[lua(output(proxy))] - x_axis: bevy::math::Vec4, - #[lua(output(proxy))] - y_axis: bevy::math::Vec4, - #[lua(output(proxy))] - z_axis: bevy::math::Vec4, - #[lua(output(proxy))] - w_axis: bevy::math::Vec4, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DMat2", - functions[r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DMat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DMat2; - -"#, - r#" -/// Creates a 2x2 matrix from two column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::DVec2, - #[proxy] - y_axis: bevy::math::DVec2, - ) -> bevy::math::DMat2; - -"#, - r#" -/// Creates a `[f64; 4]` array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 4]; - -"#, - r#" -/// Creates a `[[f64; 2]; 2]` 2D array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 2]; 2]; - -"#, - r#" -/// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. - - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::DVec2) -> bevy::math::DMat2; - -"#, - r#" -/// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_scale_angle( - #[proxy] - scale: bevy::math::DVec2, - angle: f64, - ) -> bevy::math::DMat2; - -"#, - r#" -/// Creates a 2x2 matrix containing a rotation of `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DMat2; - -"#, - r#" -/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DMat2; - -"#, - r#" -/// Returns the matrix column for the given `index`. -/// # Panics -/// Panics if `index` is greater than 1. - - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::DVec2; - -"#, - r#" -/// Returns the matrix row for the given `index`. -/// # Panics -/// Panics if `index` is greater than 1. - - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::DVec2; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns the transpose of `self`. - - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::DMat2; - -"#, - r#" -/// Returns the determinant of `self`. - - #[lua(kind = "Method")] - fn determinant(&self) -> f64; - -"#, - r#" -/// Returns the inverse of `self`. -/// If the matrix is not invertible the returned matrix will be invalid. -/// # Panics -/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DMat2; - -"#, - r#" -/// Transforms a 2D vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Multiplies two 2x2 matrices. - - #[lua(kind = "Method", output(proxy))] - fn mul_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; - -"#, - r#" -/// Adds two 2x2 matrices. - - #[lua(kind = "Method", output(proxy))] - fn add_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; - -"#, - r#" -/// Subtracts two 2x2 matrices. - - #[lua(kind = "Method", output(proxy))] - fn sub_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; - -"#, - r#" -/// Multiplies a 2x2 matrix by a scalar. - - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat2; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two matrices contain similar elements. It works best -/// when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat2, max_abs_diff: f64) -> bool; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_mat2(&self) -> bevy::math::Mat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DMat2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DMat2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaDVec2::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) -} -"#] -)] -pub struct DMat2 { - #[lua(output(proxy))] - x_axis: bevy::math::DVec2, - #[lua(output(proxy))] - y_axis: bevy::math::DVec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DMat3", - functions[r#" -/// Creates a 3x3 matrix from three column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::DVec3, - #[proxy] - y_axis: bevy::math::DVec3, - #[proxy] - z_axis: bevy::math::DVec3, - ) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a `[f64; 9]` array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 9]; - -"#, - r#" -/// Creates a `[[f64; 3]; 3]` 3D array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 3]; 3]; - -"#, - r#" -/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. - - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::DVec3) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. - - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::DMat4) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a 3D rotation matrix from the given quaternion. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in -/// radians). -/// # Panics -/// Will panic if `axis` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, - angle: f64, - ) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in -/// radians). - - #[lua(kind = "Function", output(proxy))] - fn from_euler( - #[proxy] - order: bevy::math::EulerRot, - a: f64, - b: f64, - c: f64, - ) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DMat3; - -"#, - r#" -/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DMat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D `translation`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec2) -> bevy::math::DMat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D rotation `angle` (in -/// radians). -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DMat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in -/// radians) and `translation`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::DVec2, - angle: f64, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DMat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. -/// # Panics -/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec2) -> bevy::math::DMat3; - -"#, - r#" -/// Creates an affine transformation matrix from the given 2x2 matrix. -/// The resulting matrix can be used to transform 2D points and vectors. See -/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] m: bevy::math::DMat2) -> bevy::math::DMat3; - -"#, - r#" -/// Returns the matrix column for the given `index`. -/// # Panics -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the matrix row for the given `index`. -/// # Panics -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::DVec3; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns the transpose of `self`. - - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::DMat3; - -"#, - r#" -/// Returns the determinant of `self`. - - #[lua(kind = "Method")] - fn determinant(&self) -> f64; - -"#, - r#" -/// Returns the inverse of `self`. -/// If the matrix is not invertible the returned matrix will be invalid. -/// # Panics -/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DMat3; - -"#, - r#" -/// Transforms the given 2D vector as a point. -/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Rotates the given 2D vector. -/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Transforms a 3D vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Multiplies two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn mul_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; - -"#, - r#" -/// Adds two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn add_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; - -"#, - r#" -/// Subtracts two 3x3 matrices. - - #[lua(kind = "Method", output(proxy))] - fn sub_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; - -"#, - r#" -/// Multiplies a 3x3 matrix by a scalar. - - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat3; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two matrices contain similar elements. It works best -/// when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat3, max_abs_diff: f64) -> bool; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_mat3(&self) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine2) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DMat3) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaDVec3::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) -} -"#] -)] -pub struct DMat3 { - #[lua(output(proxy))] - x_axis: bevy::math::DVec3, - #[lua(output(proxy))] - y_axis: bevy::math::DVec3, - #[lua(output(proxy))] - z_axis: bevy::math::DVec3, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DMat4", - functions[r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine3) -> bevy::math::DMat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DMat4) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DMat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a 4x4 matrix from four column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::DVec4, - #[proxy] - y_axis: bevy::math::DVec4, - #[proxy] - z_axis: bevy::math::DVec4, - #[proxy] - w_axis: bevy::math::DVec4, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a `[f64; 16]` array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 16]; - -"#, - r#" -/// Creates a `[[f64; 4]; 4]` 4D array storing data in column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 4]; 4]; - -"#, - r#" -/// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. - - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::DVec4) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3D `scale`, `rotation` and -/// `translation`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::DVec3, - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3D `translation`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_translation( - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given `rotation` quaternion. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3x3 linear transformation -/// matrix. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix from the given 3D `translation`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec3) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around a normalized -/// rotation `axis` of `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if `axis` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, - angle: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a affine transformation matrix containing a rotation from the given euler -/// rotation sequence and angles (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_euler( - #[proxy] - order: bevy::math::EulerRot, - a: f64, - b: f64, - c: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around the x axis of -/// `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around the y axis of -/// `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix containing a 3D rotation around the z axis of -/// `angle` (in radians). -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transformation matrix containing the given 3D non-uniform `scale`. -/// The resulting matrix can be used to transform 3D points and vectors. See -/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. -/// # Panics -/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec3) -> bevy::math::DMat4; - -"#, - r#" -/// Returns the matrix column for the given `index`. -/// # Panics -/// Panics if `index` is greater than 3. - - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::DVec4; - -"#, - r#" -/// Returns the matrix row for the given `index`. -/// # Panics -/// Panics if `index` is greater than 3. - - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::DVec4; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns the transpose of `self`. - - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::DMat4; - -"#, - r#" -/// Returns the determinant of `self`. - - #[lua(kind = "Method")] - fn determinant(&self) -> f64; - -"#, - r#" -/// Returns the inverse of `self`. -/// If the matrix is not invertible the returned matrix will be invalid. -/// # Panics -/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a left-handed view matrix using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a right-handed view matrix using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a left-handed view matrix using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a right-handed view matrix using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a right-handed perspective projection matrix with [-1,1] depth range. -/// This is the same as the OpenGL `gluPerspective` function. -/// See - - #[lua(kind = "Function", output(proxy))] - fn perspective_rh_gl( - fov_y_radians: f64, - aspect_ratio: f64, - z_near: f64, - z_far: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a left-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is -/// enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_lh( - fov_y_radians: f64, - aspect_ratio: f64, - z_near: f64, - z_far: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a right-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is -/// enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_rh( - fov_y_radians: f64, - aspect_ratio: f64, - z_near: f64, - z_far: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_lh( - fov_y_radians: f64, - aspect_ratio: f64, - z_near: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. -/// # Panics -/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_reverse_lh( - fov_y_radians: f64, - aspect_ratio: f64, - z_near: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an infinite right-handed perspective projection matrix with -/// `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_rh( - fov_y_radians: f64, - aspect_ratio: f64, - z_near: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an infinite reverse right-handed perspective projection matrix -/// with `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn perspective_infinite_reverse_rh( - fov_y_radians: f64, - aspect_ratio: f64, - z_near: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a right-handed orthographic projection matrix with `[-1,1]` depth -/// range. This is the same as the OpenGL `glOrtho` function in OpenGL. -/// See -/// - - #[lua(kind = "Function", output(proxy))] - fn orthographic_rh_gl( - left: f64, - right: f64, - bottom: f64, - top: f64, - near: f64, - far: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn orthographic_lh( - left: f64, - right: f64, - bottom: f64, - top: f64, - near: f64, - far: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. - - #[lua(kind = "Function", output(proxy))] - fn orthographic_rh( - left: f64, - right: f64, - bottom: f64, - top: f64, - near: f64, - far: f64, - ) -> bevy::math::DMat4; - -"#, - r#" -/// Transforms the given 3D vector as a point, applying perspective correction. -/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. -/// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. -/// This method assumes that `self` contains a projective transform. - - #[lua(kind = "Method", output(proxy))] - fn project_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Transforms the given 3D vector as a point. -/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is -/// `1.0`. -/// This method assumes that `self` contains a valid affine transform. It does not perform -/// a persective divide, if `self` contains a perspective transform, or if you are unsure, -/// the [`Self::project_point3()`] method should be used instead. -/// # Panics -/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Transforms the give 3D vector as a direction. -/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is -/// `0.0`. -/// This method assumes that `self` contains a valid affine transform. -/// # Panics -/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Transforms a 4D vector. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec4(&self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; - -"#, - r#" -/// Multiplies two 4x4 matrices. - - #[lua(kind = "Method", output(proxy))] - fn mul_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; - -"#, - r#" -/// Adds two 4x4 matrices. - - #[lua(kind = "Method", output(proxy))] - fn add_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; - -"#, - r#" -/// Subtracts two 4x4 matrices. - - #[lua(kind = "Method", output(proxy))] - fn sub_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; - -"#, - r#" -/// Multiplies a 4x4 matrix by a scalar. - - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat4; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two matrices contain similar elements. It works best -/// when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat4, max_abs_diff: f64) -> bool; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_mat4(&self) -> bevy::math::Mat4; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DMat4; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DMat4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#, - r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaDVec4::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) -} -"#] -)] -pub struct DMat4 { - #[lua(output(proxy))] - x_axis: bevy::math::DVec4, - #[lua(output(proxy))] - y_axis: bevy::math::DVec4, - #[lua(output(proxy))] - z_axis: bevy::math::DVec4, - #[lua(output(proxy))] - w_axis: bevy::math::DVec4, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Affine2", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Affine2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Affine2) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Affine2; - -"#, - r#" -/// Creates an affine transform from three column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::Vec2, - #[proxy] - y_axis: bevy::math::Vec2, - #[proxy] - z_axis: bevy::math::Vec2, - ) -> bevy::math::Affine2; - -"#, - r#" -/// Creates a `[f32; 6]` array storing data in column major order. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 6]; - -"#, - r#" -/// Creates a `[[f32; 2]; 3]` 2D array storing data in -/// column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 2]; 3]; - -"#, - r#" -/// Creates an affine transform that changes scale. -/// Note that if any scale is zero the transform will be non-invertible. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Affine2; - -"#, - r#" -/// Creates an affine transform from the given rotation `angle`. - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Affine2; - -"#, - r#" -/// Creates an affine transformation from the given 2D `translation`. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Affine2; - -"#, - r#" -/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) - - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] matrix2: bevy::math::Mat2) -> bevy::math::Affine2; - -"#, - r#" -/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a -/// translation vector. -/// Equivalent to -/// `Affine2::from_translation(translation) * Affine2::from_mat2(mat2)` - - #[lua(kind = "Function", output(proxy))] - fn from_mat2_translation( - #[proxy] - matrix2: bevy::math::Mat2, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Affine2; - -"#, - r#" -/// Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and -/// `translation`. -/// Equivalent to `Affine2::from_translation(translation) * -/// Affine2::from_angle(angle) * Affine2::from_scale(scale)` - - #[lua(kind = "Function", output(proxy))] - fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::Vec2, - angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Affine2; - -"#, - r#" -/// Creates an affine transform from the given 2D rotation `angle` (in radians) and -/// `translation`. -/// Equivalent to `Affine2::from_translation(translation) * Affine2::from_angle(angle)` - - #[lua(kind = "Function", output(proxy))] - fn from_angle_translation( - angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Affine2; - -"#, - r#" -/// The given `Mat3` must be an affine transform, - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Affine2; - -"#, - r#" -/// The given [`Mat3A`] must be an affine transform, - - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Affine2; - -"#, - r#" -/// Transforms the given 2D point, applying shear, scale, rotation and translation. - - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Transforms the given 2D vector, applying shear, scale and rotation (but NOT -/// translation). -/// To also apply translation, use [`Self::transform_point2()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return -/// `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two 3x4 matrices contain similar elements. It works -/// best when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Affine2, max_abs_diff: f32) -> bool; - -"#, - r#" -/// Return the inverse of this transform. -/// Note that if the transform is not invertible the result will be invalid. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Affine2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct Affine2 { - #[lua(output(proxy))] - matrix2: bevy::math::Mat2, - #[lua(output(proxy))] - translation: bevy::math::Vec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Affine3A", - functions[r#" -/// Creates an affine transform from three column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::Vec3A, - #[proxy] - y_axis: bevy::math::Vec3A, - #[proxy] - z_axis: bevy::math::Vec3A, - #[proxy] - w_axis: bevy::math::Vec3A, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates a `[f32; 12]` array storing data in column major order. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 12]; - -"#, - r#" -/// Creates a `[[f32; 3]; 4]` 3D array storing data in -/// column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 3]; 4]; - -"#, - r#" -/// Creates an affine transform that changes scale. -/// Note that if any scale is zero the transform will be non-invertible. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec3) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform from the given `rotation` quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around a normalized -/// rotation `axis` of `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle( - #[proxy] - axis: bevy::math::Vec3, - angle: f32, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around the x axis of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around the y axis of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around the z axis of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transformation from the given 3D `translation`. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec3) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and -/// rotation) - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat3: bevy::math::Mat3) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) -/// and a translation vector. -/// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_mat3(mat3)` - - #[lua(kind = "Function", output(proxy))] - fn from_mat3_translation( - #[proxy] - mat3: bevy::math::Mat3, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform from the given 3D `scale`, `rotation` and -/// `translation`. -/// Equivalent to `Affine3A::from_translation(translation) * -/// Affine3A::from_quat(rotation) * Affine3A::from_scale(scale)` - - #[lua(kind = "Function", output(proxy))] - fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates an affine transform from the given 3D `rotation` and `translation`. -/// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_quat(rotation)` - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_translation( - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// The given `Mat4` must be an affine transform, -/// i.e. contain no perspective transform. - - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates a left-handed view transform using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates a right-handed view transform using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates a left-handed view transform using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Creates a right-handed view transform using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; - -"#, - r#" -/// Transforms the given 3D points, applying shear, scale, rotation and translation. - - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Transforms the given 3D vector, applying shear, scale and rotation (but NOT -/// translation). -/// To also apply translation, use [`Self::transform_point3()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Transforms the given [`Vec3A`], applying shear, scale, rotation and translation. - - #[lua(kind = "Method", output(proxy))] - fn transform_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Transforms the given [`Vec3A`], applying shear, scale and rotation (but NOT -/// translation). -/// To also apply translation, use [`Self::transform_point3a()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return -/// `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two 3x4 matrices contain similar elements. It works -/// best when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Affine3A, max_abs_diff: f32) -> bool; - -"#, - r#" -/// Return the inverse of this transform. -/// Note that if the transform is not invertible the result will be invalid. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Affine3A; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Affine3A) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Affine3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine3A) -> bevy::math::Affine3A; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct Affine3A { - #[lua(output(proxy))] - matrix3: bevy::math::Mat3A, - #[lua(output(proxy))] - translation: bevy::math::Vec3A, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DAffine2", - functions[r#" -/// Creates an affine transform from three column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::DVec2, - #[proxy] - y_axis: bevy::math::DVec2, - #[proxy] - z_axis: bevy::math::DVec2, - ) -> bevy::math::DAffine2; - -"#, - r#" -/// Creates a `[f64; 6]` array storing data in column major order. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 6]; - -"#, - r#" -/// Creates a `[[f64; 2]; 3]` 2D array storing data in -/// column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 2]; 3]; - -"#, - r#" -/// Creates an affine transform that changes scale. -/// Note that if any scale is zero the transform will be non-invertible. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec2) -> bevy::math::DAffine2; - -"#, - r#" -/// Creates an affine transform from the given rotation `angle`. - - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DAffine2; - -"#, - r#" -/// Creates an affine transformation from the given 2D `translation`. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec2) -> bevy::math::DAffine2; - -"#, - r#" -/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) - - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] matrix2: bevy::math::DMat2) -> bevy::math::DAffine2; - -"#, - r#" -/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a -/// translation vector. -/// Equivalent to -/// `DAffine2::from_translation(translation) * DAffine2::from_mat2(mat2)` - - #[lua(kind = "Function", output(proxy))] - fn from_mat2_translation( - #[proxy] - matrix2: bevy::math::DMat2, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DAffine2; - -"#, - r#" -/// Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and -/// `translation`. -/// Equivalent to `DAffine2::from_translation(translation) * -/// DAffine2::from_angle(angle) * DAffine2::from_scale(scale)` - - #[lua(kind = "Function", output(proxy))] - fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::DVec2, - angle: f64, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DAffine2; - -"#, - r#" -/// Creates an affine transform from the given 2D rotation `angle` (in radians) and -/// `translation`. -/// Equivalent to `DAffine2::from_translation(translation) * DAffine2::from_angle(angle)` - - #[lua(kind = "Function", output(proxy))] - fn from_angle_translation( - angle: f64, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DAffine2; - -"#, - r#" -/// The given `DMat3` must be an affine transform, - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DAffine2; - -"#, - r#" -/// Transforms the given 2D point, applying shear, scale, rotation and translation. - - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Transforms the given 2D vector, applying shear, scale and rotation (but NOT -/// translation). -/// To also apply translation, use [`Self::transform_point2()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return -/// `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two 3x4 matrices contain similar elements. It works -/// best when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DAffine2, max_abs_diff: f64) -> bool; - -"#, - r#" -/// Return the inverse of this transform. -/// Note that if the transform is not invertible the result will be invalid. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DAffine2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DAffine2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine2) -> bevy::math::DAffine2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DAffine2) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct DAffine2 { - #[lua(output(proxy))] - matrix2: bevy::math::DMat2, - #[lua(output(proxy))] - translation: bevy::math::DVec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DAffine3", - functions[r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; - -"#, - r#" -/// Creates an affine transform from three column vectors. - - #[lua(kind = "Function", output(proxy))] - fn from_cols( - #[proxy] - x_axis: bevy::math::DVec3, - #[proxy] - y_axis: bevy::math::DVec3, - #[proxy] - z_axis: bevy::math::DVec3, - #[proxy] - w_axis: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates a `[f64; 12]` array storing data in column major order. - - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 12]; - -"#, - r#" -/// Creates a `[[f64; 3]; 4]` 3D array storing data in -/// column major order. -/// If you require data in row major order `transpose` the matrix first. - - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 3]; 4]; - -"#, - r#" -/// Creates an affine transform that changes scale. -/// Note that if any scale is zero the transform will be non-invertible. - - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec3) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform from the given `rotation` quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around a normalized -/// rotation `axis` of `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, - angle: f64, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around the x axis of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around the y axis of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform containing a 3D rotation around the z axis of -/// `angle` (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transformation from the given 3D `translation`. - - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec3) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and -/// rotation) - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat3: bevy::math::DMat3) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) -/// and a translation vector. -/// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` - - #[lua(kind = "Function", output(proxy))] - fn from_mat3_translation( - #[proxy] - mat3: bevy::math::DMat3, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform from the given 3D `scale`, `rotation` and -/// `translation`. -/// Equivalent to `DAffine3::from_translation(translation) * -/// DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` - - #[lua(kind = "Function", output(proxy))] - fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::DVec3, - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates an affine transform from the given 3D `rotation` and `translation`. -/// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_translation( - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// The given `DMat4` must be an affine transform, -/// i.e. contain no perspective transform. - - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::DMat4) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates a left-handed view transform using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates a right-handed view transform using a camera position, an up direction, and a facing -/// direction. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - - #[lua(kind = "Function", output(proxy))] - fn look_to_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates a left-handed view transform using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Creates a right-handed view transform using a camera position, an up direction, and a focal -/// point. -/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. -/// # Panics -/// Will panic if `up` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn look_at_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; - -"#, - r#" -/// Transforms the given 3D points, applying shear, scale, rotation and translation. - - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Transforms the given 3D vector, applying shear, scale and rotation (but NOT -/// translation). -/// To also apply translation, use [`Self::transform_point3()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return -/// `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Returns `true` if any elements are `NaN`. - - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two 3x4 matrices contain similar elements. It works -/// best when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DAffine3, max_abs_diff: f64) -> bool; - -"#, - r#" -/// Return the inverse of this transform. -/// Note that if the transform is not invertible the result will be invalid. - - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DAffine3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine3) -> bevy::math::DAffine3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DAffine3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DAffine3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct DAffine3 { - #[lua(output(proxy))] - matrix3: bevy::math::DMat3, - #[lua(output(proxy))] - translation: bevy::math::DVec3, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::DQuat", - functions[r#" -/// Creates a new rotation quaternion. -/// This should generally not be called manually unless you know what you are doing. -/// Use one of the other constructors instead such as `identity` or `from_axis_angle`. -/// `from_xyzw` is mostly used by unit tests and `serde` deserialization. -/// # Preconditions -/// This function does not check if the input is normalized, it is up to the user to -/// provide normalized input or to normalized the resulting quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_xyzw(x: f64, y: f64, z: f64, w: f64) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a rotation quaternion from an array. -/// # Preconditions -/// This function does not check if the input is normalized, it is up to the user to -/// provide normalized input or to normalized the resulting quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 4]) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a new rotation quaternion from a 4D vector. -/// # Preconditions -/// This function does not check if the input is normalized, it is up to the user to -/// provide normalized input or to normalized the resulting quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_vec4(#[proxy] v: bevy::math::DVec4) -> bevy::math::DQuat; - -"#, - r#" -/// Create a quaternion for a normalized rotation `axis` and `angle` (in radians). -/// The axis must be a unit vector. -/// # Panics -/// Will panic if `axis` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, - angle: f64, - ) -> bevy::math::DQuat; - -"#, - r#" -/// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. -/// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. - - #[lua(kind = "Function", output(proxy))] - fn from_scaled_axis(#[proxy] v: bevy::math::DVec3) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a quaternion from the `angle` (in radians) around the x axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a quaternion from the `angle` (in radians) around the y axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a quaternion from the `angle` (in radians) around the z axis. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). - - #[lua(kind = "Function", output(proxy))] - fn from_euler( - #[proxy] - euler: bevy::math::EulerRot, - a: f64, - b: f64, - c: f64, - ) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a quaternion from a 3x3 rotation matrix. - - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat: &glam::DMat3) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. - - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] mat: &glam::DMat4) -> bevy::math::DQuat; - -"#, - r#" -/// Gets the minimal rotation for transforming `from` to `to`. The rotation is in the -/// plane spanned by the two vectors. Will rotate at most 180 degrees. -/// The inputs must be unit vectors. -/// `from_rotation_arc(from, to) * from ≈ to`. -/// For near-singular cases (from≈to and from≈-to) the current implementation -/// is only accurate to about 0.001 (for `f32`). -/// # Panics -/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_arc( - #[proxy] - from: bevy::math::DVec3, - #[proxy] - to: bevy::math::DVec3, - ) -> bevy::math::DQuat; - -"#, - r#" -/// Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means -/// that the resulting quaternion will rotate `from` so that it is colinear with `to`. -/// The rotation is in the plane spanned by the two vectors. Will rotate at most 90 -/// degrees. -/// The inputs must be unit vectors. -/// `to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. -/// # Panics -/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_arc_colinear( - #[proxy] - from: bevy::math::DVec3, - #[proxy] - to: bevy::math::DVec3, - ) -> bevy::math::DQuat; - -"#, - r#" -/// Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is -/// around the z axis. Will rotate at most 180 degrees. -/// The inputs must be unit vectors. -/// `from_rotation_arc_2d(from, to) * from ≈ to`. -/// For near-singular cases (from≈to and from≈-to) the current implementation -/// is only accurate to about 0.001 (for `f32`). -/// # Panics -/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation_arc_2d( - #[proxy] - from: bevy::math::DVec2, - #[proxy] - to: bevy::math::DVec2, - ) -> bevy::math::DQuat; - -"#, - r#" -/// Returns the rotation axis scaled by the rotation in radians. - - #[lua(kind = "Method", output(proxy))] - fn to_scaled_axis(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the rotation angles for the given euler rotation sequence. - - #[lua(kind = "Method")] - fn to_euler(self, #[proxy] euler: bevy::math::EulerRot) -> (f64, f64, f64); - -"#, - r#" -/// `[x, y, z, w]` - - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 4]; - -"#, - r#" -/// Returns the vector part of the quaternion. - - #[lua(kind = "Method", output(proxy))] - fn xyz(self) -> bevy::math::DVec3; - -"#, - r#" -/// Returns the quaternion conjugate of `self`. For a unit quaternion the -/// conjugate is also the inverse. - - #[lua(kind = "Method", output(proxy))] - fn conjugate(self) -> bevy::math::DQuat; - -"#, - r#" -/// Returns the inverse of a normalized quaternion. -/// Typically quaternion inverse returns the conjugate of a normalized quaternion. -/// Because `self` is assumed to already be unit length this method *does not* normalize -/// before returning the conjugate. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn inverse(self) -> bevy::math::DQuat; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. The dot product is -/// equal to the cosine of the angle between two quaternion rotations. - - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DQuat) -> f64; - -"#, - r#" -/// Computes the length of `self`. - - #[lua(kind = "Method")] - fn length(self) -> f64; - -"#, - r#" -/// Computes the squared length of `self`. -/// This is generally faster than `length()` as it avoids a square -/// root operation. - - #[lua(kind = "Method")] - fn length_squared(self) -> f64; - -"#, - r#" -/// Computes `1.0 / length()`. -/// For valid results, `self` must _not_ be of length zero. - - #[lua(kind = "Method")] - fn length_recip(self) -> f64; - -"#, - r#" -/// Returns `self` normalized to length 1.0. -/// For valid results, `self` must _not_ be of length zero. -/// Panics -/// Will panic if `self` is zero length when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DQuat; - -"#, - r#" -/// Returns `true` if, and only if, all elements are finite. -/// If any element is either `NaN`, positive or negative infinity, this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(self) -> bool; - -"#, - r#" - - #[lua(kind = "Method")] - fn is_nan(self) -> bool; - -"#, - r#" -/// Returns whether `self` of length `1.0` or not. -/// Uses a precision threshold of `1e-6`. - - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; - -"#, - r#" - - #[lua(kind = "Method")] - fn is_near_identity(self) -> bool; - -"#, - r#" -/// Returns the angle (in radians) for the minimal rotation -/// for transforming this quaternion into another. -/// Both quaternions must be normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::DQuat) -> f64; - -"#, - r#" -/// Returns true if the absolute difference of all elements between `self` and `rhs` -/// is less than or equal to `max_abs_diff`. -/// This can be used to compare if two quaternions contain similar elements. It works -/// best when comparing with a known value. The `max_abs_diff` that should be used used -/// depends on the values being compared against. -/// For more see -/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DQuat, max_abs_diff: f64) -> bool; - -"#, - r#" -/// Performs a linear interpolation between `self` and `rhs` based on -/// the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` -/// is `1.0`, the result will be equal to `rhs`. -/// # Panics -/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] end: bevy::math::DQuat, s: f64) -> bevy::math::DQuat; - -"#, - r#" -/// Performs a spherical linear interpolation between `self` and `end` -/// based on the value `s`. -/// When `s` is `0.0`, the result will be equal to `self`. When `s` -/// is `1.0`, the result will be equal to `end`. -/// # Panics -/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn slerp(self, #[proxy] end: bevy::math::DQuat, s: f64) -> bevy::math::DQuat; - -"#, - r#" -/// Multiplies a quaternion and a 3D vector, returning the rotated vector. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Multiplies two quaternions. If they each represent a rotation, the result will -/// represent the combined rotation. -/// Note that due to floating point rounding the result may not be perfectly normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - - #[lua(kind = "Method", output(proxy))] - fn mul_quat(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; - -"#, - r#" -/// Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. - - #[lua(kind = "Function", output(proxy))] - fn from_affine3(#[proxy] a: &glam::DAffine3) -> bevy::math::DQuat; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_quat(self) -> bevy::math::Quat; - -"#, - r#" - - #[lua(kind = "Method", output(proxy))] - fn as_f32(self) -> bevy::math::Quat; - -"#, - r#" -/// Divides a quaternion by a scalar value. -/// The quotient is not guaranteed to be normalized. - - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DQuat; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DQuat; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DQuat) -> bool; - -"#, - r#" -/// Adds two quaternions. -/// The sum is not guaranteed to be normalized. -/// Note that addition is not the same as combining the rotations represented by the -/// two quaternions! That corresponds to multiplication. - - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DQuat; - -"#, - r#" -/// Multiplies a quaternion by a scalar value. -/// The product is not guaranteed to be normalized. - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DQuat; - -"#, - r#" -/// Subtracts the `rhs` quaternion from `self`. -/// The difference is not guaranteed to be normalized. - - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; - -"#, - r#" -/// Multiplies a quaternion and a 3D vector, returning the rotated vector. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; - -"#, - r#" -/// Multiplies two quaternions. If they each represent a rotation, the result will -/// represent the combined rotation. -/// Note that due to floating point rounding the result may not be perfectly -/// normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct DQuat { - x: f64, - y: f64, - z: f64, - w: f64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::EulerRot", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::EulerRot; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::EulerRot) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct EulerRot {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::BVec3A", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::BVec3A) -> bool; - -"#, - r#" -/// Creates a new vector mask. - - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool) -> bevy::math::BVec3A; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec3A; - -"#, - r#" -/// Returns a bitmask with the lowest 3 bits set from the elements of `self`. -/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn bitmask(self) -> u32; - -"#, - r#" -/// Returns true if any of the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn any(self) -> bool; - -"#, - r#" -/// Returns true if all the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn all(self) -> bool; - -"#, - r#" -/// Tests the value at `index`. -/// Panics if `index` is greater than 2. - - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; - -"#, - r#" -/// Sets the element at `index`. -/// Panics if `index` is greater than 2. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec3A; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct BVec3A(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::BVec4A", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec4A; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::BVec4A) -> bool; - -"#, - r#" -/// Creates a new vector mask. - - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool, w: bool) -> bevy::math::BVec4A; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec4A; - -"#, - r#" -/// Returns a bitmask with the lowest 4 bits set from the elements of `self`. -/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes -/// into the first lowest bit, element `y` into the second, etc. - - #[lua(kind = "Method")] - fn bitmask(self) -> u32; - -"#, - r#" -/// Returns true if any of the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn any(self) -> bool; - -"#, - r#" -/// Returns true if all the elements are true, false otherwise. - - #[lua(kind = "Method")] - fn all(self) -> bool; - -"#, - r#" -/// Tests the value at `index`. -/// Panics if `index` is greater than 3. - - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; - -"#, - r#" -/// Sets the element at `index`. -/// Panics if `index` is greater than 3. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct BVec4A(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Direction2d", - functions[r#" -/// Create a [`Direction2d`] from a [`Vec2`] that is already normalized. -/// # Warning -/// `value` must be normalized, i.e it's length must be `1.0`. - - #[lua(kind = "Function", output(proxy))] - fn new_unchecked( - #[proxy] - value: bevy::math::Vec2, - ) -> bevy::math::primitives::Direction2d; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Direction2d; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::primitives::Direction2d; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Direction2d) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Direction2d(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Circle", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Circle; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Circle) -> bool; - -"#, - r#" -/// Create a new [`Circle`] from a `radius` - - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32) -> bevy::math::primitives::Circle; - -"#, - r#" -/// Get the diameter of the circle - - #[lua(kind = "Method")] - fn diameter(&self) -> f32; - -"#, - r#" -/// Get the area of the circle - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the perimeter or circumference of the circle - - #[lua(kind = "Method")] - fn perimeter(&self) -> f32; - -"#, - r#" -/// Finds the point on the circle that is closest to the given `point`. -/// If the point is outside the circle, the returned point will be on the perimeter of the circle. -/// Otherwise, it will be inside the circle and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point(&self, #[proxy] point: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Circle { - radius: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Ellipse", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Ellipse) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Ellipse; - -"#, - r#" -/// Create a new `Ellipse` from half of its width and height. -/// This corresponds to the two perpendicular radii defining the ellipse. - - #[lua(kind = "Function", output(proxy))] - fn new(half_width: f32, half_height: f32) -> bevy::math::primitives::Ellipse; - -"#, - r#" -/// Create a new `Ellipse` from a given full size. -/// `size.x` is the diameter along the X axis, and `size.y` is the diameter along the Y axis. - - #[lua(kind = "Function", output(proxy))] - fn from_size(#[proxy] size: bevy::math::Vec2) -> bevy::math::primitives::Ellipse; - -"#, - r#" -/// Returns the length of the semi-major axis. This corresponds to the longest radius of the ellipse. - - #[lua(kind = "Method")] - fn semi_major(self) -> f32; - -"#, - r#" -/// Returns the length of the semi-minor axis. This corresponds to the shortest radius of the ellipse. - - #[lua(kind = "Method")] - fn semi_minor(self) -> f32; - -"#, - r#" -/// Get the area of the ellipse - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Ellipse { - #[lua(output(proxy))] - half_size: bevy::math::Vec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Plane2d", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Plane2d; - -"#, - r#" -/// Create a new `Plane2d` from a normal -/// # Panics -/// Panics if the given `normal` is zero (or very close to zero), or non-finite. - - #[lua(kind = "Function", output(proxy))] - fn new(#[proxy] normal: bevy::math::Vec2) -> bevy::math::primitives::Plane2d; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Plane2d) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Plane2d { - #[lua(output(proxy))] - normal: bevy::math::primitives::Direction2d, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Line2d", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Line2d) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Line2d; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Line2d { - #[lua(output(proxy))] - direction: bevy::math::primitives::Direction2d, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Segment2d", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Segment2d) -> bool; - -"#, - r#" -/// Create a new `Segment2d` from a direction and full length of the segment - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - direction: bevy::math::primitives::Direction2d, - length: f32, - ) -> bevy::math::primitives::Segment2d; - -"#, - r#" -/// Get the position of the first point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point1(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Get the position of the second point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point2(&self) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Segment2d; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Segment2d { - #[lua(output(proxy))] - direction: bevy::math::primitives::Direction2d, - half_length: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Triangle2d", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Triangle2d) -> bool; - -"#, - r#" -/// Create a new `Triangle2d` from points `a`, `b`, and `c` - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - a: bevy::math::Vec2, - #[proxy] - b: bevy::math::Vec2, - #[proxy] - c: bevy::math::Vec2, - ) -> bevy::math::primitives::Triangle2d; - -"#, - r#" -/// Get the area of the triangle - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the perimeter of the triangle - - #[lua(kind = "Method")] - fn perimeter(&self) -> f32; - -"#, - r#" -/// Reverse the [`WindingOrder`] of the triangle -/// by swapping the second and third vertices - - #[lua(kind = "MutatingMethod")] - fn reverse(&mut self) -> (); - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Triangle2d; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Triangle2d { - vertices: ReflectedValue, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Rectangle", - functions[r#" -/// Create a new `Rectangle` from a full width and height - - #[lua(kind = "Function", output(proxy))] - fn new(width: f32, height: f32) -> bevy::math::primitives::Rectangle; - -"#, - r#" -/// Create a new `Rectangle` from a given full size - - #[lua(kind = "Function", output(proxy))] - fn from_size(#[proxy] size: bevy::math::Vec2) -> bevy::math::primitives::Rectangle; - -"#, - r#" -/// Create a new `Rectangle` from two corner points - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - point1: bevy::math::Vec2, - #[proxy] - point2: bevy::math::Vec2, - ) -> bevy::math::primitives::Rectangle; - -"#, - r#" -/// Get the size of the rectangle - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Get the area of the rectangle - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the perimeter of the rectangle - - #[lua(kind = "Method")] - fn perimeter(&self) -> f32; - -"#, - r#" -/// Finds the point on the rectangle that is closest to the given `point`. -/// If the point is outside the rectangle, the returned point will be on the perimeter of the rectangle. -/// Otherwise, it will be inside the rectangle and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point(&self, #[proxy] point: bevy::math::Vec2) -> bevy::math::Vec2; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Rectangle; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Rectangle) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Rectangle { - #[lua(output(proxy))] - half_size: bevy::math::Vec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::RegularPolygon", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::RegularPolygon; - -"#, - r#" -/// Create a new `RegularPolygon` -/// from the radius of the circumcircle and a number of sides -/// # Panics -/// Panics if `circumradius` is non-positive - - #[lua(kind = "Function", output(proxy))] - fn new(circumradius: f32, sides: usize) -> bevy::math::primitives::RegularPolygon; - -"#, - r#" -/// Get the radius of the circumcircle on which all vertices -/// of the regular polygon lie - - #[lua(kind = "Method")] - fn circumradius(&self) -> f32; - -"#, - r#" -/// Get the inradius or apothem of the regular polygon. -/// This is the radius of the largest circle that can -/// be drawn within the polygon - - #[lua(kind = "Method")] - fn inradius(&self) -> f32; - -"#, - r#" -/// Get the length of one side of the regular polygon - - #[lua(kind = "Method")] - fn side_length(&self) -> f32; - -"#, - r#" -/// Get the area of the regular polygon - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the perimeter of the regular polygon. -/// This is the sum of its sides - - #[lua(kind = "Method")] - fn perimeter(&self) -> f32; - -"#, - r#" -/// Get the internal angle of the regular polygon in degrees. -/// This is the angle formed by two adjacent sides with points -/// within the angle being in the interior of the polygon - - #[lua(kind = "Method")] - fn internal_angle_degrees(&self) -> f32; - -"#, - r#" -/// Get the internal angle of the regular polygon in radians. -/// This is the angle formed by two adjacent sides with points -/// within the angle being in the interior of the polygon - - #[lua(kind = "Method")] - fn internal_angle_radians(&self) -> f32; - -"#, - r#" -/// Get the external angle of the regular polygon in degrees. -/// This is the angle formed by two adjacent sides with points -/// within the angle being in the exterior of the polygon - - #[lua(kind = "Method")] - fn external_angle_degrees(&self) -> f32; - -"#, - r#" -/// Get the external angle of the regular polygon in radians. -/// This is the angle formed by two adjacent sides with points -/// within the angle being in the exterior of the polygon - - #[lua(kind = "Method")] - fn external_angle_radians(&self) -> f32; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::RegularPolygon) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct RegularPolygon { - #[lua(output(proxy))] - circumcircle: bevy::math::primitives::Circle, - sides: usize, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Capsule2d", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Capsule2d) -> bool; - -"#, - r#" -/// Create a new `Capsule2d` from a radius and length - - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, length: f32) -> bevy::math::primitives::Capsule2d; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Capsule2d; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Capsule2d { - radius: f32, - half_length: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Direction3d", - functions[r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Direction3d; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Direction3d) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::primitives::Direction3d; - -"#, - r#" -/// Create a [`Direction3d`] from a [`Vec3`] that is already normalized. -/// # Warning -/// `value` must be normalized, i.e it's length must be `1.0`. - - #[lua(kind = "Function", output(proxy))] - fn new_unchecked( - #[proxy] - value: bevy::math::Vec3, - ) -> bevy::math::primitives::Direction3d; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Direction3d(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Sphere", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Sphere; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Sphere) -> bool; - -"#, - r#" -/// Create a new [`Sphere`] from a `radius` - - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32) -> bevy::math::primitives::Sphere; - -"#, - r#" -/// Get the diameter of the sphere - - #[lua(kind = "Method")] - fn diameter(&self) -> f32; - -"#, - r#" -/// Get the surface area of the sphere - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the volume of the sphere - - #[lua(kind = "Method")] - fn volume(&self) -> f32; - -"#, - r#" -/// Finds the point on the sphere that is closest to the given `point`. -/// If the point is outside the sphere, the returned point will be on the surface of the sphere. -/// Otherwise, it will be inside the sphere and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Sphere { - radius: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Plane3d", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Plane3d) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Plane3d; - -"#, - r#" -/// Create a new `Plane3d` from a normal -/// # Panics -/// Panics if the given `normal` is zero (or very close to zero), or non-finite. - - #[lua(kind = "Function", output(proxy))] - fn new(#[proxy] normal: bevy::math::Vec3) -> bevy::math::primitives::Plane3d; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Plane3d { - #[lua(output(proxy))] - normal: bevy::math::primitives::Direction3d, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Line3d", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Line3d; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Line3d) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Line3d { - #[lua(output(proxy))] - direction: bevy::math::primitives::Direction3d, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Segment3d", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Segment3d) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Segment3d; - -"#, - r#" -/// Create a new `Segment3d` from a direction and full length of the segment - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - direction: bevy::math::primitives::Direction3d, - length: f32, - ) -> bevy::math::primitives::Segment3d; - -"#, - r#" -/// Get the position of the first point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point1(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Get the position of the second point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point2(&self) -> bevy::math::Vec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Segment3d { - #[lua(output(proxy))] - direction: bevy::math::primitives::Direction3d, - half_length: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Cuboid", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Cuboid; - -"#, - r#" -/// Create a new `Cuboid` from a full x, y, and z length - - #[lua(kind = "Function", output(proxy))] - fn new( - x_length: f32, - y_length: f32, - z_length: f32, - ) -> bevy::math::primitives::Cuboid; - -"#, - r#" -/// Create a new `Cuboid` from a given full size - - #[lua(kind = "Function", output(proxy))] - fn from_size(#[proxy] size: bevy::math::Vec3) -> bevy::math::primitives::Cuboid; - -"#, - r#" -/// Create a new `Cuboid` from two corner points - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - point1: bevy::math::Vec3, - #[proxy] - point2: bevy::math::Vec3, - ) -> bevy::math::primitives::Cuboid; - -"#, - r#" -/// Get the size of the cuboid - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Get the surface area of the cuboid - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the volume of the cuboid - - #[lua(kind = "Method")] - fn volume(&self) -> f32; - -"#, - r#" -/// Finds the point on the cuboid that is closest to the given `point`. -/// If the point is outside the cuboid, the returned point will be on the surface of the cuboid. -/// Otherwise, it will be inside the cuboid and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Cuboid) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Cuboid { - #[lua(output(proxy))] - half_size: bevy::math::Vec3, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Cylinder", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Cylinder; - -"#, - r#" -/// Create a new `Cylinder` from a radius and full height - - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, height: f32) -> bevy::math::primitives::Cylinder; - -"#, - r#" -/// Get the base of the cylinder as a [`Circle`] - - #[lua(kind = "Method", output(proxy))] - fn base(&self) -> bevy::math::primitives::Circle; - -"#, - r#" -/// Get the surface area of the side of the cylinder, -/// also known as the lateral area - - #[lua(kind = "Method")] - fn lateral_area(&self) -> f32; - -"#, - r#" -/// Get the surface area of one base of the cylinder - - #[lua(kind = "Method")] - fn base_area(&self) -> f32; - -"#, - r#" -/// Get the total surface area of the cylinder - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the volume of the cylinder - - #[lua(kind = "Method")] - fn volume(&self) -> f32; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Cylinder) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Cylinder { - radius: f32, - half_height: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Capsule3d", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Capsule3d; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Capsule3d) -> bool; - -"#, - r#" -/// Create a new `Capsule3d` from a radius and length - - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, length: f32) -> bevy::math::primitives::Capsule3d; - -"#, - r#" -/// Get the part connecting the hemispherical ends -/// of the capsule as a [`Cylinder`] - - #[lua(kind = "Method", output(proxy))] - fn to_cylinder(&self) -> bevy::math::primitives::Cylinder; - -"#, - r#" -/// Get the surface area of the capsule - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the volume of the capsule - - #[lua(kind = "Method")] - fn volume(&self) -> f32; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Capsule3d { - radius: f32, - half_length: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Cone", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Cone) -> bool; - -"#, - r#" -/// Get the base of the cone as a [`Circle`] - - #[lua(kind = "Method", output(proxy))] - fn base(&self) -> bevy::math::primitives::Circle; - -"#, - r#" -/// Get the slant height of the cone, the length of the line segment -/// connecting a point on the base to the apex - - #[lua(kind = "Method")] - fn slant_height(&self) -> f32; - -"#, - r#" -/// Get the surface area of the side of the cone, -/// also known as the lateral area - - #[lua(kind = "Method")] - fn lateral_area(&self) -> f32; - -"#, - r#" -/// Get the surface area of the base of the cone - - #[lua(kind = "Method")] - fn base_area(&self) -> f32; - -"#, - r#" -/// Get the total surface area of the cone - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the volume of the cone - - #[lua(kind = "Method")] - fn volume(&self) -> f32; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Cone; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Cone { - radius: f32, - height: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::ConicalFrustum", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::ConicalFrustum) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::ConicalFrustum; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct ConicalFrustum { - radius_top: f32, - radius_bottom: f32, - height: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::primitives::Torus", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::primitives::Torus) -> bool; - -"#, - r#" -/// Create a new `Torus` from an inner and outer radius. -/// The inner radius is the radius of the hole, and the outer radius -/// is the radius of the entire object - - #[lua(kind = "Function", output(proxy))] - fn new(inner_radius: f32, outer_radius: f32) -> bevy::math::primitives::Torus; - -"#, - r#" -/// Get the inner radius of the torus. -/// For a ring torus, this corresponds to the radius of the hole, -/// or `major_radius - minor_radius` - - #[lua(kind = "Method")] - fn inner_radius(&self) -> f32; - -"#, - r#" -/// Get the outer radius of the torus. -/// This corresponds to the overall radius of the entire object, -/// or `major_radius + minor_radius` - - #[lua(kind = "Method")] - fn outer_radius(&self) -> f32; - -"#, - r#" -/// Get the surface area of the torus. Note that this only produces -/// the expected result when the torus has a ring and isn't self-intersecting - - #[lua(kind = "Method")] - fn area(&self) -> f32; - -"#, - r#" -/// Get the volume of the torus. Note that this only produces -/// the expected result when the torus has a ring and isn't self-intersecting - - #[lua(kind = "Method")] - fn volume(&self) -> f32; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::primitives::Torus; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Torus { - minor_radius: f32, - major_radius: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::IRect", - functions[r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::IRect; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::IRect) -> bool; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::IRect; -/// let r = IRect::new(0, 4, 10, 6); // w=10 h=2 -/// let r = IRect::new(2, 3, 5, -1); // w=3 h=4 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new(x0: i32, y0: i32, x1: i32, y1: i32) -> bevy::math::IRect; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// // Unit rect from [0,0] to [1,1] -/// let r = IRect::from_corners(IVec2::ZERO, IVec2::ONE); // w=1 h=1 -/// // Same; the points do not need to be ordered -/// let r = IRect::from_corners(IVec2::ONE, IVec2::ZERO); // w=1 h=1 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - p0: bevy::math::IVec2, - #[proxy] - p1: bevy::math::IVec2, - ) -> bevy::math::IRect; - -"#, - r#" -/// Create a new rectangle from its center and size. -/// # Rounding Behaviour -/// If the size contains odd numbers they will be rounded down to the nearest whole number. -/// # Panics -/// This method panics if any of the components of the size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::from_center_size(IVec2::ZERO, IVec2::new(3, 2)); // w=2 h=2 -/// assert_eq!(r.min, IVec2::splat(-1)); -/// assert_eq!(r.max, IVec2::splat(1)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_size( - #[proxy] - origin: bevy::math::IVec2, - #[proxy] - size: bevy::math::IVec2, - ) -> bevy::math::IRect; - -"#, - r#" -/// Create a new rectangle from its center and half-size. -/// # Panics -/// This method panics if any of the components of the half-size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::from_center_half_size(IVec2::ZERO, IVec2::ONE); // w=2 h=2 -/// assert_eq!(r.min, IVec2::splat(-1)); -/// assert_eq!(r.max, IVec2::splat(1)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_half_size( - #[proxy] - origin: bevy::math::IVec2, - #[proxy] - half_size: bevy::math::IVec2, - ) -> bevy::math::IRect; - -"#, - r#" -/// Check if the rectangle is empty. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::from_corners(IVec2::ZERO, IVec2::new(0, 1)); // w=0 h=1 -/// assert!(r.is_empty()); -/// ``` - - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; - -"#, - r#" -/// Rectangle width (max.x - min.x). -/// # Examples -/// ``` -/// # use bevy_math::IRect; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.width(), 5); -/// ``` - - #[lua(kind = "Method")] - fn width(&self) -> i32; - -"#, - r#" -/// Rectangle height (max.y - min.y). -/// # Examples -/// ``` -/// # use bevy_math::IRect; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.height(), 1); -/// ``` - - #[lua(kind = "Method")] - fn height(&self) -> i32; - -"#, - r#" -/// Rectangle size. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.size(), IVec2::new(5, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Rectangle half-size. -/// # Rounding Behaviour -/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 4, 3); // w=4 h=3 -/// assert_eq!(r.half_size(), IVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn half_size(&self) -> bevy::math::IVec2; - -"#, - r#" -/// The center point of the rectangle. -/// # Rounding Behaviour -/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 5, 2); // w=5 h=2 -/// assert_eq!(r.center(), IVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn center(&self) -> bevy::math::IVec2; - -"#, - r#" -/// Check if a point lies within this rectangle, inclusive of its edges. -/// # Examples -/// ``` -/// # use bevy_math::IRect; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// assert!(r.contains(r.center())); -/// assert!(r.contains(r.min)); -/// assert!(r.contains(r.max)); -/// ``` - - #[lua(kind = "Method")] - fn contains(&self, #[proxy] point: bevy::math::IVec2) -> bool; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and another rectangle. -/// The union is the smallest rectangle enclosing both rectangles. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r1 = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// let r2 = IRect::new(1, -1, 3, 3); // w=2 h=4 -/// let r = r1.union(r2); -/// assert_eq!(r.min, IVec2::new(0, -1)); -/// assert_eq!(r.max, IVec2::new(5, 3)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union(&self, #[proxy] other: bevy::math::IRect) -> bevy::math::IRect; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and a point. -/// The union is the smallest rectangle enclosing both the rectangle and the point. If the -/// point is already inside the rectangle, this method returns a copy of the rectangle. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// let u = r.union_point(IVec2::new(3, 6)); -/// assert_eq!(u.min, IVec2::ZERO); -/// assert_eq!(u.max, IVec2::new(5, 6)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union_point(&self, #[proxy] other: bevy::math::IVec2) -> bevy::math::IRect; - -"#, - r#" -/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. -/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection -/// is empty, this method returns an empty rectangle ([`IRect::is_empty()`] returns `true`), but -/// the actual values of [`IRect::min`] and [`IRect::max`] are implementation-dependent. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r1 = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// let r2 = IRect::new(1, -1, 3, 3); // w=2 h=4 -/// let r = r1.intersect(r2); -/// assert_eq!(r.min, IVec2::new(1, 0)); -/// assert_eq!(r.max, IVec2::new(3, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn intersect(&self, #[proxy] other: bevy::math::IRect) -> bevy::math::IRect; - -"#, - r#" -/// Create a new rectangle with a constant inset. -/// The inset is the extra border on all sides. A positive inset produces a larger rectangle, -/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative -/// and its absolute value is larger than the rectangle half-size, the created rectangle is empty. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// let r2 = r.inset(3); // w=11 h=7 -/// assert_eq!(r2.min, IVec2::splat(-3)); -/// assert_eq!(r2.max, IVec2::new(8, 4)); -/// let r = IRect::new(0, -1, 4, 3); // w=4 h=4 -/// let r2 = r.inset(-1); // w=2 h=2 -/// assert_eq!(r2.min, IVec2::new(1, 0)); -/// assert_eq!(r2.max, IVec2::new(3, 2)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn inset(&self, inset: i32) -> bevy::math::IRect; - -"#, - r#" -/// Returns self as [`Rect`] (f32) - - #[lua(kind = "Method", output(proxy))] - fn as_rect(&self) -> bevy::math::Rect; - -"#, - r#" -/// Returns self as [`URect`] (u32) - - #[lua(kind = "Method", output(proxy))] - fn as_urect(&self) -> bevy::math::URect; - -"#, - 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) -} -"#] -)] -pub struct IRect { - #[lua(output(proxy))] - min: bevy::math::IVec2, - #[lua(output(proxy))] - max: bevy::math::IVec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::Rect", - functions[r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::Rect; -/// let r = Rect::new(0., 4., 10., 6.); // w=10 h=2 -/// let r = Rect::new(2., 3., 5., -1.); // w=3 h=4 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> bevy::math::Rect; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// // Unit rect from [0,0] to [1,1] -/// let r = Rect::from_corners(Vec2::ZERO, Vec2::ONE); // w=1 h=1 -/// // Same; the points do not need to be ordered -/// let r = Rect::from_corners(Vec2::ONE, Vec2::ZERO); // w=1 h=1 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - p0: bevy::math::Vec2, - #[proxy] - p1: bevy::math::Vec2, - ) -> bevy::math::Rect; - -"#, - r#" -/// Create a new rectangle from its center and size. -/// # Panics -/// This method panics if any of the components of the size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::from_center_size(Vec2::ZERO, Vec2::ONE); // w=1 h=1 -/// assert!(r.min.abs_diff_eq(Vec2::splat(-0.5), 1e-5)); -/// assert!(r.max.abs_diff_eq(Vec2::splat(0.5), 1e-5)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_size( - #[proxy] - origin: bevy::math::Vec2, - #[proxy] - size: bevy::math::Vec2, - ) -> bevy::math::Rect; - -"#, - r#" -/// Create a new rectangle from its center and half-size. -/// # Panics -/// This method panics if any of the components of the half-size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::from_center_half_size(Vec2::ZERO, Vec2::ONE); // w=2 h=2 -/// assert!(r.min.abs_diff_eq(Vec2::splat(-1.), 1e-5)); -/// assert!(r.max.abs_diff_eq(Vec2::splat(1.), 1e-5)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_half_size( - #[proxy] - origin: bevy::math::Vec2, - #[proxy] - half_size: bevy::math::Vec2, - ) -> bevy::math::Rect; - -"#, - r#" -/// Check if the rectangle is empty. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::from_corners(Vec2::ZERO, Vec2::new(0., 1.)); // w=0 h=1 -/// assert!(r.is_empty()); -/// ``` - - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; - -"#, - r#" -/// Rectangle width (max.x - min.x). -/// # Examples -/// ``` -/// # use bevy_math::Rect; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!((r.width() - 5.).abs() <= 1e-5); -/// ``` - - #[lua(kind = "Method")] - fn width(&self) -> f32; - -"#, - r#" -/// Rectangle height (max.y - min.y). -/// # Examples -/// ``` -/// # use bevy_math::Rect; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!((r.height() - 1.).abs() <= 1e-5); -/// ``` - - #[lua(kind = "Method")] - fn height(&self) -> f32; - -"#, - r#" -/// Rectangle size. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.size().abs_diff_eq(Vec2::new(5., 1.), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Rectangle half-size. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.half_size().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn half_size(&self) -> bevy::math::Vec2; - -"#, - r#" -/// The center point of the rectangle. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.center().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn center(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Check if a point lies within this rectangle, inclusive of its edges. -/// # Examples -/// ``` -/// # use bevy_math::Rect; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.contains(r.center())); -/// assert!(r.contains(r.min)); -/// assert!(r.contains(r.max)); -/// ``` - - #[lua(kind = "Method")] - fn contains(&self, #[proxy] point: bevy::math::Vec2) -> bool; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and another rectangle. -/// The union is the smallest rectangle enclosing both rectangles. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r1 = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// let r2 = Rect::new(1., -1., 3., 3.); // w=2 h=4 -/// let r = r1.union(r2); -/// assert!(r.min.abs_diff_eq(Vec2::new(0., -1.), 1e-5)); -/// assert!(r.max.abs_diff_eq(Vec2::new(5., 3.), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union(&self, #[proxy] other: bevy::math::Rect) -> bevy::math::Rect; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and a point. -/// The union is the smallest rectangle enclosing both the rectangle and the point. If the -/// point is already inside the rectangle, this method returns a copy of the rectangle. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// let u = r.union_point(Vec2::new(3., 6.)); -/// assert!(u.min.abs_diff_eq(Vec2::ZERO, 1e-5)); -/// assert!(u.max.abs_diff_eq(Vec2::new(5., 6.), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union_point(&self, #[proxy] other: bevy::math::Vec2) -> bevy::math::Rect; - -"#, - r#" -/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. -/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection -/// is empty, this method returns an empty rectangle ([`Rect::is_empty()`] returns `true`), but -/// the actual values of [`Rect::min`] and [`Rect::max`] are implementation-dependent. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r1 = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// let r2 = Rect::new(1., -1., 3., 3.); // w=2 h=4 -/// let r = r1.intersect(r2); -/// assert!(r.min.abs_diff_eq(Vec2::new(1., 0.), 1e-5)); -/// assert!(r.max.abs_diff_eq(Vec2::new(3., 1.), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn intersect(&self, #[proxy] other: bevy::math::Rect) -> bevy::math::Rect; - -"#, - r#" -/// Create a new rectangle with a constant inset. -/// The inset is the extra border on all sides. A positive inset produces a larger rectangle, -/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative -/// and its absolute value is larger than the rectangle half-size, the created rectangle is empty. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// let r2 = r.inset(3.); // w=11 h=7 -/// assert!(r2.min.abs_diff_eq(Vec2::splat(-3.), 1e-5)); -/// assert!(r2.max.abs_diff_eq(Vec2::new(8., 4.), 1e-5)); -/// let r = Rect::new(0., -1., 6., 7.); // w=6 h=8 -/// let r2 = r.inset(-2.); // w=11 h=7 -/// assert!(r2.min.abs_diff_eq(Vec2::new(2., 1.), 1e-5)); -/// assert!(r2.max.abs_diff_eq(Vec2::new(4., 5.), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn inset(&self, inset: f32) -> bevy::math::Rect; - -"#, - r#" -/// Build a new rectangle from this one with its coordinates expressed -/// relative to `other` in a normalized ([0..1] x [0..1]) coordinate system. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(2., 3., 4., 6.); -/// let s = Rect::new(0., 0., 10., 10.); -/// let n = r.normalize(s); -/// assert_eq!(n.min.x, 0.2); -/// assert_eq!(n.min.y, 0.3); -/// assert_eq!(n.max.x, 0.4); -/// assert_eq!(n.max.y, 0.6); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn normalize(&self, #[proxy] other: bevy::math::Rect) -> bevy::math::Rect; - -"#, - r#" -/// Returns self as [`IRect`] (i32) - - #[lua(kind = "Method", output(proxy))] - fn as_irect(&self) -> bevy::math::IRect; - -"#, - r#" -/// Returns self as [`URect`] (u32) - - #[lua(kind = "Method", output(proxy))] - fn as_urect(&self) -> bevy::math::URect; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Rect; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::Rect) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Rect { - #[lua(output(proxy))] - min: bevy::math::Vec2, - #[lua(output(proxy))] - max: bevy::math::Vec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::URect", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_math::URect) -> bool; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::URect; -/// let r = URect::new(0, 4, 10, 6); // w=10 h=2 -/// let r = URect::new(2, 4, 5, 0); // w=3 h=4 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new(x0: u32, y0: u32, x1: u32, y1: u32) -> bevy::math::URect; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// // Unit rect from [0,0] to [1,1] -/// let r = URect::from_corners(UVec2::ZERO, UVec2::ONE); // w=1 h=1 -/// // Same; the points do not need to be ordered -/// let r = URect::from_corners(UVec2::ONE, UVec2::ZERO); // w=1 h=1 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - p0: bevy::math::UVec2, - #[proxy] - p1: bevy::math::UVec2, - ) -> bevy::math::URect; - -"#, - r#" -/// Create a new rectangle from its center and size. -/// # Rounding Behaviour -/// If the size contains odd numbers they will be rounded down to the nearest whole number. -/// # Panics -/// This method panics if any of the components of the size is negative or if `origin - (size / 2)` results in any negatives. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::from_center_size(UVec2::ONE, UVec2::splat(2)); // w=2 h=2 -/// assert_eq!(r.min, UVec2::splat(0)); -/// assert_eq!(r.max, UVec2::splat(2)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_size( - #[proxy] - origin: bevy::math::UVec2, - #[proxy] - size: bevy::math::UVec2, - ) -> bevy::math::URect; - -"#, - r#" -/// Create a new rectangle from its center and half-size. -/// # Panics -/// This method panics if any of the components of the half-size is negative or if `origin - half_size` results in any negatives. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::from_center_half_size(UVec2::ONE, UVec2::ONE); // w=2 h=2 -/// assert_eq!(r.min, UVec2::splat(0)); -/// assert_eq!(r.max, UVec2::splat(2)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_half_size( - #[proxy] - origin: bevy::math::UVec2, - #[proxy] - half_size: bevy::math::UVec2, - ) -> bevy::math::URect; - -"#, - r#" -/// Check if the rectangle is empty. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::from_corners(UVec2::ZERO, UVec2::new(0, 1)); // w=0 h=1 -/// assert!(r.is_empty()); -/// ``` - - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; - -"#, - r#" -/// Rectangle width (max.x - min.x). -/// # Examples -/// ``` -/// # use bevy_math::URect; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.width(), 5); -/// ``` - - #[lua(kind = "Method")] - fn width(&self) -> u32; - -"#, - r#" -/// Rectangle height (max.y - min.y). -/// # Examples -/// ``` -/// # use bevy_math::URect; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.height(), 1); -/// ``` - - #[lua(kind = "Method")] - fn height(&self) -> u32; - -"#, - r#" -/// Rectangle size. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.size(), UVec2::new(5, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::UVec2; - -"#, - r#" -/// Rectangle half-size. -/// # Rounding Behaviour -/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 -/// assert_eq!(r.half_size(), UVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn half_size(&self) -> bevy::math::UVec2; - -"#, - r#" -/// The center point of the rectangle. -/// # Rounding Behaviour -/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 -/// assert_eq!(r.center(), UVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn center(&self) -> bevy::math::UVec2; - -"#, - r#" -/// Check if a point lies within this rectangle, inclusive of its edges. -/// # Examples -/// ``` -/// # use bevy_math::URect; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// assert!(r.contains(r.center())); -/// assert!(r.contains(r.min)); -/// assert!(r.contains(r.max)); -/// ``` - - #[lua(kind = "Method")] - fn contains(&self, #[proxy] point: bevy::math::UVec2) -> bool; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and another rectangle. -/// The union is the smallest rectangle enclosing both rectangles. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r1 = URect::new(0, 0, 5, 1); // w=5 h=1 -/// let r2 = URect::new(1, 0, 3, 8); // w=2 h=4 -/// let r = r1.union(r2); -/// assert_eq!(r.min, UVec2::new(0, 0)); -/// assert_eq!(r.max, UVec2::new(5, 8)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union(&self, #[proxy] other: bevy::math::URect) -> bevy::math::URect; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and a point. -/// The union is the smallest rectangle enclosing both the rectangle and the point. If the -/// point is already inside the rectangle, this method returns a copy of the rectangle. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// let u = r.union_point(UVec2::new(3, 6)); -/// assert_eq!(u.min, UVec2::ZERO); -/// assert_eq!(u.max, UVec2::new(5, 6)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union_point(&self, #[proxy] other: bevy::math::UVec2) -> bevy::math::URect; - -"#, - r#" -/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. -/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection -/// is empty, this method returns an empty rectangle ([`URect::is_empty()`] returns `true`), but -/// the actual values of [`URect::min`] and [`URect::max`] are implementation-dependent. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r1 = URect::new(0, 0, 2, 2); // w=2 h=2 -/// let r2 = URect::new(1, 1, 3, 3); // w=2 h=2 -/// let r = r1.intersect(r2); -/// assert_eq!(r.min, UVec2::new(1, 1)); -/// assert_eq!(r.max, UVec2::new(2, 2)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn intersect(&self, #[proxy] other: bevy::math::URect) -> bevy::math::URect; - -"#, - r#" -/// Create a new rectangle with a constant inset. -/// The inset is the extra border on all sides. A positive inset produces a larger rectangle, -/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative -/// and its absolute value is larger than the rectangle half-size, the created rectangle is empty. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(4, 4, 6, 6); // w=2 h=2 -/// let r2 = r.inset(1); // w=4 h=4 -/// assert_eq!(r2.min, UVec2::splat(3)); -/// assert_eq!(r2.max, UVec2::splat(7)); -/// let r = URect::new(4, 4, 8, 8); // w=4 h=4 -/// let r2 = r.inset(-1); // w=2 h=2 -/// assert_eq!(r2.min, UVec2::splat(5)); -/// assert_eq!(r2.max, UVec2::splat(7)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn inset(&self, inset: i32) -> bevy::math::URect; - -"#, - r#" -/// Returns self as [`Rect`] (f32) - - #[lua(kind = "Method", output(proxy))] - fn as_rect(&self) -> bevy::math::Rect; - -"#, - r#" -/// Returns self as [`IRect`] (i32) - - #[lua(kind = "Method", output(proxy))] - fn as_irect(&self) -> bevy::math::IRect; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::URect; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct URect { - #[lua(output(proxy))] - min: bevy::math::UVec2, - #[lua(output(proxy))] - max: bevy::math::UVec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "smol_str::SmolStr", - functions[r#" - - #[lua(kind = "Method")] - fn to_string(&self) -> std::string::String; - -"#, - r#" - - #[lua(kind = "Method")] - fn len(&self) -> usize; - -"#, - r#" - - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; - -"#, - r#" - - #[lua(kind = "Method")] - fn is_heap_allocated(&self) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &smol_str::SmolStr) -> bool; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> smol_str::SmolStr; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct SmolStr(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "std::num::NonZeroIsize", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::num::NonZeroIsize) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a non-zero without checking whether the value is non-zero. -/// This results in undefined behaviour if the value is zero. -/// # Safety -/// The value must not be zero. - - #[lua(kind = "Function", output(proxy))] - unsafe fn new_unchecked(n: isize) -> std::num::NonZeroIsize; - -"#, - r#" -/// Returns the value as a primitive type. - - #[lua(kind = "Method")] - fn get(self) -> isize; - -"#, - r#" -/// Returns the number of leading zeros in the binary representation of `self`. -/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroIsize::new(-1isize).unwrap(); -/// assert_eq!(n.leading_zeros(), 0); -/// ``` - - #[lua(kind = "Method")] - fn leading_zeros(self) -> u32; - -"#, - r#" -/// Returns the number of trailing zeros in the binary representation -/// of `self`. -/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. -/// # Examples -/// Basic usage: -/// ``` -///let n = std::num::NonZeroIsize::new(0b0101000).unwrap(); -/// assert_eq!(n.trailing_zeros(), 3); -/// ``` - - #[lua(kind = "Method")] - fn trailing_zeros(self) -> u32; - -"#, - r#" -/// Computes the absolute value of self. -///See [`isize::abs`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroIsize::new(1)?; -///let neg = NonZeroIsize::new(-1)?; -/// assert_eq!(pos, pos.abs()); -/// assert_eq!(pos, neg.abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> std::num::NonZeroIsize; - -"#, - r#" -/// Saturating absolute value, see -///[`isize::saturating_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroIsize::new(1)?; -///let neg = NonZeroIsize::new(-1)?; -///let min = NonZeroIsize::new(isize::MIN)?; -///let min_plus = NonZeroIsize::new(isize::MIN + 1)?; -///let max = NonZeroIsize::new(isize::MAX)?; -/// assert_eq!(pos, pos.saturating_abs()); -/// assert_eq!(pos, neg.saturating_abs()); -/// assert_eq!(max, min.saturating_abs()); -/// assert_eq!(max, min_plus.saturating_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_abs(self) -> std::num::NonZeroIsize; - -"#, - r#" -/// Wrapping absolute value, see -///[`isize::wrapping_abs`]. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos = NonZeroIsize::new(1)?; -///let neg = NonZeroIsize::new(-1)?; -///let min = NonZeroIsize::new(isize::MIN)?; -///# let max = NonZeroIsize::new(isize::MAX)?; -/// assert_eq!(pos, pos.wrapping_abs()); -/// assert_eq!(pos, neg.wrapping_abs()); -/// assert_eq!(min, min.wrapping_abs()); -/// assert_eq!(max, (-max).wrapping_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_abs(self) -> std::num::NonZeroIsize; - -"#, - r#" -/// Computes the absolute value of self -/// without any wrapping or panicking. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -///# use std::num::NonZeroUsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let u_pos = NonZeroUsize::new(1)?; -///let i_pos = NonZeroIsize::new(1)?; -///let i_neg = NonZeroIsize::new(-1)?; -///let i_min = NonZeroIsize::new(isize::MIN)?; -///let u_max = NonZeroUsize::new(usize::MAX / 2 + 1)?; -/// assert_eq!(u_pos, i_pos.unsigned_abs()); -/// assert_eq!(u_pos, i_neg.unsigned_abs()); -/// assert_eq!(u_max, i_min.unsigned_abs()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn unsigned_abs(self) -> std::num::NonZeroUsize; - -"#, - r#" -/// Returns `true` if `self` is positive and `false` if the -/// number is negative. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroIsize::new(5)?; -///let neg_five = NonZeroIsize::new(-5)?; -/// assert!(pos_five.is_positive()); -/// assert!(!neg_five.is_positive()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_positive(self) -> bool; - -"#, - r#" -/// Returns `true` if `self` is negative and `false` if the -/// number is positive. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroIsize::new(5)?; -///let neg_five = NonZeroIsize::new(-5)?; -/// assert!(neg_five.is_negative()); -/// assert!(!pos_five.is_negative()); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn is_negative(self) -> bool; - -"#, - r#" -/// Saturating negation. Computes `-self`, -///returning [`NonZeroIsize::MAX`] -///if `self == NonZeroIsize::MIN` -/// instead of overflowing. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroIsize::new(5)?; -///let neg_five = NonZeroIsize::new(-5)?; -///let min = NonZeroIsize::new(isize::MIN)?; -///let min_plus_one = NonZeroIsize::new(isize::MIN + 1)?; -///let max = NonZeroIsize::new(isize::MAX)?; -/// assert_eq!(pos_five.saturating_neg(), neg_five); -/// assert_eq!(min.saturating_neg(), max); -/// assert_eq!(max.saturating_neg(), min_plus_one); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_neg(self) -> std::num::NonZeroIsize; - -"#, - r#" -/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary -/// of the type. -///See [`isize::wrapping_neg`] -/// for documentation on overflow behaviour. -/// # Example -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let pos_five = NonZeroIsize::new(5)?; -///let neg_five = NonZeroIsize::new(-5)?; -///let min = NonZeroIsize::new(isize::MIN)?; -/// assert_eq!(pos_five.wrapping_neg(), neg_five); -/// assert_eq!(min.wrapping_neg(), min); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn wrapping_neg(self) -> std::num::NonZeroIsize; - -"#, - r#" -/// Multiplies two non-zero integers together. -///Return [`NonZeroIsize::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let two = NonZeroIsize::new(2)?; -///let four = NonZeroIsize::new(4)?; -///let max = NonZeroIsize::new(isize::MAX)?; -/// assert_eq!(four, two.saturating_mul(two)); -/// assert_eq!(max, four.saturating_mul(max)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_mul( - self, - #[proxy] - other: std::num::NonZeroIsize, - ) -> std::num::NonZeroIsize; - -"#, - r#" -/// Raise non-zero value to an integer power. -///Return [`NonZeroIsize::MIN`] or [`NonZeroIsize::MAX`] on overflow. -/// # Examples -/// ``` -///# use std::num::NonZeroIsize; -/// # fn main() { test().unwrap(); } -/// # fn test() -> Option<()> { -///let three = NonZeroIsize::new(3)?; -///let twenty_seven = NonZeroIsize::new(27)?; -///let max = NonZeroIsize::new(isize::MAX)?; -/// assert_eq!(twenty_seven, three.saturating_pow(3)); -/// assert_eq!(max, max.saturating_pow(3)); -/// # Some(()) -/// # } -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn saturating_pow(self, other: u32) -> std::num::NonZeroIsize; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::num::NonZeroIsize; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> std::num::NonZeroIsize; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct NonZeroIsize(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::utils::Uuid", - functions[r#" -/// Returns the version number of the UUID. -/// This represents the algorithm used to generate the value. -/// This method is the future-proof alternative to [`Uuid::get_version`]. -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::Uuid; -/// # fn main() -> Result<(), uuid::Error> { -/// let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?; -/// assert_eq!(3, my_uuid.get_version_num()); -/// # Ok(()) -/// # } -/// ``` -/// # References -/// * [Version in RFC4122](https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.3) - - #[lua(kind = "Method")] - fn get_version_num(&self) -> usize; - -"#, - r#" -/// Returns a 128bit value containing the value. -/// The bytes in the UUID will be packed directly into a `u128`. -/// # Examples -/// ``` -/// # use uuid::Uuid; -/// # fn main() -> Result<(), uuid::Error> { -/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; -/// assert_eq!( -/// uuid.as_u128(), -/// 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8, -/// ); -/// # Ok(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn as_u128(&self) -> u128; - -"#, - r#" -/// Returns a 128bit little-endian value containing the value. -/// The bytes in the `u128` will be flipped to convert into big-endian -/// order. This is based on the endianness of the UUID, rather than the -/// target environment so bytes will be flipped on both big and little -/// endian machines. -/// Note that this will produce a different result than -/// [`Uuid::to_fields_le`], because the entire UUID is reversed, rather -/// than reversing the individual fields in-place. -/// # Examples -/// ``` -/// # use uuid::Uuid; -/// # fn main() -> Result<(), uuid::Error> { -/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; -/// assert_eq!( -/// uuid.to_u128_le(), -/// 0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1, -/// ); -/// # Ok(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn to_u128_le(&self) -> u128; - -"#, - r#" -/// Returns two 64bit values containing the value. -/// The bytes in the UUID will be split into two `u64`. -/// The first u64 represents the 64 most significant bits, -/// the second one represents the 64 least significant. -/// # Examples -/// ``` -/// # use uuid::Uuid; -/// # fn main() -> Result<(), uuid::Error> { -/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; -/// assert_eq!( -/// uuid.as_u64_pair(), -/// (0xa1a2a3a4b1b2c1c2, 0xd1d2d3d4d5d6d7d8), -/// ); -/// # Ok(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn as_u64_pair(&self) -> (u64, u64); - -"#, - r#" -/// Consumes self and returns the underlying byte value of the UUID. -/// # Examples -/// ``` -/// # use uuid::Uuid; -/// let bytes = [ -/// 0xa1, 0xa2, 0xa3, 0xa4, -/// 0xb1, 0xb2, -/// 0xc1, 0xc2, -/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, -/// ]; -/// let uuid = Uuid::from_bytes(bytes); -/// assert_eq!(bytes, uuid.into_bytes()); -/// ``` - - #[lua(kind = "Method")] - fn into_bytes(self) -> [u8; 16]; - -"#, - r#" -/// Returns the bytes of the UUID in little-endian order. -/// The bytes will be flipped to convert into little-endian order. This is -/// based on the endianness of the UUID, rather than the target environment -/// so bytes will be flipped on both big and little endian machines. -/// # Examples -/// ``` -/// use uuid::Uuid; -/// # fn main() -> Result<(), uuid::Error> { -/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; -/// assert_eq!( -/// uuid.to_bytes_le(), -/// ([ -/// 0xa4, 0xa3, 0xa2, 0xa1, 0xb2, 0xb1, 0xc2, 0xc1, 0xd1, 0xd2, -/// 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 -/// ]) -/// ); -/// # Ok(()) -/// # } -/// ``` - - #[lua(kind = "Method")] - fn to_bytes_le(&self) -> [u8; 16]; - -"#, - r#" -/// Tests if the UUID is nil (all zeros). - - #[lua(kind = "Method")] - fn is_nil(&self) -> bool; - -"#, - r#" -/// Tests if the UUID is max (all ones). - - #[lua(kind = "Method")] - fn is_max(&self) -> bool; - -"#, - r#" -/// A buffer that can be used for `encode_...` calls, that is -/// guaranteed to be long enough for any of the format adapters. -/// # Examples -/// ``` -/// # use uuid::Uuid; -/// let uuid = Uuid::nil(); -/// assert_eq!( -/// uuid.simple().encode_lower(&mut Uuid::encode_buffer()), -/// "00000000000000000000000000000000" -/// ); -/// assert_eq!( -/// uuid.hyphenated() -/// .encode_lower(&mut Uuid::encode_buffer()), -/// "00000000-0000-0000-0000-000000000000" -/// ); -/// assert_eq!( -/// uuid.urn().encode_lower(&mut Uuid::encode_buffer()), -/// "urn:uuid:00000000-0000-0000-0000-000000000000" -/// ); -/// ``` - - #[lua(kind = "Function")] - fn encode_buffer() -> [u8; 45]; - -"#, - r#" -/// The 'nil UUID' (all zeros). -/// The nil UUID is a special form of UUID that is specified to have all -/// 128 bits set to zero. -/// # References -/// * [Nil UUID in RFC4122](https://tools.ietf.org/html/rfc4122.html#section-4.1.7) -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::Uuid; -/// let uuid = Uuid::nil(); -/// assert_eq!( -/// "00000000-0000-0000-0000-000000000000", -/// uuid.hyphenated().to_string(), -/// ); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn nil() -> bevy::utils::Uuid; - -"#, - r#" -/// The 'max UUID' (all ones). -/// The max UUID is a special form of UUID that is specified to have all -/// 128 bits set to one. -/// # References -/// * [Max UUID in Draft RFC: New UUID Formats, Version 4](https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.4) -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::Uuid; -/// let uuid = Uuid::max(); -/// assert_eq!( -/// "ffffffff-ffff-ffff-ffff-ffffffffffff", -/// uuid.hyphenated().to_string(), -/// ); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn max() -> bevy::utils::Uuid; - -"#, - r#" -/// Creates a UUID from a 128bit value. -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::Uuid; -/// let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128; -/// let uuid = Uuid::from_u128(v); -/// assert_eq!( -/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8", -/// uuid.hyphenated().to_string(), -/// ); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_u128(v: u128) -> bevy::utils::Uuid; - -"#, - r#" -/// Creates a UUID from a 128bit value in little-endian order. -/// The entire value will be flipped to convert into big-endian order. -/// This is based on the endianness of the UUID, rather than the target -/// environment so bytes will be flipped on both big and little endian -/// machines. -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::Uuid; -/// let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128; -/// let uuid = Uuid::from_u128_le(v); -/// assert_eq!( -/// "d8d7d6d5-d4d3-d2d1-c2c1-b2b1a4a3a2a1", -/// uuid.hyphenated().to_string(), -/// ); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_u128_le(v: u128) -> bevy::utils::Uuid; - -"#, - r#" -/// Creates a UUID from two 64bit values. -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::Uuid; -/// let hi = 0xa1a2a3a4b1b2c1c2u64; -/// let lo = 0xd1d2d3d4d5d6d7d8u64; -/// let uuid = Uuid::from_u64_pair(hi, lo); -/// assert_eq!( -/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8", -/// uuid.hyphenated().to_string(), -/// ); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_u64_pair(high_bits: u64, low_bits: u64) -> bevy::utils::Uuid; - -"#, - r#" -/// Creates a UUID using the supplied bytes. -/// # Examples -/// Basic usage: -/// ``` -/// # fn main() -> Result<(), uuid::Error> { -/// # use uuid::Uuid; -/// let bytes = [ -/// 0xa1, 0xa2, 0xa3, 0xa4, -/// 0xb1, 0xb2, -/// 0xc1, 0xc2, -/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, -/// ]; -/// let uuid = Uuid::from_bytes(bytes); -/// assert_eq!( -/// uuid.hyphenated().to_string(), -/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8" -/// ); -/// # Ok(()) -/// # } -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_bytes(bytes: [u8; 16]) -> bevy::utils::Uuid; - -"#, - r#" -/// Creates a UUID using the supplied bytes in little endian order. -/// The individual fields encoded in the buffer will be flipped. -/// # Examples -/// Basic usage: -/// ``` -/// # fn main() -> Result<(), uuid::Error> { -/// # use uuid::Uuid; -/// let bytes = [ -/// 0xa1, 0xa2, 0xa3, 0xa4, -/// 0xb1, 0xb2, -/// 0xc1, 0xc2, -/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, -/// ]; -/// let uuid = Uuid::from_bytes_le(bytes); -/// assert_eq!( -/// "a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8", -/// uuid.hyphenated().to_string(), -/// ); -/// # Ok(()) -/// # } -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_bytes_le(b: [u8; 16]) -> bevy::utils::Uuid; - -"#, - r#" - - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::utils::Uuid; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a random UUID. -/// This uses the [`getrandom`] crate to utilise the operating system's RNG -/// as the source of random numbers. If you'd like to use a custom -/// generator, don't use this method: generate random bytes using your -/// custom generator and pass them to the -/// [`uuid::Builder::from_random_bytes`][from_random_bytes] function -/// instead. -/// Note that usage of this method requires the `v4` feature of this crate -/// to be enabled. -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::{Uuid, Version}; -/// let uuid = Uuid::new_v4(); -/// assert_eq!(Some(Version::Random), uuid.get_version()); -/// ``` -/// # References -/// * [Version 4 UUIDs in RFC4122](https://www.rfc-editor.org/rfc/rfc4122#section-4.4) -/// [`getrandom`]: https://crates.io/crates/getrandom -/// [from_random_bytes]: struct.Builder.html#method.from_random_bytes - - #[lua(kind = "Function", output(proxy))] - fn new_v4() -> bevy::utils::Uuid; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_utils::Uuid) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{}", _self) -} -"#] -)] -pub struct Uuid(); -#[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( - "Duration", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Instant", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroI128", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroI16", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroI32", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroI64", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroI8", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroU128", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroU16", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroU32", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroU64", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroU8", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroUsize", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "PathBuf", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Quat", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Vec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "IVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "IVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "IVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "I64Vec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "I64Vec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "I64Vec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "UVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "UVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "UVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "U64Vec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "U64Vec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "U64Vec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Vec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Vec3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Vec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "BVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "BVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "BVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Mat2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Mat3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Mat3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Mat4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DMat2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DMat3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DMat4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Affine2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Affine3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DAffine2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DAffine3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "DQuat", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "BVec3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "BVec4A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Direction2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Circle", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Ellipse", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Plane2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Segment2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Triangle2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Rectangle", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "RegularPolygon", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaRegularPolygon, - >::new, - )?; - instances - .add_instance( - "Capsule2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Direction3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Sphere", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Plane3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Segment3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Cuboid", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Cylinder", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Capsule3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Torus", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "IRect", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Rect", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "URect", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "NonZeroIsize", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Uuid", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - Ok(()) - } -} -pub struct BevyReflectAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyReflectAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "BevyReflectAPI", - |tw| { - tw.document_global_instance::() - .expect("Something went wrong documenting globals") - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDuration, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroI128, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroI16, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroI32, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroI64, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroI8, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroU128, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroU16, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroU32, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroU64, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroU8, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroUsize, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAffine3A, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDAffine2, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDAffine3, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDirection2d, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaSegment2d, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaTriangle2d, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRectangle, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRegularPolygon, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCapsule2d, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDirection3d, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaSegment3d, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCylinder, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCapsule3d, - >, - >() - .process_type::() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaNonZeroIsize, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() - }, - ), - ) - } - 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::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - } -} diff --git a/crates/bevy_script_api/src/providers/bevy_transform.rs b/crates/bevy_script_api/src/providers/bevy_transform.rs deleted file mode 100644 index c9e46db5..00000000 --- a/crates/bevy_script_api/src/providers/bevy_transform.rs +++ /dev/null @@ -1,739 +0,0 @@ -// @generated by cargo bevy-api-gen generate, modify the templates not this file -#![allow(clippy::all)] -#![allow(unused, deprecated, dead_code)] -#![cfg_attr(rustfmt, rustfmt_skip)] -use super::bevy_ecs::*; -use super::bevy_reflect::*; -use super::bevy_core::*; -use super::bevy_hierarchy::*; -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::transform::components::GlobalTransform", - functions[r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul( - self, - #[proxy] - global_transform: bevy::transform::components::GlobalTransform, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &components::global_transform::GlobalTransform) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul( - self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] value: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_xyz(x: f32, y: f32, z: f32) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_translation( - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_rotation( - #[proxy] - rotation: bevy::math::Quat, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_scale( - #[proxy] - scale: bevy::math::Vec3, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" -/// Returns the 3d affine transformation matrix as a [`Mat4`]. - - #[lua(kind = "Method", output(proxy))] - fn compute_matrix(&self) -> bevy::math::Mat4; - -"#, - r#" -/// Returns the 3d affine transformation matrix as an [`Affine3A`]. - - #[lua(kind = "Method", output(proxy))] - fn affine(&self) -> bevy::math::Affine3A; - -"#, - r#" -/// Returns the transformation as a [`Transform`]. -/// The transform is expected to be non-degenerate and without shearing, or the output -/// will be invalid. - - #[lua(kind = "Method", output(proxy))] - fn compute_transform(&self) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns the [`Transform`] `self` would have if it was a child of an entity -/// with the `parent` [`GlobalTransform`]. -/// This is useful if you want to "reparent" an [`Entity`](bevy_ecs::entity::Entity). -/// Say you have an entity `e1` that you want to turn into a child of `e2`, -/// but you want `e1` to keep the same global transform, even after re-parenting. You would use: -/// ``` -/// # use bevy_transform::prelude::{GlobalTransform, Transform}; -/// # use bevy_ecs::prelude::{Entity, Query, Component, Commands}; -/// # use bevy_hierarchy::{prelude::Parent, BuildChildren}; -/// #[derive(Component)] -/// struct ToReparent { -/// new_parent: Entity, -/// } -/// fn reparent_system( -/// mut commands: Commands, -/// mut targets: Query<(&mut Transform, Entity, &GlobalTransform, &ToReparent)>, -/// transforms: Query<&GlobalTransform>, -/// ) { -/// for (mut transform, entity, initial, to_reparent) in targets.iter_mut() { -/// if let Ok(parent_transform) = transforms.get(to_reparent.new_parent) { -/// *transform = initial.reparented_to(parent_transform); -/// commands.entity(entity) -/// .remove::() -/// .set_parent(to_reparent.new_parent); -/// } -/// } -/// } -/// ``` -/// The transform is expected to be non-degenerate and without shearing, or the output -/// will be invalid. - - #[lua(kind = "Method", output(proxy))] - fn reparented_to( - &self, - #[proxy] - parent: &components::global_transform::GlobalTransform, - ) -> bevy::transform::components::Transform; - -"#, - r#" -///Return the local right vector (X). - - #[lua(kind = "Method", output(proxy))] - fn right(&self) -> bevy::math::Vec3; - -"#, - r#" -///Return the local left vector (-X). - - #[lua(kind = "Method", output(proxy))] - fn left(&self) -> bevy::math::Vec3; - -"#, - r#" -///Return the local up vector (Y). - - #[lua(kind = "Method", output(proxy))] - fn up(&self) -> bevy::math::Vec3; - -"#, - r#" -///Return the local down vector (-Y). - - #[lua(kind = "Method", output(proxy))] - fn down(&self) -> bevy::math::Vec3; - -"#, - r#" -///Return the local back vector (Z). - - #[lua(kind = "Method", output(proxy))] - fn back(&self) -> bevy::math::Vec3; - -"#, - r#" -///Return the local forward vector (-Z). - - #[lua(kind = "Method", output(proxy))] - fn forward(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Get the translation as a [`Vec3`]. - - #[lua(kind = "Method", output(proxy))] - fn translation(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Get the translation as a [`Vec3A`]. - - #[lua(kind = "Method", output(proxy))] - fn translation_vec3a(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Get an upper bound of the radius from the given `extents`. - - #[lua(kind = "Method")] - fn radius_vec3a(&self, #[proxy] extents: bevy::math::Vec3A) -> f32; - -"#, - r#" -/// Transforms the given `point`, applying shear, scale, rotation and translation. -/// This moves `point` into the local space of this [`GlobalTransform`]. - - #[lua(kind = "Method", output(proxy))] - fn transform_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Multiplies `self` with `transform` component by component, returning the -/// resulting [`GlobalTransform`] - - #[lua(kind = "Method", output(proxy))] - fn mul_transform( - &self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct GlobalTransform(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::transform::components::Transform", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::transform::components::Transform; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul( - self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::Transform; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &components::transform::Transform) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul( - self, - #[proxy] - global_transform: bevy::transform::components::GlobalTransform, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" -/// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component -/// is used for z-ordering elements: higher `z`-value will be in front of lower -/// `z`-value. - - #[lua(kind = "Function", output(proxy))] - fn from_xyz(x: f32, y: f32, z: f32) -> bevy::transform::components::Transform; - -"#, - r#" -/// Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine -/// transformation matrix. - - #[lua(kind = "Function", output(proxy))] - fn from_matrix( - #[proxy] - matrix: bevy::math::Mat4, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Creates a new [`Transform`], with `translation`. Rotation will be 0 and scale 1 on -/// all axes. - - #[lua(kind = "Function", output(proxy))] - fn from_translation( - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Creates a new [`Transform`], with `rotation`. Translation will be 0 and scale 1 on -/// all axes. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation( - #[proxy] - rotation: bevy::math::Quat, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Creates a new [`Transform`], with `scale`. Translation will be 0 and rotation 0 on -/// all axes. - - #[lua(kind = "Function", output(proxy))] - fn from_scale( - #[proxy] - scale: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new rotation so that [`Transform::forward`] -/// points towards the `target` position and [`Transform::up`] points towards `up`. -/// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: -/// * if `target` is the same as the transform translation, `Vec3::Z` is used instead -/// * if `up` is zero, `Vec3::Y` is used instead -/// * if the resulting forward direction is parallel with `up`, an orthogonal vector is used as the "right" direction - - #[lua(kind = "Method", output(proxy))] - fn looking_at( - self, - #[proxy] - target: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new rotation so that [`Transform::forward`] -/// points in the given `direction` and [`Transform::up`] points towards `up`. -/// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: -/// * if `direction` is zero, `Vec3::Z` is used instead -/// * if `up` is zero, `Vec3::Y` is used instead -/// * if `direction` is parallel with `up`, an orthogonal vector is used as the "right" direction - - #[lua(kind = "Method", output(proxy))] - fn looking_to( - self, - #[proxy] - direction: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new translation. - - #[lua(kind = "Method", output(proxy))] - fn with_translation( - self, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new rotation. - - #[lua(kind = "Method", output(proxy))] - fn with_rotation( - self, - #[proxy] - rotation: bevy::math::Quat, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new scale. - - #[lua(kind = "Method", output(proxy))] - fn with_scale( - self, - #[proxy] - scale: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns the 3d affine transformation matrix from this transforms translation, -/// rotation, and scale. - - #[lua(kind = "Method", output(proxy))] - fn compute_matrix(&self) -> bevy::math::Mat4; - -"#, - r#" -/// Returns the 3d affine transformation matrix from this transforms translation, -/// rotation, and scale. - - #[lua(kind = "Method", output(proxy))] - fn compute_affine(&self) -> bevy::math::Affine3A; - -"#, - r#" -/// Rotates this [`Transform`] by the given rotation. -/// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent. -/// # Examples -/// - [`3d_rotation`] -/// [`3d_rotation`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/3d_rotation.rs - - #[lua(kind = "MutatingMethod")] - fn rotate(&mut self, #[proxy] rotation: bevy::math::Quat) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around the given `axis` by `angle` (in radians). -/// If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent. - - #[lua(kind = "MutatingMethod")] - fn rotate_axis(&mut self, #[proxy] axis: bevy::math::Vec3, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around the `X` axis by `angle` (in radians). -/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. - - #[lua(kind = "MutatingMethod")] - fn rotate_x(&mut self, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around the `Y` axis by `angle` (in radians). -/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. - - #[lua(kind = "MutatingMethod")] - fn rotate_y(&mut self, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around the `Z` axis by `angle` (in radians). -/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. - - #[lua(kind = "MutatingMethod")] - fn rotate_z(&mut self, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] by the given `rotation`. -/// The `rotation` is relative to this [`Transform`]'s current rotation. - - #[lua(kind = "MutatingMethod")] - fn rotate_local(&mut self, #[proxy] rotation: bevy::math::Quat) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around its local `axis` by `angle` (in radians). - - #[lua(kind = "MutatingMethod")] - fn rotate_local_axis(&mut self, #[proxy] axis: bevy::math::Vec3, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around its local `X` axis by `angle` (in radians). - - #[lua(kind = "MutatingMethod")] - fn rotate_local_x(&mut self, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around its local `Y` axis by `angle` (in radians). - - #[lua(kind = "MutatingMethod")] - fn rotate_local_y(&mut self, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around its local `Z` axis by `angle` (in radians). - - #[lua(kind = "MutatingMethod")] - fn rotate_local_z(&mut self, angle: f32) -> (); - -"#, - r#" -/// Translates this [`Transform`] around a `point` in space. -/// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. - - #[lua(kind = "MutatingMethod")] - fn translate_around( - &mut self, - #[proxy] - point: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, - ) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around a `point` in space. -/// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. - - #[lua(kind = "MutatingMethod")] - fn rotate_around( - &mut self, - #[proxy] - point: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, - ) -> (); - -"#, - r#" -/// Rotates this [`Transform`] so that [`Transform::forward`] points towards the `target` position, -/// and [`Transform::up`] points towards `up`. -/// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: -/// * if `target` is the same as the transform translation, `Vec3::Z` is used instead -/// * if `up` is zero, `Vec3::Y` is used instead -/// * if the resulting forward direction is parallel with `up`, an orthogonal vector is used as the "right" direction - - #[lua(kind = "MutatingMethod")] - fn look_at( - &mut self, - #[proxy] - target: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> (); - -"#, - r#" -/// Rotates this [`Transform`] so that [`Transform::forward`] points in the given `direction` -/// and [`Transform::up`] points towards `up`. -/// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases: -/// * if `direction` is zero, `Vec3::NEG_Z` is used instead -/// * if `up` is zero, `Vec3::Y` is used instead -/// * if `direction` is parallel with `up`, an orthogonal vector is used as the "right" direction - - #[lua(kind = "MutatingMethod")] - fn look_to( - &mut self, - #[proxy] - direction: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> (); - -"#, - r#" -/// Multiplies `self` with `transform` component by component, returning the -/// resulting [`Transform`] - - #[lua(kind = "Method", output(proxy))] - fn mul_transform( - &self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Transforms the given `point`, applying scale, rotation and translation. -/// If this [`Transform`] has a parent, this will transform a `point` that is -/// relative to the parent's [`Transform`] into one relative to this [`Transform`]. -/// If this [`Transform`] does not have a parent, this will transform a `point` -/// that is in global space into one relative to this [`Transform`]. -/// If you want to transform a `point` in global space to the local space of this [`Transform`], -/// consider using [`GlobalTransform::transform_point()`] instead. - - #[lua(kind = "Method", output(proxy))] - fn transform_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -/// Returns `true` if, and only if, translation, rotation and scale all are -/// finite. If any of them contains a `NaN`, positive or negative infinity, -/// this will return `false`. - - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] value: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Transform { - #[lua(output(proxy))] - translation: bevy::math::Vec3, - #[lua(output(proxy))] - rotation: bevy::math::Quat, - #[lua(output(proxy))] - scale: bevy::math::Vec3, -} -#[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( - "GlobalTransform", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGlobalTransform, - >::new, - )?; - instances - .add_instance( - "Transform", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - Ok(()) - } -} -pub struct BevyTransformAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyTransformAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "BevyTransformAPI", - |tw| { - tw.document_global_instance::() - .expect("Something went wrong documenting globals") - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGlobalTransform, - >, - >() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaTransform, - >, - >() - }, - ), - ) - } - 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::(); - app.register_foreign_lua_type::(); - } -} diff --git a/crates/bevy_script_api/src/providers/bevy_window.rs b/crates/bevy_script_api/src/providers/bevy_window.rs deleted file mode 100644 index 5815cca5..00000000 --- a/crates/bevy_script_api/src/providers/bevy_window.rs +++ /dev/null @@ -1,1682 +0,0 @@ -// @generated by cargo bevy-api-gen generate, modify the templates not this file -#![allow(clippy::all)] -#![allow(unused, deprecated, dead_code)] -#![cfg_attr(rustfmt, rustfmt_skip)] -use super::bevy_ecs::*; -use super::bevy_reflect::*; -use super::bevy_input::*; -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::window::prelude::CursorEntered", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::CursorEntered; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::CursorEntered) -> 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) -} -"#] -)] -pub struct CursorEntered { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::CursorIcon", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::CursorIcon; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &cursor::CursorIcon) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct CursorIcon {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::CursorLeft", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::CursorLeft; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::CursorLeft) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct CursorLeft { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::CursorMoved", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::CursorMoved; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::CursorMoved) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct CursorMoved { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - #[lua(output(proxy))] - position: bevy::math::Vec2, - delta: ReflectedValue, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::FileDragAndDrop", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::FileDragAndDrop) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::FileDragAndDrop; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct FileDragAndDrop {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::Ime", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::Ime; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::Ime) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Ime {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::MonitorSelection", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::MonitorSelection) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::MonitorSelection; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct MonitorSelection {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::ReceivedCharacter", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::ReceivedCharacter; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::ReceivedCharacter) -> 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) -} -"#] -)] -pub struct ReceivedCharacter { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - #[lua(output(proxy))] - char: smol_str::SmolStr, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::Window", - functions[r#" -/// Setting to true will attempt to maximize the window. -/// Setting to false will attempt to un-maximize the window. - - #[lua(kind = "MutatingMethod")] - fn set_maximized(&mut self, maximized: bool) -> (); - -"#, - r#" -/// Setting to true will attempt to minimize the window. -/// Setting to false will attempt to un-minimize the window. - - #[lua(kind = "MutatingMethod")] - fn set_minimized(&mut self, minimized: bool) -> (); - -"#, - r#" -/// The window's client area width in logical pixels. -/// See [`WindowResolution`] for an explanation about logical/physical sizes. - - #[lua(kind = "Method")] - fn width(&self) -> f32; - -"#, - r#" -/// The window's client area height in logical pixels. -/// See [`WindowResolution`] for an explanation about logical/physical sizes. - - #[lua(kind = "Method")] - fn height(&self) -> f32; - -"#, - r#" -/// The window's client area width in physical pixels. -/// See [`WindowResolution`] for an explanation about logical/physical sizes. - - #[lua(kind = "Method")] - fn physical_width(&self) -> u32; - -"#, - r#" -/// The window's client area height in physical pixels. -/// See [`WindowResolution`] for an explanation about logical/physical sizes. - - #[lua(kind = "Method")] - fn physical_height(&self) -> u32; - -"#, - r#" -/// The window's scale factor. -/// Ratio of physical size to logical size, see [`WindowResolution`]. - - #[lua(kind = "Method")] - fn scale_factor(&self) -> f32; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::Window; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Window { - #[lua(output(proxy))] - cursor: bevy::window::Cursor, - #[lua(output(proxy))] - present_mode: bevy::window::PresentMode, - #[lua(output(proxy))] - mode: bevy::window::WindowMode, - #[lua(output(proxy))] - position: bevy::window::prelude::WindowPosition, - #[lua(output(proxy))] - resolution: bevy::window::WindowResolution, - title: std::string::String, - name: std::option::Option, - #[lua(output(proxy))] - composite_alpha_mode: bevy::window::CompositeAlphaMode, - #[lua(output(proxy))] - resize_constraints: bevy::window::prelude::WindowResizeConstraints, - resizable: bool, - #[lua(output(proxy))] - enabled_buttons: bevy::window::EnabledButtons, - decorations: bool, - transparent: bool, - focused: bool, - #[lua(output(proxy))] - window_level: bevy::window::WindowLevel, - canvas: std::option::Option, - prevent_default_event_handling: bool, - #[lua(output(proxy))] - internal: bevy::window::InternalWindowState, - ime_enabled: bool, - #[lua(output(proxy))] - ime_position: bevy::math::Vec2, - window_theme: ReflectedValue, - visible: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::WindowMoved", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::WindowMoved; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowMoved) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowMoved { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - #[lua(output(proxy))] - position: bevy::math::IVec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::WindowPosition", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::WindowPosition; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::WindowPosition) -> bool; - -"#, - r#" -/// Creates a new [`WindowPosition`] at a position. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - position: bevy::math::IVec2, - ) -> bevy::window::prelude::WindowPosition; - -"#, - r#" -/// Set the position to a specific point. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, #[proxy] position: bevy::math::IVec2) -> (); - -"#, - r#" -/// Set the window to a specific monitor. - - #[lua(kind = "MutatingMethod")] - fn center( - &mut self, - #[proxy] - monitor: bevy::window::prelude::MonitorSelection, - ) -> (); - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowPosition {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::prelude::WindowResizeConstraints", - functions[r#" -/// Checks if the constraints are valid. -/// Will output warnings if it isn't. - - #[lua(kind = "Method", output(proxy))] - fn check_constraints(&self) -> bevy::window::prelude::WindowResizeConstraints; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::WindowResizeConstraints; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::WindowResizeConstraints) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowResizeConstraints { - min_width: f32, - min_height: f32, - max_width: f32, - max_height: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowResized", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowResized) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowResized; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowResized { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - width: f32, - height: f32, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowCreated", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowCreated; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowCreated) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowCreated { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowClosed", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowClosed) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowClosed; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowClosed { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowCloseRequested", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowCloseRequested; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowCloseRequested) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowCloseRequested { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowDestroyed", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowDestroyed; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowDestroyed) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowDestroyed { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::RequestRedraw", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::RequestRedraw) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::RequestRedraw; - -"#, - 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) -} -"#] -)] -pub struct RequestRedraw {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowFocused", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowFocused; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowFocused) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowFocused { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - focused: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowOccluded", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowOccluded; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowOccluded) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowOccluded { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - occluded: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowScaleFactorChanged", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowScaleFactorChanged; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowScaleFactorChanged) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowScaleFactorChanged { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - scale_factor: f64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowBackendScaleFactorChanged", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowBackendScaleFactorChanged) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowBackendScaleFactorChanged; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowBackendScaleFactorChanged { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - scale_factor: f64, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowThemeChanged", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::WindowThemeChanged) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowThemeChanged; - -"#, - 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) -} -"#] -)] -pub struct WindowThemeChanged { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - #[lua(output(proxy))] - theme: bevy::window::WindowTheme, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::ApplicationLifetime", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::ApplicationLifetime; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &event::ApplicationLifetime) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct ApplicationLifetime {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::PrimaryWindow", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::PrimaryWindow; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::PrimaryWindow) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct PrimaryWindow {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::Cursor", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::Cursor; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Cursor { - #[lua(output(proxy))] - icon: bevy::window::prelude::CursorIcon, - visible: bool, - #[lua(output(proxy))] - grab_mode: bevy::window::CursorGrabMode, - hit_test: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::CursorGrabMode", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::CursorGrabMode) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::CursorGrabMode; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct CursorGrabMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::CompositeAlphaMode", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::CompositeAlphaMode) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::CompositeAlphaMode; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct CompositeAlphaMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowResolution", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::WindowResolution) -> bool; - -"#, - r#" -/// Creates a new [`WindowResolution`]. - - #[lua(kind = "Function", output(proxy))] - fn new(logical_width: f32, logical_height: f32) -> bevy::window::WindowResolution; - -"#, - r#" -/// Builder method for adding a scale factor override to the resolution. - - #[lua(kind = "Method", output(proxy))] - fn with_scale_factor_override( - self, - scale_factor_override: f32, - ) -> bevy::window::WindowResolution; - -"#, - r#" -/// The window's client area width in logical pixels. - - #[lua(kind = "Method")] - fn width(&self) -> f32; - -"#, - r#" -/// The window's client area height in logical pixels. - - #[lua(kind = "Method")] - fn height(&self) -> f32; - -"#, - r#" -/// The window's client area width in physical pixels. - - #[lua(kind = "Method")] - fn physical_width(&self) -> u32; - -"#, - r#" -/// The window's client area height in physical pixels. - - #[lua(kind = "Method")] - fn physical_height(&self) -> u32; - -"#, - r#" -/// The ratio of physical pixels to logical pixels. -/// `physical_pixels = logical_pixels * scale_factor` - - #[lua(kind = "Method")] - fn scale_factor(&self) -> f32; - -"#, - r#" -/// The window scale factor as reported by the window backend. -/// This value is unaffected by [`WindowResolution::scale_factor_override`]. - - #[lua(kind = "Method")] - fn base_scale_factor(&self) -> f32; - -"#, - r#" -/// The scale factor set with [`WindowResolution::set_scale_factor_override`]. -/// This value may be different from the scale factor reported by the window backend. - - #[lua(kind = "Method")] - fn scale_factor_override(&self) -> std::option::Option; - -"#, - r#" -/// Set the window's logical resolution. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, width: f32, height: f32) -> (); - -"#, - r#" -/// Set the window's physical resolution. -/// This will ignore the scale factor setting, so most of the time you should -/// prefer to use [`WindowResolution::set`]. - - #[lua(kind = "MutatingMethod")] - fn set_physical_resolution(&mut self, width: u32, height: u32) -> (); - -"#, - r#" -/// Set the window's scale factor, this may get overridden by the backend. - - #[lua(kind = "MutatingMethod")] - fn set_scale_factor(&mut self, scale_factor: f32) -> (); - -"#, - r#" -/// Set the window's scale factor, this will be used over what the backend decides. -/// This can change the logical and physical sizes if the resulting physical -/// size is not within the limits. - - #[lua(kind = "MutatingMethod")] - fn set_scale_factor_override( - &mut self, - scale_factor_override: std::option::Option, - ) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowResolution; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowResolution {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowMode", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::WindowMode) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowMode; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowLevel", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowLevel; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::WindowLevel) -> bool; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowLevel {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::PresentMode", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::PresentMode) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::PresentMode; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct PresentMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::InternalWindowState", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::InternalWindowState) -> bool; - -"#, - r#" -/// Consumes the current maximize request, if it exists. This should only be called by window backends. - - #[lua(kind = "MutatingMethod")] - fn take_maximize_request(&mut self) -> std::option::Option; - -"#, - r#" -/// Consumes the current minimize request, if it exists. This should only be called by window backends. - - #[lua(kind = "MutatingMethod")] - fn take_minimize_request(&mut self) -> std::option::Option; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::InternalWindowState; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct InternalWindowState {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowTheme", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowTheme; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::WindowTheme) -> 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) -} -"#] -)] -pub struct WindowTheme {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::EnabledButtons", - functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::EnabledButtons) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::EnabledButtons; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct EnabledButtons { - minimize: bool, - maximize: bool, - close: bool, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::WindowRef", - functions[r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowRef; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct WindowRef {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::window::NormalizedWindowRef", - functions[r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Fetch the entity of this window reference - - #[lua(kind = "Method", output(proxy))] - fn entity(&self) -> bevy::ecs::entity::Entity; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &window::NormalizedWindowRef) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::NormalizedWindowRef; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct NormalizedWindowRef(); -#[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( - "WindowPosition", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaWindowPosition, - >::new, - )?; - instances - .add_instance( - "WindowResolution", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaWindowResolution, - >::new, - )?; - Ok(()) - } -} -pub struct BevyWindowAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyWindowAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( - "BevyWindowAPI", - |tw| { - tw.document_global_instance::() - .expect("Something went wrong documenting globals") - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaWindowPosition, - >, - >() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaWindowResolution, - >, - >() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - .process_type::() - }, - ), - ) - } - 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::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::< - bevy::window::prelude::WindowResizeConstraints, - >(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - } -} diff --git a/crates/bevy_script_api/src/providers/mod.rs b/crates/bevy_script_api/src/providers/mod.rs deleted file mode 100644 index 62a19bbb..00000000 --- a/crates/bevy_script_api/src/providers/mod.rs +++ /dev/null @@ -1,80 +0,0 @@ -// @generated by cargo bevy-api-gen collect, modify the templates not this file -#![allow(clippy::all)] -#![allow(unused, deprecated, dead_code)] -#![cfg_attr(rustfmt, rustfmt_skip)] -pub(crate) mod bevy_ecs; -pub(crate) mod bevy_transform; -pub(crate) mod bevy_input; -pub(crate) mod bevy_core; -pub(crate) mod bevy_time; -pub(crate) mod bevy_hierarchy; -pub(crate) mod bevy_window; -pub(crate) mod bevy_reflect; -extern crate self as bevy_script_api; -use bevy_mod_scripting_core::docs::DocFragment; -pub struct LuaBevyAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for LuaBevyAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - bevy_ecs::BevyEcsAPIProvider.attach_api(ctx)?; - bevy_transform::BevyTransformAPIProvider.attach_api(ctx)?; - bevy_input::BevyInputAPIProvider.attach_api(ctx)?; - bevy_core::BevyCoreAPIProvider.attach_api(ctx)?; - bevy_time::BevyTimeAPIProvider.attach_api(ctx)?; - bevy_hierarchy::BevyHierarchyAPIProvider.attach_api(ctx)?; - bevy_window::BevyWindowAPIProvider.attach_api(ctx)?; - bevy_reflect::BevyReflectAPIProvider.attach_api(ctx)?; - Ok(()) - } - fn get_doc_fragment(&self) -> Option { - [ - bevy_ecs::BevyEcsAPIProvider.get_doc_fragment(), - bevy_transform::BevyTransformAPIProvider.get_doc_fragment(), - bevy_input::BevyInputAPIProvider.get_doc_fragment(), - bevy_core::BevyCoreAPIProvider.get_doc_fragment(), - bevy_time::BevyTimeAPIProvider.get_doc_fragment(), - bevy_hierarchy::BevyHierarchyAPIProvider.get_doc_fragment(), - bevy_window::BevyWindowAPIProvider.get_doc_fragment(), - bevy_reflect::BevyReflectAPIProvider.get_doc_fragment(), - ] - .into_iter() - .filter_map(|a: Option<_>| a) - .fold( - None, - |a, b| match a { - Some(a) => Some(a.merge(b)), - None => Some(b), - }, - ) - } - 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) { - bevy_ecs::BevyEcsAPIProvider.register_with_app(app); - bevy_transform::BevyTransformAPIProvider.register_with_app(app); - bevy_input::BevyInputAPIProvider.register_with_app(app); - bevy_core::BevyCoreAPIProvider.register_with_app(app); - bevy_time::BevyTimeAPIProvider.register_with_app(app); - bevy_hierarchy::BevyHierarchyAPIProvider.register_with_app(app); - bevy_window::BevyWindowAPIProvider.register_with_app(app); - bevy_reflect::BevyReflectAPIProvider.register_with_app(app); - } -} diff --git a/crates/bevy_script_api/src/rhai/bevy/mod.rs b/crates/bevy_script_api/src/rhai/bevy/mod.rs deleted file mode 100644 index 4ab540e1..00000000 --- a/crates/bevy_script_api/src/rhai/bevy/mod.rs +++ /dev/null @@ -1,272 +0,0 @@ -use bevy::prelude::Entity; -use bevy_mod_scripting_core::{prelude::*, world::WorldPointer}; - -#[allow(deprecated)] -use bevy_mod_scripting_rhai::{ - prelude::*, - rhai::{self, CustomType, INT}, -}; -use rhai::plugin::*; - -use crate::{ - common::bevy::{ScriptTypeRegistration, ScriptWorld}, - ReflectedValue, -}; - -use super::{RegisterForeignRhaiType, ToDynamic}; - -#[allow(deprecated)] -impl CustomType for ScriptTypeRegistration { - fn build(mut builder: rhai::TypeBuilder) { - builder - .with_name("TypeRegistration") - .with_fn("short_name", |self_: &mut Self| { - ImmutableString::from(self_.short_name()) - }) - .with_fn("type_name", |self_: &mut Self| self_.type_name()) - .with_fn("to_string", |self_: &mut Self| self_.to_string()) - .with_fn("to_debug", |self_: &mut Self| format!("{:?}", self_)); - } -} - -#[allow(deprecated)] -impl CustomType for ScriptWorld { - fn build(mut builder: rhai::TypeBuilder) { - builder - .with_name("World") - .with_fn("get_type_by_name", |self_: ScriptWorld, type_name: &str| { - self_ - .get_type_by_name(type_name) - .map(Dynamic::from) - .unwrap_or_default() - }) - .with_fn( - "add_default_component", - |self_: ScriptWorld, entity: Entity, type_registration: ScriptTypeRegistration| { - self_ - .add_default_component(entity, type_registration) - .map_err(|e| { - Box::new(EvalAltResult::ErrorRuntime( - Dynamic::from(e.to_string()), - Position::NONE, - )) - }) - .and_then(|ok| ok.to_dynamic()) - }, - ) - .with_fn( - "get_component", - |self_: ScriptWorld, entity: Entity, comp_type: ScriptTypeRegistration| { - let component = self_.get_component(entity, comp_type).map_err(|e| { - Box::new(EvalAltResult::ErrorRuntime( - e.to_string().into(), - Position::NONE, - )) - })?; - if let Some(c) = component { - c.to_dynamic() - } else { - Ok(Default::default()) - } - }, - ) - .with_fn( - "has_compoennt", - |self_: ScriptWorld, entity: Entity, comp_type: ScriptTypeRegistration| { - self_.has_component(entity, comp_type).map_err(|e| { - Box::new(EvalAltResult::ErrorRuntime( - e.to_string().into(), - Position::NONE, - )) - }) - }, - ) - .with_fn( - "remove_component", - |mut self_: ScriptWorld, entity: Entity, comp_type: ScriptTypeRegistration| { - self_.remove_component(entity, comp_type).map_err(|e| { - Box::new(EvalAltResult::ErrorRuntime( - e.to_string().into(), - Position::NONE, - )) - }) - }, - ) - .with_fn( - "get_resource", - |self_: ScriptWorld, res_type: ScriptTypeRegistration| { - let resource = self_.get_resource(res_type).map_err(|err| { - Box::new(EvalAltResult::ErrorRuntime( - err.to_string().into(), - Position::NONE, - )) - })?; - - if let Some(c) = resource { - c.to_dynamic() - } else { - Ok(Default::default()) - } - }, - ) - .with_fn( - "has_resource", - |self_: &mut ScriptWorld, res_type: ScriptTypeRegistration| { - self_.has_resource(res_type).map_err(|e| { - Box::new(EvalAltResult::ErrorRuntime( - e.to_string().into(), - Position::NONE, - )) - }) - }, - ) - .with_fn( - "remove_resource", - |self_: &mut ScriptWorld, res_type: ScriptTypeRegistration| { - self_.remove_resource(res_type).map_err(|e| { - Box::new(EvalAltResult::ErrorRuntime( - e.to_string().into(), - Position::NONE, - )) - }) - }, - ) - .with_fn("get_parent", |self_: ScriptWorld, entity: Entity| { - if let Some(parent) = self_.get_parent(entity) { - Dynamic::from(parent) - } else { - Dynamic::UNIT - } - }) - .with_fn("get_children", |self_: ScriptWorld, parent: Entity| { - self_ - .get_children(parent) - .into_iter() - .map(Dynamic::from) - .collect::>() - }) - .with_fn( - "push_child", - |self_: &mut ScriptWorld, parent: Entity, child: Entity| { - self_.push_child(parent, child) - }, - ) - .with_fn( - "remove_children", - |self_: &mut ScriptWorld, parent: Entity, children: Vec| { - self_.remove_children( - parent, - &children - .into_iter() - .map(Dynamic::cast::) - .collect::>(), - ) - }, - ) - .with_fn( - "remove_child", - |self_: &mut ScriptWorld, parent: Entity, child: Entity| { - self_.remove_children(parent, &[child]) - }, - ) - .with_fn( - "insert_children", - |self_: &mut ScriptWorld, parent: Entity, index: INT, children: Vec| { - self_.insert_children( - parent, - index.try_into().expect("number too large"), - &children - .into_iter() - .map(Dynamic::cast::) - .collect::>(), - ) - }, - ) - .with_fn( - "insert_child", - |self_: &mut ScriptWorld, parent: Entity, index: INT, child: Entity| { - self_.insert_children( - parent, - index.try_into().expect("number too large"), - &[child], - ) - }, - ) - .with_fn( - "despawn_children_recursive", - |self_: &mut ScriptWorld, entity: Entity| self_.despawn_children_recursive(entity), - ) - .with_fn( - "despawn_recursive", - |self_: &mut ScriptWorld, entity: Entity| self_.despawn_recursive(entity), - ) - .with_fn("spawn", |self_: &mut ScriptWorld| { - let mut w = self_.write(); - w.spawn(()).id() - }) - .with_fn("despawn", |self_: &mut ScriptWorld, entity: Entity| { - let mut w = self_.write(); - - w.despawn(entity) - }) - .with_fn("to_string", |self_: &mut ScriptWorld| self_.to_string()) - .with_fn("to_debug", |self_: &mut ScriptWorld| format!("{:?}", self_)); - } -} - -pub struct RhaiBevyAPIProvider; - -impl APIProvider for RhaiBevyAPIProvider { - type APITarget = Engine; - type ScriptContext = RhaiContext; - type DocTarget = RhaiDocFragment; - - fn attach_api(&mut self, engine: &mut Self::APITarget) -> Result<(), ScriptError> { - engine.build_type::(); - engine.build_type::(); - engine.build_type::(); - Ok(()) - } - - fn setup_script_runtime( - &mut self, - world_ptr: WorldPointer, - _script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - ctx.scope.set_value("world", ScriptWorld::new(world_ptr)); - Ok(()) - } - - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - ctx.scope.set_value("entity", script_data.entity); - Ok(()) - } - - fn get_doc_fragment(&self) -> Option { - None - } - - fn register_with_app(&self, app: &mut bevy::prelude::App) { - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - app.register_foreign_rhai_type::(); - } -} diff --git a/crates/bevy_script_api/src/rhai/mod.rs b/crates/bevy_script_api/src/rhai/mod.rs deleted file mode 100644 index d3e50f7d..00000000 --- a/crates/bevy_script_api/src/rhai/mod.rs +++ /dev/null @@ -1,194 +0,0 @@ -use ::std::borrow::Cow; - -use ::bevy::{ - prelude::{App, AppTypeRegistry}, - reflect::{FromType, GetTypeRegistration, Reflect}, -}; -#[allow(deprecated)] -use bevy_mod_scripting_rhai::rhai::{CustomType, Dynamic, EvalAltResult, INT}; - -use crate::{ReflectReference, ReflectedValue, ValueIndex}; - -pub mod bevy; -pub mod std; - -/// A trait allowing the registration of the [`RhaiProxyable`] trait with the type registry for foreign types -/// -/// If you have access to the type you should prefer to use `#[reflect(RhaiProxyable)]` instead. -/// This is exactly equivalent. -pub trait RegisterForeignRhaiType { - fn register_foreign_rhai_type( - &mut self, - ) -> &mut Self; -} - -impl RegisterForeignRhaiType for App { - fn register_foreign_rhai_type( - &mut self, - ) -> &mut Self { - { - let registry = self.world.resource_mut::(); - let mut registry = registry.write(); - - let rhai_data = >::from_type(); - - if let Some(registration) = registry.get_mut(TypeId::of::()) { - registration.insert(rhai_data) - } else { - let mut registration = T::get_type_registration(); - registration.insert(rhai_data); - registry.add_registration(registration); - } - } - - self - } -} - -pub trait RhaiProxyable { - fn ref_to_rhai(self_: ReflectReference) -> Result>; - fn apply_rhai(self_: &mut ReflectReference, new_val: Dynamic) - -> Result<(), Box>; -} - -pub trait FromRhaiProxy: Sized { - fn from_rhai_proxy(self_: Dynamic) -> Result>; -} - -pub trait ToRhaiProxy { - fn to_rhai_proxy(self) -> Result>; -} - -#[derive(Clone)] -pub struct ReflectRhaiProxyable { - ref_to_rhai: fn(ref_: ReflectReference) -> Result>, - apply_rhai: fn(ref_: &mut ReflectReference, new_val: Dynamic) -> Result<(), Box>, -} - -impl ReflectRhaiProxyable { - pub fn ref_to_rhai(&self, ref_: ReflectReference) -> Result> { - (self.ref_to_rhai)(ref_) - } - - pub fn apply_rhai( - &self, - ref_: &mut ReflectReference, - new_val: Dynamic, - ) -> Result<(), Box> { - (self.apply_rhai)(ref_, new_val) - } -} - -impl FromType for ReflectRhaiProxyable { - fn from_type() -> Self { - Self { - ref_to_rhai: T::ref_to_rhai, - apply_rhai: T::apply_rhai, - } - } -} - -pub trait ToDynamic { - fn to_dynamic(self) -> Result>; -} - -impl ToDynamic for ReflectedValue { - fn to_dynamic(self) -> Result> { - Ok(Dynamic::from(self)) - } -} - -impl ToDynamic for ReflectReference { - fn to_dynamic(self) -> Result> { - // clone since it's cheap and we don't want to clone self later - let world = self.world_ptr.clone(); - let world = world.read(); - - let type_data = world.resource::(); - let g = type_data.read(); - - let type_id = self.get(|s| s.type_id())?; - - if let Some(v) = g.get_type_data::(type_id) { - v.ref_to_rhai(self) - } else { - ReflectedValue { ref_: self }.to_dynamic() - } - } -} - -pub trait ApplyRhai { - fn apply_rhai(&mut self, value: Dynamic) -> Result<(), Box>; -} - -impl ApplyRhai for ReflectReference { - fn apply_rhai(&mut self, value: Dynamic) -> Result<(), Box> { - let world_ptr = self.world_ptr.clone(); - - // remove typedata from the world to be able to manipulate world - let proxyable = { - let world = world_ptr.read(); - let type_registry = world.resource::().read(); - type_registry - .get_type_data::(self.get(|s| s.type_id())?) - .cloned() - }; - - if let Some(ud) = proxyable { - return ud.apply_rhai(self, value); - } else if value.is::() { - let b = value.cast::(); - self.apply(&b.into())?; - return Ok(()); - } - - Err(Box::new(EvalAltResult::ErrorRuntime(self.get(|s| - format!("Attempted to assign `{}` = {value:?}. Did you forget to call `app.register_foreign_rhai_type::<{}>`?", - self.path, - s.get_represented_type_info().unwrap().type_path() - ))?.into(),Position::NONE) - )) - } -} - -impl ValueIndex for ReflectReference { - type Output = Result>; - - fn index(&self, index: Dynamic) -> Self::Output { - if index.is::() { - return Ok(self.index(index.as_int().unwrap() as usize)); - } else if index.is::() { - return Ok(self.index(Cow::Owned(index.into_string().unwrap()))); - }; - - Err(Box::new(EvalAltResult::ErrorMismatchDataType( - index.type_name().to_owned(), - "integer or string".to_owned(), - Position::NONE, - ))) - } -} - -use bevy_mod_scripting_rhai::rhai::plugin::*; - -#[allow(deprecated)] -impl CustomType for ReflectedValue { - fn build(mut builder: bevy_mod_scripting_rhai::rhai::TypeBuilder) { - builder - .with_indexer_get_result(|obj: &mut ReflectedValue, index: Dynamic| { - obj.ref_.index(index)?.to_dynamic() - }) - .with_indexer_set_result(|obj: &mut ReflectedValue, index: Dynamic, value: Dynamic| { - obj.ref_.index(index)?.apply_rhai(value) - }) - .with_fn("to_debug", |self_: &mut ReflectedValue| { - format!("{:?}", self_) - }) - .with_fn("to_string", |self_: &mut ReflectedValue| { - self_ - .ref_ - .get(|s| format!("{:?}", &s)) - .map_err::, _>(|e| e.into()) - }); - } -} diff --git a/crates/bevy_script_api/src/rhai/std.rs b/crates/bevy_script_api/src/rhai/std.rs deleted file mode 100644 index a0bb178b..00000000 --- a/crates/bevy_script_api/src/rhai/std.rs +++ /dev/null @@ -1,427 +0,0 @@ -use std::{ - any::type_name, - fmt::{Debug, Display}, - iter::Map, -}; - -use bevy::reflect::{FromReflect, Reflect, TypePath}; -#[allow(deprecated)] -use bevy_mod_scripting_rhai::rhai::{CustomType, Dynamic, Engine, EvalAltResult, Position}; - -use crate::{ - common::std::ScriptVec, error::ReflectionError, ReflectReference, ReflectionPathElement, - ValueIndex, -}; - -use super::{ApplyRhai, FromRhaiProxy, RhaiProxyable, ToDynamic, ToRhaiProxy}; - -impl RhaiProxyable for T { - fn ref_to_rhai(self_: crate::ReflectReference) -> Result> { - self_.get_typed(|self_: &T| Ok(Dynamic::from(self_.clone())))? - } - - fn apply_rhai( - self_: &mut crate::ReflectReference, - new_val: Dynamic, - ) -> Result<(), Box> { - let other = if new_val.is::() { - new_val.cast::() - } else { - return Err(Box::new(EvalAltResult::ErrorMismatchDataType( - stringify!(T).to_owned(), - new_val.type_name().to_string(), - Position::NONE, - ))); - }; - - self_.set_val(other)?; - Ok(()) - } -} - -/// A marker trait signifying this type is to receive an automatic proxy implementation via `Dynamic::from`. -/// This means the proxy for this type is the type itself, and is created by cloning the original reference. -pub trait RhaiCopy {} - -/// Implements RhaiProxyabel for a numeric type via another proxy type by coercing the type -macro_rules! impl_rhai_proxy { - // i.e. impl_rhai_proxy!(String as Into) - ($type:ty as Into) => { - impl_rhai_proxy!($type,$type,self: {self.into()}, s: {s.into()}); - }; - // i.e. impl_rhai_proxy!(u32 as i64) - ($type:ty as $proxy_type:ty) => { - impl_rhai_proxy!($type, $proxy_type,self:{(self as $proxy_type).into()}, s:{(*s as $proxy_type).into()}); - }; - // i.e. impl_rhai_proxy!(ident, u32, i64, (*ident as i64).into()) expression is used in ref_to_rhai - ($type:ty, $proxy_type:ty,$self:ident: {$($proxy_expr:tt)*}, $self_to_rhai:ident : {$($proxy_expr_to_rhai:tt)*} ) => { - impl RhaiProxyable for $type { - fn ref_to_rhai( - self_: crate::ReflectReference, - ) -> Result> { - self_.get_typed(|$self_to_rhai: &$type| Ok($($proxy_expr_to_rhai)*))? - } - - fn apply_rhai( - self_: &mut crate::ReflectReference, - new_val: Dynamic, - ) -> Result<(), Box> { - self_.set_val(Self::from_rhai_proxy(new_val)?)?; - Ok(()) - } - } - - impl FromRhaiProxy for $type { - #[inline(always)] - fn from_rhai_proxy(self_: Dynamic) -> Result> { - if self_.is::<$proxy_type>(){ - Ok(self_.cast::<$proxy_type>() as $type) - } else { - Err(Box::new(EvalAltResult::ErrorMismatchDataType( - stringify!($type).to_owned(), - self_.type_name().to_owned(), - Position::NONE, - ))) - } - - } - } - - impl ToRhaiProxy for $type { - #[inline(always)] - fn to_rhai_proxy($self) -> Result> { - Ok($($proxy_expr)*) - } - } - }; -} -use bevy_mod_scripting_rhai::rhai::{FLOAT, INT}; - -impl_rhai_proxy!(i8 as INT); -impl_rhai_proxy!(i16 as INT); -impl_rhai_proxy!(i32 as INT); -impl_rhai_proxy!(i64 as INT); -impl_rhai_proxy!(i128 as INT); -impl_rhai_proxy!(isize as INT); -impl_rhai_proxy!(u8 as INT); -impl_rhai_proxy!(u16 as INT); -impl_rhai_proxy!(u32 as INT); -impl_rhai_proxy!(u64 as INT); -impl_rhai_proxy!(u128 as INT); -impl_rhai_proxy!(usize as INT); -impl_rhai_proxy!(f32 as FLOAT); -impl_rhai_proxy!(f64 as FLOAT); -impl_rhai_proxy!(bool as bool); -impl_rhai_proxy!(String as Into); - -impl RhaiProxyable - for Option -{ - fn ref_to_rhai(self_: crate::ReflectReference) -> Result> { - self_.get_typed(|s: &Option| match s { - Some(_) => T::ref_to_rhai(self_.sub_ref(ReflectionPathElement::SubReflection { - label: "as_ref", - get: std::sync::Arc::new(|ref_| { - ref_.downcast_ref::>() - .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.get_represented_type_info().unwrap().type_path().into(), - to: stringify!(Option).into(), - })? - .as_ref() - .map(|t| t as &dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - }), - get_mut: std::sync::Arc::new(|ref_| { - ref_.downcast_mut::>() - // TODO: there is some weird borrow checker fuckery going on here - // i tried having from: ref_.get_represented_type_info().unwrap().type_path().into() instead of "Reflect" - // and lying this out in an if let expression, but nothing will satisfy the borrow checker here, so leaving this for now - .ok_or_else(|| ReflectionError::CannotDowncast { - from: "Reflect".into(), - to: stringify!(Option).into(), - })? - .as_mut() - .map(|t| t as &mut dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - }), - })), - None => Ok(Dynamic::UNIT), - })? - } - - fn apply_rhai( - self_: &mut crate::ReflectReference, - new_val: Dynamic, - ) -> Result<(), Box> { - if new_val.is::<()>() { - self_.get_mut_typed(|s: &mut Option| { - *s = None; - Ok(()) - })? - } else { - // we need to do this in two passes, first - // ensure that the target type is the 'some' variant to allow a sub reference - - let is_none = self_.get_typed(|s: &Option| s.is_none())?; - - if is_none { - return self_.get_mut_typed(|s: &mut Option| { - *s = Some(T::from_rhai_proxy(new_val)?); - Ok::<_, Box>(()) - })?; - } - - T::apply_rhai( - &mut self_.sub_ref(ReflectionPathElement::SubReflection { - label: "", - get: std::sync::Arc::new(|ref_| { - ref_.downcast_ref::>() - .ok_or_else(|| ReflectionError::CannotDowncast { - from: ref_.get_represented_type_info().unwrap().type_path().into(), - to: stringify!(Option).into(), - })? - .as_ref() - .map(|t| t as &dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - }), - get_mut: std::sync::Arc::new(|ref_| { - if ref_.is::>() { - ref_.downcast_mut::>() - .unwrap() - .as_mut() - .map(|t| t as &mut dyn Reflect) - .ok_or_else(|| { - ReflectionError::Other( - "Stale reference to Option. Cannot sub reflect.".to_owned(), - ) - }) - } else { - Err(ReflectionError::CannotDowncast { - from: ref_.get_represented_type_info().unwrap().type_path().into(), - to: stringify!(Option).into(), - }) - } - }), - }), - new_val, - ) - } - } -} - -impl FromRhaiProxy for Option { - fn from_rhai_proxy(self_: Dynamic) -> Result> { - if self_.is::<()>() { - Ok(None) - } else { - T::from_rhai_proxy(self_).map(Option::Some) - } - } -} - -impl ToRhaiProxy for Option { - fn to_rhai_proxy(self) -> Result> { - match self { - Some(v) => v.to_rhai_proxy(), - None => Ok(Dynamic::UNIT), - } - } -} - -/// Composite trait composing the various traits required for a type `T` to be used as part of a RhaiVec -pub trait RhaiVecElem: FromReflect + TypePath + RhaiProxyable + FromRhaiProxy + Clone {} -impl RhaiVecElem for T {} - -/// A ScriptVec wrapper which implements a custom iterator ontop of ScriptVec's -pub struct RhaiVec(pub ScriptVec); - -impl Clone for RhaiVec { - fn clone(&self) -> Self { - Self(self.0.clone()) - } -} - -impl Debug for RhaiVec { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } -} - -impl Display for RhaiVec { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - -impl RhaiVec { - pub fn new_ref(self_: crate::ReflectReference) -> Self { - Self(ScriptVec::::new_ref(self_)) - } -} - -impl std::ops::Deref for RhaiVec { - type Target = ScriptVec; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl std::ops::DerefMut for RhaiVec { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl IntoIterator for RhaiVec { - type Item = Result>; - - type IntoIter = - Map< as IntoIterator>::IntoIter, fn(ReflectReference) -> Self::Item>; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter().map(|v| v.to_dynamic()) - } -} - -impl RhaiProxyable for Vec { - fn ref_to_rhai(self_: crate::ReflectReference) -> Result> { - Ok(Dynamic::from(RhaiVec::::new_ref(self_))) - } - - fn apply_rhai( - self_: &mut crate::ReflectReference, - new_val: Dynamic, - ) -> Result<(), Box> { - if new_val.is::>() { - let last_target_idx = self_.get_typed(|s: &Vec| s.len())? - 1; - // there is also another case to consider, Vec has a lua representation available as well (table) - // if we receive one of those, we should also apply it - for (idx, entry) in new_val.cast::>().into_iter().enumerate() { - if idx > last_target_idx { - // here we don't need to do anything special just use LuaProxyable impl - T::apply_rhai(&mut self_.index(idx), entry)?; - } else { - // here we don't have anything to apply this to - // use FromLua impl - self_.get_mut_typed(|s: &mut Vec| { - s[idx] = T::from_rhai_proxy(entry)?; - Ok::<_, Box>(()) - })??; - } - } - Ok(()) - } else if new_val.is::>() { - let vec = new_val.cast::>(); - self_.apply(&vec.ref_)?; - Ok(()) - } else { - Err(Box::new(EvalAltResult::ErrorMismatchDataType( - "Array or Vec".to_owned(), - new_val.type_name().to_owned(), - Position::NONE, - ))) - } - } -} - -impl FromRhaiProxy for Vec { - fn from_rhai_proxy(self_: Dynamic) -> Result> { - if self_.is::>() { - let vec = self_.cast::>(); - vec.ref_.get_typed(|s: &Vec| Ok(s.clone()))? - } else if self_.is::>() { - self_ - .cast::>() - .into_iter() - .map(|v| T::from_rhai_proxy(v)) - .collect::, _>>() - } else { - Err(Box::new(EvalAltResult::ErrorMismatchDataType( - "Array or Vec".to_owned(), - self_.type_name().to_owned(), - Position::NONE, - ))) - } - } -} - -impl ToRhaiProxy for Vec { - fn to_rhai_proxy(self) -> Result> { - self.into_iter() - .map(|v| T::to_rhai_proxy(v)) - .collect::, _>>() - .map(Dynamic::from) - } -} - -#[allow(deprecated)] -impl CustomType for RhaiVec { - fn build(mut builder: bevy_mod_scripting_rhai::rhai::TypeBuilder) { - builder - .with_name(type_name::>()) - .with_fn("to_debug", |vec: &mut RhaiVec| format!("{:?}", vec)) - .with_fn("to_string", |vec: &mut RhaiVec| { - vec.ref_ - .get(|s| format!("{:?}", &s)) - .map_err::, _>(|e| e.into()) - }) - .with_result_fn("is_empty", |vec: &mut RhaiVec| { - vec.is_empty().map_err(Into::into) - }) - .with_result_fn("len", |vec: &mut RhaiVec| { - vec.len().map(|v| v as INT).map_err(Into::into) - }) - .with_result_fn("push", |vec: &mut RhaiVec, val: Dynamic| { - vec.push(T::from_rhai_proxy(val)?).map_err(Into::into) - }) - .with_result_fn("pop", |vec: &mut RhaiVec| vec.pop().map_err(Into::into)) - .with_result_fn("clear", |vec: &mut RhaiVec| { - vec.clear().map_err(Into::into) - }) - .with_result_fn("insert", |vec: &mut RhaiVec, idx: INT, val: Dynamic| { - vec.insert(idx as usize, T::from_rhai_proxy(val)?) - .map_err(Into::into) - }) - .with_result_fn("remove", |vec: &mut RhaiVec, idx: INT| { - vec.remove(idx as usize).map_err(Into::into) - }) - .with_result_fn("index$get$", |vec: &mut RhaiVec, idx: INT| { - vec.index(idx as usize).to_dynamic() - }) - .with_result_fn( - "index$set$", - |vec: &mut RhaiVec, idx: INT, value: Dynamic| { - vec.index(idx as usize).apply_rhai(value) - }, - ); - } -} - -/// A trait for making monomorphization of Vec implementations for any T easier. -/// -/// Rhai does not support the idea of generic types, instead every function is a standalone thing, and hence -/// generics must be monomorphized manually (registered for every type you want to use them with). -pub trait RegisterVecType { - fn register_vec_functions(&mut self) -> &mut Self; -} - -impl RegisterVecType for Engine { - fn register_vec_functions(&mut self) -> &mut Self { - self.build_type::>(); - self.register_iterator_result::, _>(); - self - } -} diff --git a/crates/bevy_script_api/src/script_ref.rs b/crates/bevy_script_api/src/script_ref.rs deleted file mode 100644 index bb9e61ba..00000000 --- a/crates/bevy_script_api/src/script_ref.rs +++ /dev/null @@ -1,185 +0,0 @@ -use bevy::prelude::*; -use parking_lot::RwLock; -use std::fmt::Debug; -use std::{borrow::Cow, sync::Weak}; - -use bevy_mod_scripting_core::world::WorldPointer; - -use crate::{ - error::ReflectionError, - sub_reflect::{ReflectBase, ReflectionPath, ReflectionPathElement}, -}; - -/// A reference to a rust type available from some script language. -/// References can be either to rust or script managed values (created either on the bevy or script side). -/// but also to any subfield of those values (All pointed to values must support `reflect`). -/// Each reference holds a reflection path from the root. -/// -/// Automatically converts to the most convenient lua representation. -/// See [`ReflectReference::to_lua`] -#[derive(Clone, Debug)] -pub struct ReflectReference { - /// The reflection path from the root - pub(crate) path: ReflectionPath, - pub(crate) world_ptr: WorldPointer, -} - -/// Safety: copying just copies the path of reflection, any closures inside, and the world pointer. -/// that itself is safe to copy. -unsafe impl Send for ReflectReference {} -/// Safety: all accesses to value are protected by locking the world pointer. -unsafe impl Sync for ReflectReference {} - -impl ReflectReference { - /// Safely creates a new base component reference - pub fn new_component_ref( - comp: ReflectComponent, - entity: Entity, - world_ptr: WorldPointer, - ) -> Self { - Self { - path: ReflectionPath::new(ReflectBase::Component { comp, entity }), - world_ptr, - } - } - - pub fn new_resource_ref(res: ReflectResource, world_ptr: WorldPointer) -> Self { - Self { - path: ReflectionPath::new(ReflectBase::Resource { res }), - world_ptr, - } - } - - /// Creates a reference to a script owned value - pub fn new_script_ref(ptr: Weak>, world_ptr: WorldPointer) -> Self { - Self { - path: ReflectionPath::new(ReflectBase::ScriptOwned { val: ptr }), - world_ptr, - } - } - - /// Creates a new script reference which points to a sub component of the original data, - /// This also updates the pointer - pub(crate) fn sub_ref(&self, elem: ReflectionPathElement) -> ReflectReference { - let path = self.path.new_sub(elem); - - Self { - path, - ..self.clone() - } - } - - /// Retrieves the underlying `dyn Reflect` reference and applies function which can retrieve a value. - /// Panics if the reference is invalid or world is already borrowed mutably. - #[inline(always)] - pub fn get(&self, f: F) -> Result - where - F: FnOnce(&dyn Reflect) -> O, - { - self.path.get(self.world_ptr.clone(), f) - } - - pub fn get_typed(&self, f: F) -> Result - where - F: FnOnce(&T) -> O, - T: Reflect, - { - self.path.get(self.world_ptr.clone(), |reflect| { - (f)(reflect.downcast_ref::().unwrap_or_else(|| { - panic!( - "Expected `{}` found `{}`", - ::std::any::type_name::(), - reflect.get_represented_type_info().unwrap().type_path() - ) - })) - }) - } - - /// Retrieves the underlying `dyn Reflect` reference and applies function which can retrieve a value. - /// If this is a component it is marked as changed. - /// Panics if the reference is invalid or if the world/value is already borrowed or if r is not a mutable pointer. - #[inline(always)] - pub fn get_mut(&mut self, f: F) -> Result - where - F: FnOnce(&mut dyn Reflect) -> O, - { - self.path.get_mut(self.world_ptr.clone(), f) - } - - pub fn get_mut_typed(&mut self, f: F) -> Result - where - F: FnOnce(&mut T) -> O, - T: Reflect, - { - self.path.get_mut(self.world_ptr.clone(), |reflect| { - (f)(reflect.downcast_mut().unwrap()) - }) - } - - /// applies another [`ReflectReference`] to self by carefuly acquiring locks and cloning if necessary. - /// - /// This is semantically equivalent to the [`Reflect::apply`] method. - /// If you know the type of this value use [`Self::apply_luaref_typed`] since it avoids double cloning and allocating - pub fn apply(&mut self, other: &ReflectReference) -> Result<(), ReflectionError> { - // sadly apply already performs a clone for value types, so this incurs - // a double clone in some cases TODO: is there another way ? - // can we avoid the box ? - let cloned = other.get(|s| s.clone_value())?; - - self.get_mut(|s| s.apply(&*cloned)) - } - - /// Unlike apply this method expects the other type to be identical. Does not allocate so is likely to be faster than apply, uses direct assignment. - /// If you have a concrete value use [`Self::set_val`](TypedReflectReference) unstead - pub fn set(&mut self, other: &Self) -> Result<(), ReflectionError> - where - T: Reflect + Clone, - { - let other: T = other.get_typed(|s: &T| s.clone())?; - self.get_mut_typed(|s| *s = other) - } - - /// Version of [`Self::set`](TypedReflectReference) which directly accepts a `T` value - pub fn set_val(&mut self, other: T) -> Result<(), ReflectionError> - where - T: Reflect, - { - self.get_mut_typed(|s| *s = other) - } -} - -/// A version of index for returning values instead of references -pub trait ValueIndex { - type Output; - - fn index(&self, index: Idx) -> Self::Output; -} - -impl ValueIndex for ReflectReference { - type Output = Self; - - fn index(&self, index: usize) -> Self::Output { - self.sub_ref(ReflectionPathElement::IndexAccess(index)) - } -} - -impl ValueIndex> for ReflectReference { - type Output = Self; - - fn index(&self, index: Cow<'static, str>) -> Self::Output { - self.sub_ref(ReflectionPathElement::FieldAccess(index)) - } -} - -/// A value representing a type which has no special UserData implementation, -/// It exposes the much less convenient reflect interface of the underlying type. -#[derive(Clone, Debug)] -pub struct ReflectedValue { - pub(crate) ref_: ReflectReference, -} - -impl From for ReflectReference { - fn from(ref_: ReflectedValue) -> Self { - ref_.ref_ - } -} diff --git a/crates/bevy_script_api/src/sub_reflect.rs b/crates/bevy_script_api/src/sub_reflect.rs deleted file mode 100644 index 9ec23952..00000000 --- a/crates/bevy_script_api/src/sub_reflect.rs +++ /dev/null @@ -1,389 +0,0 @@ -use parking_lot::RwLock; -use std::fmt; -use std::fmt::{Debug, Display}; -use std::sync::Arc; -use std::{borrow::Cow, sync::Weak}; - -use bevy::{ - prelude::{Entity, ReflectComponent, ReflectResource}, - reflect::{Reflect, ReflectMut, ReflectRef}, -}; - -use crate::error::ReflectionError; -use bevy_mod_scripting_core::world::WorldPointer; - -/// The base of a reflect path, i.e. the top-level object or source. -/// Reflections paths are always relative to some reflect base. -/// -/// If the reflection base and reflection path are both valid we can use them to traverse reflect types -#[derive(Clone)] -pub(crate) enum ReflectBase { - /// A bevy component reference - Component { - comp: ReflectComponent, - entity: Entity, - }, - /// A bevy resource reference - Resource { res: ReflectResource }, - - /// A script owned reflect type (for example a vector constructed in lua) - ScriptOwned { val: Weak> }, -} - -/// Safety: we can safely send this value across thread boundaries -/// the pointer variant is always accessed with the -unsafe impl Send for ReflectBase {} -/// Safety: todo!() -unsafe impl Sync for ReflectBase {} - -impl fmt::Debug for ReflectBase { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Component { entity, .. } => { - f.debug_struct("Component").field("entity", entity).finish() - } - Self::ScriptOwned { .. } => write!(f, "ScriptOwned"), - Self::Resource { .. } => f.debug_struct("Resource").finish(), - } - } -} - -impl fmt::Display for ReflectBase { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - ReflectBase::Component { entity, .. } => { - f.write_str("(Component on ")?; - f.write_str(&entity.index().to_string())?; - f.write_str(")") - } - ReflectBase::Resource { .. } => f.write_str("(Resource)"), - ReflectBase::ScriptOwned { .. } => f.write_str("(ScriptOwned)"), - } - } -} - -pub type Get = dyn Fn(&dyn Reflect) -> Result<&dyn Reflect, ReflectionError>; -pub type GetMut = dyn Fn(&mut dyn Reflect) -> Result<&mut dyn Reflect, ReflectionError>; - -/// Stores a part of the path of reflection + sub reflection from a root reflect reference. -/// Sub reflection allows us to access values unreachable by standard reflection. -#[derive(Clone)] -pub enum ReflectionPathElement { - SubReflection { - label: &'static str, - get: Arc, - get_mut: Arc, - }, - /// Access to a struct field - FieldAccess(Cow<'static, str>), - /// Access to a TupleStruct, Tuple, List or Array element - IndexAccess(usize), // TODO: Map access -} - -impl Debug for ReflectionPathElement { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::SubReflection { label, .. } => f - .debug_struct("SubReflection") - .field("label", label) - .finish(), - Self::FieldAccess(arg0) => f.debug_tuple("FieldAccess").field(arg0).finish(), - Self::IndexAccess(arg0) => f.debug_tuple("IndexAccess").field(arg0).finish(), - } - } -} - -impl Display for ReflectionPathElement { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - ReflectionPathElement::SubReflection { label, .. } => { - f.write_str(".")?; - f.write_str(label)?; - f.write_str("()") - } - ReflectionPathElement::FieldAccess(s) => { - f.write_str(".")?; - f.write_str(s) - } - ReflectionPathElement::IndexAccess(i) => { - f.write_str("[")?; - f.write_str(&i.to_string())?; - f.write_str("]") - } - } - } -} - -impl ReflectionPathElement { - pub(crate) fn sub_ref<'a>( - &self, - base: &'a dyn Reflect, - ) -> Result<&'a dyn Reflect, ReflectionError> { - match self { - ReflectionPathElement::SubReflection { get, .. } => get(base), - ReflectionPathElement::FieldAccess(field) => match base.reflect_ref() { - ReflectRef::Struct(s) => { - s.field(field) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such field".to_owned(), - }) - } - _ => Err(ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such field".to_owned(), - }), - }, - ReflectionPathElement::IndexAccess(index) => match base.reflect_ref() { - ReflectRef::TupleStruct(s) => { - s.field(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - ReflectRef::Tuple(s) => { - s.field(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - ReflectRef::List(s) => { - s.get(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - ReflectRef::Array(s) => { - s.get(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - _ => Err(ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }), - }, - } - } - - pub(crate) fn sub_ref_mut<'a>( - &self, - base: &'a mut dyn Reflect, - ) -> Result<&'a mut dyn Reflect, ReflectionError> { - match self { - ReflectionPathElement::SubReflection { get_mut, .. } => get_mut(base), - ReflectionPathElement::FieldAccess(field) => match base.reflect_mut() { - ReflectMut::Struct(s) => { - s.field_mut(field) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such field".to_owned(), - }) - } - _ => Err(ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such field".to_owned(), - }), - }, - ReflectionPathElement::IndexAccess(index) => match base.reflect_mut() { - ReflectMut::TupleStruct(s) => { - s.field_mut(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - ReflectMut::Tuple(s) => { - s.field_mut(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - ReflectMut::List(s) => { - s.get_mut(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - ReflectMut::Array(s) => { - s.get_mut(*index) - .ok_or_else(|| ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }) - } - _ => Err(ReflectionError::InvalidReflectionPath { - path: self.to_string(), - msg: "No such element".to_owned(), - }), - }, - } - } -} - -#[derive(Clone, Debug)] -pub(crate) struct ReflectionPath { - base: ReflectBase, - // most of these will be very short, people don't make many nested hashmaps vecs etc. - accesses: Vec, -} - -impl Display for ReflectionPath { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&self.base.to_string())?; - for access in &self.accesses { - f.write_str(&access.to_string())? - } - Ok(()) - } -} - -impl ReflectionPath { - pub fn new(base: ReflectBase) -> Self { - Self { - base, - accesses: Vec::default(), - } - } - - /// Creates a new composite sub reflect - pub fn new_sub(&self, elem: ReflectionPathElement) -> Self { - let mut accesses = self.accesses.clone(); - - accesses.push(elem); - - Self { - accesses, - ..self.clone() - } - } - - /// Walks the path with the given reference as the base - fn walk_path<'a>(&self, ref_: &'a dyn Reflect) -> Result<&'a dyn Reflect, ReflectionError> { - let first = self.accesses.first().map(|s| s.sub_ref(ref_)); - - if let Some(first) = first { - if self.accesses.len() > 1 { - self.accesses[1..] - .iter() - .try_fold(first?, |a, access| access.sub_ref(a)) - } else { - first - } - } else { - Ok(ref_) - } - } - - /// Walks the path with the given mutable reference as the base. - fn walk_path_mut<'a>( - &self, - ref_: &'a mut dyn Reflect, - ) -> Result<&'a mut dyn Reflect, ReflectionError> { - if let Some(first) = self.accesses.first() { - if self.accesses.len() > 1 { - return self.accesses[1..] - .iter() - .try_fold(first.sub_ref_mut(ref_)?, |a, access| access.sub_ref_mut(a)); - } else { - first.sub_ref_mut(ref_) - } - } else { - Ok(ref_) - } - } - - pub fn get(&self, world_ptr: WorldPointer, f: F) -> Result - where - F: FnOnce(&dyn Reflect) -> O, - { - match &self.base { - ReflectBase::Component { comp, entity } => { - let g = world_ptr.read(); - - let entity_ref = - g.get_entity(*entity) - .ok_or_else(|| ReflectionError::InvalidBaseReference { - base: self.base.to_string(), - reason: "This entity does not exist".to_owned(), - })?; - - let ref_ = self.walk_path(comp.reflect(entity_ref).ok_or_else(|| { - ReflectionError::InvalidBaseReference { - base: self.base.to_string(), - reason: "Given component does not exist on this entity".to_owned(), - } - })?)?; - Ok(f(ref_)) - } - ReflectBase::Resource { res } => { - let g = world_ptr.read(); - - let ref_ = self.walk_path(res.reflect(&g).ok_or_else(|| { - ReflectionError::InvalidBaseReference { - base: self.base.to_string(), - reason: "Given resource does not exist in this world".to_owned(), - } - })?)?; - Ok(f(ref_)) - } - ReflectBase::ScriptOwned { val } => { - let g = val - .upgrade() - .expect("Trying to access cached value from previous frame"); - - let g = g.try_read().expect("Rust safety violation: attempted to borrow value {self:?} while it was already mutably borrowed"); - Ok(f(self.walk_path(&*g)?)) - } - } - } - - pub fn get_mut(&mut self, world_ptr: WorldPointer, f: F) -> Result - where - F: FnOnce(&mut dyn Reflect) -> O, - { - match &self.base { - ReflectBase::Component { comp, entity } => { - let mut g = world_ptr.write(); - - let mut e = g.entity_mut(*entity); - let ref_ = self.walk_path_mut( - comp.reflect_mut(&mut e) - .ok_or_else(|| ReflectionError::InvalidBaseReference { - base: self.base.to_string(), - reason: "Given component does not exist on this entity".to_owned(), - })? - .into_inner(), - )?; - Ok(f(ref_)) - } - ReflectBase::Resource { res } => { - let mut g = world_ptr.write(); - - let ref_ = self.walk_path_mut( - res.reflect_mut(&mut g) - .ok_or_else(|| ReflectionError::InvalidBaseReference { - base: self.base.to_string(), - reason: "Given resource does not exist in this world".to_owned(), - })? - .into_inner(), - )?; - Ok(f(ref_)) - } - ReflectBase::ScriptOwned { val } => { - let g = val - .upgrade() - .expect("Trying to access cached value from previous frame"); - let mut g = g.try_write().expect("Rust safety violation: attempted to borrow value {self:?} while it was already mutably borrowed"); - Ok(f(self.walk_path_mut(&mut *g)?)) - } - } - } -} diff --git a/crates/bevy_script_api/src/wrappers.rs b/crates/bevy_script_api/src/wrappers.rs deleted file mode 100644 index d2110b27..00000000 --- a/crates/bevy_script_api/src/wrappers.rs +++ /dev/null @@ -1,107 +0,0 @@ -#[macro_export] -macro_rules! ref_only_wrapper_methods { - ($type_:path, $wrapper_name: ident) => { - /// Creates a script reference pointing to the wrapped value. - /// - /// Depending on this value it may be a lua owned or reflect relative reference - pub fn reflect_ref( - &self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - ) -> $crate::script_ref::ReflectReference { - match self { - Self::Owned(val) => $crate::script_ref::ReflectReference::new_script_ref( - ::std::sync::Arc::downgrade(val), - world_ptr, - ), - Self::Ref(ref_) => ref_.clone(), - } - } - - pub fn new(b: $type_) -> Self { - Self::Owned(::std::sync::Arc::new($crate::parking_lot::RwLock::new(b))) - } - - pub fn new_ref(b: $crate::script_ref::ReflectReference) -> Self { - Self::Ref(b) - } - - /// Perform an operation on the base type and optionally retrieve something by value - /// may require a read lock on the world in case this is a reference - pub fn val(&self, accessor: F) -> Result - where - F: FnOnce(&$type_) -> G, - { - match self { - Self::Owned(v) => Ok(accessor(&v.read())), - Self::Ref(v) => v.get(|s| accessor(s.downcast_ref::<$type_>().unwrap())), - } - } - - pub fn val_mut(&mut self, accessor: F) -> Result - where - F: FnOnce(&mut $type_) -> G, - { - match self { - Self::Owned(v) => Ok(accessor(&mut *v.write())), - Self::Ref(v) => v.get_mut(|s| accessor(s.downcast_mut::<$type_>().unwrap())), - } - } - - /// Applies Self to another ReflectReference. - /// may require a write lock on the world - pub fn apply_self_to_base( - &self, - other: &mut $crate::script_ref::ReflectReference, - ) -> Result<(), $crate::error::ReflectionError> { - match self { - Self::Owned(v) => { - other.get_mut(|other| other.apply(&mut *v.write()))?; - Ok(()) - } - Self::Ref(v) => { - // if we are a ReflectReference, we have to be careful with borrows - // to avoid deadlock - // we take advantage of the fact we know the expected type - other.apply(v) - } - } - } - }; -} - -#[macro_export] -macro_rules! define_wrapper { - ($type_:path, $wrapper_name:ident) => { - #[allow(clippy::large_enum_variant)] - #[doc=concat!("A script wrapper for the type `",stringify!($type_),"`")] - #[derive(Clone)] - pub enum $wrapper_name { - Owned(::std::sync::Arc<$crate::parking_lot::RwLock<$type_>>), - Ref($crate::script_ref::ReflectReference), - } - }; -} - -#[macro_export] -macro_rules! make_script_wrapper { - ($type_:path as $wrapper_name:ident with Clone) => { - $crate::define_wrapper!($type_, $wrapper_name); - impl $wrapper_name { - $crate::ref_only_wrapper_methods!($type_, $wrapper_name); - - /// retrieves the underlying value by cloning it - pub fn inner(&self) -> Result<$type_, $crate::error::ReflectionError> - where - $type_: Clone, - { - self.val(|s| s.clone()) - } - } - }; - ($type_:path as $wrapper_name:ident) => { - $crate::define_wrapper!($type_, $wrapper_name); - impl $wrapper_name { - $crate::ref_only_wrapper_methods!($type_, $wrapper_name); - } - }; -} diff --git a/crates/languages/bevy_mod_scripting_lua/Cargo.toml b/crates/languages/bevy_mod_scripting_lua/Cargo.toml index 11768079..ded1c20e 100644 --- a/crates/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/crates/languages/bevy_mod_scripting_lua/Cargo.toml @@ -41,11 +41,14 @@ path = "src/lib.rs" [dependencies] bevy = { workspace = true, default-features = false } bevy_mod_scripting_core = { workspace = true } +bevy_mod_scripting_derive = { path = "../../bevy_mod_scripting_derive", version = "0.6.0" } tealr = { version = "0.9", features = [ "mlua_vendored", "mlua_send", "mlua_macros", ] } + parking_lot = "0.12.1" serde_json = "1.0.81" anyhow = "1.0.75" +smol_str = "0.2" diff --git a/crates/languages/bevy_mod_scripting_lua/src/assets.rs b/crates/languages/bevy_mod_scripting_lua/src/assets.rs index 8c94f4e5..eeae93a0 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/assets.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/assets.rs @@ -1,156 +1,156 @@ -use bevy::{ - asset::{io::Reader, Asset, AssetLoader, AsyncReadExt}, - reflect::TypePath, - utils::BoxedFuture, -}; -use bevy_mod_scripting_core::asset::CodeAsset; +// use bevy::{ +// asset::{io::Reader, Asset, AssetLoader, AsyncReadExt}, +// reflect::TypePath, +// utils::BoxedFuture, +// }; +// use bevy_mod_scripting_core::asset::CodeAsset; -use anyhow::Error; +// use anyhow::Error; -#[derive(Asset, TypePath, Debug)] -/// A lua code file in bytes -pub struct LuaFile { - pub bytes: Vec, -} +// #[derive(Asset, TypePath, Debug)] +// /// A lua code file in bytes +// pub struct LuaFile { +// pub bytes: Vec, +// } -impl CodeAsset for LuaFile { - fn bytes(&self) -> &[u8] { - self.bytes.as_slice() - } -} +// impl CodeAsset for LuaFile { +// fn bytes(&self) -> &[u8] { +// self.bytes.as_slice() +// } +// } -#[derive(Default)] -/// Asset loader for lua scripts -pub struct LuaLoader; +// #[derive(Default)] +// /// Asset loader for lua scripts +// pub struct LuaLoader; -fn old_lua_load<'a>( - bytes: &'a [u8], - load_context: &'a mut bevy::asset::LoadContext, -) -> BoxedFuture<'a, Result, Error>> { - match load_context.path().extension().map(|s| s.to_str().unwrap()) { - #[cfg(all(feature = "teal", debug_assertions))] - Some("tl") => { - use bevy::asset::io::file::FileAssetReader; - use std::fs; - use std::path::PathBuf; - use std::process::Command; +// fn old_lua_load<'a>( +// bytes: &'a [u8], +// load_context: &'a mut bevy::asset::LoadContext, +// ) -> BoxedFuture<'a, Result, Error>> { +// match load_context.path().extension().map(|s| s.to_str().unwrap()) { +// #[cfg(all(feature = "teal", debug_assertions))] +// Some("tl") => { +// use bevy::asset::io::file::FileAssetReader; +// use std::fs; +// use std::path::PathBuf; +// use std::process::Command; - let scripts_dir = &FileAssetReader::get_base_path() - .join("assets") - .join("scripts"); +// let scripts_dir = &FileAssetReader::get_base_path() +// .join("assets") +// .join("scripts"); - let temp_file_path = &std::env::temp_dir().join("bevy_mod_scripting.temp.lua"); - bevy::prelude::info!("tl file path {}", scripts_dir.to_str().unwrap()); - // optionally put the output in the /build folder - let build_dir_path: Option = - if load_context.path().starts_with("scripts/build/") { - Some( - load_context - .path() - .strip_prefix("scripts/") - .unwrap() - .to_owned(), - ) - } else if load_context.path().starts_with("scripts/") { - Some( - PathBuf::from("build/") - .join(load_context.path().strip_prefix("scripts/").unwrap()), - ) - } else { - None - }; +// let temp_file_path = &std::env::temp_dir().join("bevy_mod_scripting.temp.lua"); +// bevy::prelude::info!("tl file path {}", scripts_dir.to_str().unwrap()); +// // optionally put the output in the /build folder +// let build_dir_path: Option = +// if load_context.path().starts_with("scripts/build/") { +// Some( +// load_context +// .path() +// .strip_prefix("scripts/") +// .unwrap() +// .to_owned(), +// ) +// } else if load_context.path().starts_with("scripts/") { +// Some( +// PathBuf::from("build/") +// .join(load_context.path().strip_prefix("scripts/").unwrap()), +// ) +// } else { +// None +// }; - let full_path = &FileAssetReader::get_base_path() - .join("assets") - .join(load_context.path()); - bevy::log::info!( - "tl check {} : {}", - full_path.to_str().unwrap(), - scripts_dir.to_str().unwrap() - ); - if let Ok(e) = Command::new("tl") - .args(["check", full_path.to_str().unwrap()]) - .current_dir(scripts_dir) - .status() - { - if !e.success() { - return Box::pin(async move { - Err(Error::msg(format!( - "Teal file `{}` has errors", - load_context.path().to_str().unwrap() - ))) - }); - } - } else { - fs::remove_file(temp_file_path).expect("Something went wrong running `tl check`"); - panic!("Something went wrong running `tl check`"); - } +// let full_path = &FileAssetReader::get_base_path() +// .join("assets") +// .join(load_context.path()); +// bevy::log::info!( +// "tl check {} : {}", +// full_path.to_str().unwrap(), +// scripts_dir.to_str().unwrap() +// ); +// if let Ok(e) = Command::new("tl") +// .args(["check", full_path.to_str().unwrap()]) +// .current_dir(scripts_dir) +// .status() +// { +// if !e.success() { +// return Box::pin(async move { +// Err(Error::msg(format!( +// "Teal file `{}` has errors", +// load_context.path().to_str().unwrap() +// ))) +// }); +// } +// } else { +// fs::remove_file(temp_file_path).expect("Something went wrong running `tl check`"); +// panic!("Something went wrong running `tl check`"); +// } - if let Ok(e) = Command::new("tl") - .args([ - "gen", - full_path.to_str().unwrap(), - "-o", - temp_file_path.to_str().unwrap(), - ]) - .current_dir(scripts_dir) - .status() - { - if !e.success() { - return Box::pin(async move { - Err(Error::msg(format!( - "Teal file `{}` could not be compiled!", - load_context.path().to_str().unwrap() - ))) - }); - } - } else { - fs::remove_file(temp_file_path).expect("Something went wrong running `tl gen`"); - panic!("Something went wrong running `tl gen`") - } +// if let Ok(e) = Command::new("tl") +// .args([ +// "gen", +// full_path.to_str().unwrap(), +// "-o", +// temp_file_path.to_str().unwrap(), +// ]) +// .current_dir(scripts_dir) +// .status() +// { +// if !e.success() { +// return Box::pin(async move { +// Err(Error::msg(format!( +// "Teal file `{}` could not be compiled!", +// load_context.path().to_str().unwrap() +// ))) +// }); +// } +// } else { +// fs::remove_file(temp_file_path).expect("Something went wrong running `tl gen`"); +// panic!("Something went wrong running `tl gen`") +// } - if let Some(mut build_dir_path) = build_dir_path { - build_dir_path = scripts_dir.join(build_dir_path); - let _ = fs::create_dir_all(build_dir_path.parent().unwrap()); - let _ = fs::copy(temp_file_path, build_dir_path.with_extension("lua")); - } +// if let Some(mut build_dir_path) = build_dir_path { +// build_dir_path = scripts_dir.join(build_dir_path); +// let _ = fs::create_dir_all(build_dir_path.parent().unwrap()); +// let _ = fs::copy(temp_file_path, build_dir_path.with_extension("lua")); +// } - let lua_code = - fs::read_to_string(temp_file_path).expect("Could not find output lua file"); - fs::remove_file(temp_file_path).unwrap(); +// let lua_code = +// fs::read_to_string(temp_file_path).expect("Could not find output lua file"); +// fs::remove_file(temp_file_path).unwrap(); - Box::pin(async move { Ok(lua_code.as_bytes().into()) }) - } +// Box::pin(async move { Ok(lua_code.as_bytes().into()) }) +// } - _ => Box::pin(async move { Ok(bytes.into()) }), - } -} -impl AssetLoader for LuaLoader { - type Asset = LuaFile; - type Settings = (); - type Error = Error; +// _ => Box::pin(async move { Ok(bytes.into()) }), +// } +// } +// impl AssetLoader for LuaLoader { +// type Asset = LuaFile; +// type Settings = (); +// type Error = Error; - fn load<'a>( - &'a self, - reader: &'a mut Reader, //bytes: &'a [u8], - _settings: &'a (), - load_context: &'a mut bevy::asset::LoadContext, - ) -> bevy::asset::BoxedFuture<'a, Result> { - bevy::prelude::info!("lua loader invoked: {:#}", load_context.asset_path()); - Box::pin(async move { - let mut bytes = Vec::new(); - reader.read_to_end(&mut bytes).await?; - let bytes = old_lua_load(bytes.as_slice(), load_context).await?; - Ok(LuaFile { bytes }) //}) - }) - } +// fn load<'a>( +// &'a self, +// reader: &'a mut Reader, //bytes: &'a [u8], +// _settings: &'a (), +// load_context: &'a mut bevy::asset::LoadContext, +// ) -> bevy::asset::BoxedFuture<'a, Result> { +// bevy::prelude::info!("lua loader invoked: {:#}", load_context.asset_path()); +// Box::pin(async move { +// let mut bytes = Vec::new(); +// reader.read_to_end(&mut bytes).await?; +// let bytes = old_lua_load(bytes.as_slice(), load_context).await?; +// Ok(LuaFile { bytes }) //}) +// }) +// } - #[cfg(feature = "teal")] - fn extensions(&self) -> &[&str] { - &["lua", "tl"] - } - #[cfg(not(feature = "teal"))] - fn extensions(&self) -> &[&str] { - &["lua"] - } -} +// #[cfg(feature = "teal")] +// fn extensions(&self) -> &[&str] { +// &["lua", "tl"] +// } +// #[cfg(not(feature = "teal"))] +// fn extensions(&self) -> &[&str] { +// &["lua"] +// } +// } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs new file mode 100644 index 00000000..5a278b63 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs @@ -0,0 +1,8 @@ +use bevy_mod_scripting_core::bindings::WorldCallbackAccess; + +pub mod providers; +pub mod proxy; +pub mod reference; +pub mod std; +pub mod type_registration; +pub mod world; diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs new file mode 100644 index 00000000..f27b993e --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs @@ -0,0 +1,83 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::core::prelude::Name", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct Name {} +#[derive(Default)] +pub(crate) struct Globals; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { + Ok(()) + } +} +fn bevy_core_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyCoreScriptingPlugin; +impl bevy::app::Plugin for BevyCoreScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_core_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( + "BevyCoreAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + }, + ), + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs new file mode 100644 index 00000000..deeb5d0e --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs @@ -0,0 +1,385 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_reflect::*; +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::ecs::entity::Entity", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + 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()] + fn from_raw(index: u32) -> LuaReflectValProxy; + +"#, + 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()] + fn to_bits(_self: LuaReflectValProxy) -> 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()] + fn from_bits(bits: u64) -> LuaReflectValProxy; + +"#, + 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()] + fn index(_self: LuaReflectValProxy) -> 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()] + fn generation(_self: LuaReflectValProxy) -> u32; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Entity {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::ecs::component::ComponentId", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + 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()] + fn new(index: usize) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the index of the current component. + + #[lua()] + fn index(_self: LuaReflectValProxy) -> usize; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ComponentId(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::ecs::component::Tick", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new [`Tick`] wrapping the given value. + + #[lua()] + fn new(tick: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Gets the value of this change tick. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Sets the value of this change tick. + + #[lua()] + fn set(_self: LuaReflectRefMutProxy, 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()] + fn is_newer_than( + _self: LuaReflectValProxy, + last_run: LuaReflectValProxy, + this_run: LuaReflectValProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Tick {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::ecs::component::ComponentTicks", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if the component or resource was added after the system last ran. + + #[lua()] + fn is_added( + _self: LuaReflectRefProxy, + last_run: LuaReflectValProxy, + this_run: LuaReflectValProxy, + ) -> bool; + +"#, + r#" +/// Returns `true` if the component or resource was added or mutably dereferenced after the system last ran. + + #[lua()] + fn is_changed( + _self: LuaReflectRefProxy, + last_run: LuaReflectValProxy, + this_run: LuaReflectValProxy, + ) -> bool; + +"#, + r#" +/// Returns the tick recording the time this component or resource was most recently changed. + + #[lua()] + fn last_changed_tick( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the tick recording the time this component or resource was added. + + #[lua()] + fn added_tick( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Manually sets the change tick. +/// This is normally done automatically via the [`DerefMut`](std::ops::DerefMut) implementation +/// on [`Mut`](crate::change_detection::Mut), [`ResMut`](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()] + fn set_changed( + _self: LuaReflectRefMutProxy, + change_tick: LuaReflectValProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ComponentTicks {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::ecs::entity::EntityHash", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#] +)] +pub struct EntityHash {} +#[derive(Default)] +pub(crate) struct Globals; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { + instances + .add_instance("Entity", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "ComponentId", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Tick", crate::tealr::mlu::UserDataProxy::::new)?; + Ok(()) + } +} +fn bevy_ecs_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyEcsScriptingPlugin; +impl bevy::app::Plugin for BevyEcsScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_ecs_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( + "BevyEcsAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + }, + ), + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs new file mode 100644 index 00000000..2b75e619 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs @@ -0,0 +1,110 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use super::bevy_core::*; +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::hierarchy::prelude::Children", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Swaps the child at `a_index` with the child at `b_index`. + + #[lua()] + fn swap( + _self: LuaReflectRefMutProxy, + a_index: usize, + b_index: usize, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Children(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::hierarchy::prelude::Parent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Parent(); +#[derive(Default)] +pub(crate) struct Globals; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { + Ok(()) + } +} +fn bevy_hierarchy_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyHierarchyScriptingPlugin; +impl bevy::app::Plugin for BevyHierarchyScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_hierarchy_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( + "BevyHierarchyAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + }, + ), + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs new file mode 100644 index 00000000..d4a9f2b4 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs @@ -0,0 +1,1674 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::Gamepad", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a new [`Gamepad`]. + + #[lua()] + fn new(id: usize) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Gamepad { + id: usize, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadAxis", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Creates a new [`GamepadAxis`]. +/// # Examples +/// ``` +/// # use bevy_input::gamepad::{GamepadAxis, GamepadAxisType, Gamepad}; +/// # +/// let gamepad_axis = GamepadAxis::new( +/// Gamepad::new(1), +/// GamepadAxisType::LeftStickX, +/// ); +/// ``` + + #[lua()] + fn new( + gamepad: LuaReflectValProxy, + axis_type: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadAxis { + gamepad: bevy::input::gamepad::Gamepad, + axis_type: bevy::input::gamepad::GamepadAxisType, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadAxisType", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadAxisType {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadButton", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a new [`GamepadButton`]. +/// # Examples +/// ``` +/// # use bevy_input::gamepad::{GamepadButton, GamepadButtonType, Gamepad}; +/// # +/// let gamepad_button = GamepadButton::new( +/// Gamepad::new(1), +/// GamepadButtonType::South, +/// ); +/// ``` + + #[lua()] + fn new( + gamepad: LuaReflectValProxy, + button_type: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadButton { + gamepad: bevy::input::gamepad::Gamepad, + button_type: bevy::input::gamepad::GamepadButtonType, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadButtonType", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadButtonType {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::keyboard::KeyCode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct KeyCode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::mouse::MouseButton", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct MouseButton {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::touch::TouchInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct TouchInput { + phase: bevy::input::touch::TouchPhase, + position: ReflectReference, + window: ReflectReference, + force: ReflectReference, + id: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::keyboard::Key", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Key {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::keyboard::KeyboardInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct KeyboardInput { + key_code: bevy::input::keyboard::KeyCode, + logical_key: bevy::input::keyboard::Key, + state: bevy::input::ButtonState, + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::keyboard::NativeKey", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct NativeKey {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::keyboard::NativeKeyCode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct NativeKeyCode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::mouse::MouseButtonInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct MouseButtonInput { + button: bevy::input::mouse::MouseButton, + state: bevy::input::ButtonState, + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::mouse::MouseMotion", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct MouseMotion { + delta: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::mouse::MouseScrollUnit", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct MouseScrollUnit {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::mouse::MouseWheel", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct MouseWheel { + unit: bevy::input::mouse::MouseScrollUnit, + x: f32, + y: f32, + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::touch::ForceTouch", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ForceTouch {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::touch::TouchPhase", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct TouchPhase {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::touchpad::TouchpadMagnify", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct TouchpadMagnify(f32); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::touchpad::TouchpadRotate", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct TouchpadRotate(f32); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::AxisSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Get the value above which inputs will be rounded up to 1.0. + + #[lua()] + fn livezone_upperbound( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Try to set the value above which inputs will be rounded up to 1.0. +/// If the value passed is negative or less than `deadzone_upperbound`, +/// the value will not be changed. +/// Returns the new value of `livezone_upperbound`. + + #[lua()] + fn set_livezone_upperbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; + +"#, + r#" +/// Get the value below which positive inputs will be rounded down to 0.0. + + #[lua()] + fn deadzone_upperbound( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Try to set the value below which positive inputs will be rounded down to 0.0. +/// If the value passed is negative or greater than `livezone_upperbound`, +/// the value will not be changed. +/// Returns the new value of `deadzone_upperbound`. + + #[lua()] + fn set_deadzone_upperbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; + +"#, + r#" +/// Get the value below which negative inputs will be rounded down to -1.0. + + #[lua()] + fn livezone_lowerbound( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Try to set the value below which negative inputs will be rounded down to -1.0. +/// If the value passed is positive or greater than `deadzone_lowerbound`, +/// the value will not be changed. +/// Returns the new value of `livezone_lowerbound`. + + #[lua()] + fn set_livezone_lowerbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; + +"#, + r#" +/// Get the value above which inputs will be rounded up to 0.0. + + #[lua()] + fn deadzone_lowerbound( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Try to set the value above which inputs will be rounded up to 0.0. +/// If the value passed is less than -1.0 or less than `livezone_lowerbound`, +/// the value will not be changed. +/// Returns the new value of `deadzone_lowerbound`. + + #[lua()] + fn set_deadzone_lowerbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; + +"#, + r#" +/// Get the minimum value by which input must change before the change is registered. + + #[lua()] + fn threshold(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Try to set the minimum value by which input must change before the changes will be applied. +/// If the value passed is not within [0.0..=2.0], the value will not be changed. +/// Returns the new value of threshold. + + #[lua()] + fn set_threshold( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; + +"#, + r#" +/// Clamps the `raw_value` according to the `AxisSettings`. + + #[lua()] + fn clamp( + _self: LuaReflectRefProxy, + new_value: f32, + ) -> f32; + +"#, + r#" +/// Filters the `new_value` based on the `old_value`, according to the [`AxisSettings`]. +/// Returns the clamped `new_value` if the change exceeds the settings threshold, +/// and `None` otherwise. + + #[lua()] + fn filter( + _self: LuaReflectRefProxy, + new_value: f32, + old_value: std::option::Option, + ) -> std::option::Option; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct AxisSettings {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::ButtonAxisSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Filters the `new_value` based on the `old_value`, according to the [`ButtonAxisSettings`]. +/// Returns the clamped `new_value`, according to the [`ButtonAxisSettings`], if the change +/// exceeds the settings threshold, and `None` otherwise. + + #[lua()] + fn filter( + _self: LuaReflectRefProxy, + new_value: f32, + old_value: std::option::Option, + ) -> std::option::Option; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ButtonAxisSettings { + high: f32, + low: f32, + threshold: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::ButtonSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if the button is pressed. +/// A button is considered pressed if the `value` passed is greater than or equal to the press threshold. + + #[lua()] + fn is_pressed( + _self: LuaReflectRefProxy, + value: f32, + ) -> bool; + +"#, + r#" +/// Returns `true` if the button is released. +/// A button is considered released if the `value` passed is lower than or equal to the release threshold. + + #[lua()] + fn is_released( + _self: LuaReflectRefProxy, + value: f32, + ) -> bool; + +"#, + r#" +/// Get the button input threshold above which the button is considered pressed. + + #[lua()] + fn press_threshold( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Try to set the button input threshold above which the button is considered pressed. +/// If the value passed is outside the range [release threshold..=1.0], the value will not be changed. +/// Returns the new value of the press threshold. + + #[lua()] + fn set_press_threshold( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; + +"#, + r#" +/// Get the button input threshold below which the button is considered released. + + #[lua()] + fn release_threshold( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Try to set the button input threshold below which the button is considered released. If the +/// value passed is outside the range [0.0..=press threshold], the value will not be changed. +/// Returns the new value of the release threshold. + + #[lua()] + fn set_release_threshold( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ButtonSettings {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadAxisChangedEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a [`GamepadAxisChangedEvent`]. + + #[lua()] + fn new( + gamepad: LuaReflectValProxy, + axis_type: LuaReflectValProxy, + value: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadAxisChangedEvent { + gamepad: bevy::input::gamepad::Gamepad, + axis_type: bevy::input::gamepad::GamepadAxisType, + value: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadButtonChangedEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a [`GamepadButtonChangedEvent`]. + + #[lua()] + fn new( + gamepad: LuaReflectValProxy, + button_type: LuaReflectValProxy, + value: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadButtonChangedEvent { + gamepad: bevy::input::gamepad::Gamepad, + button_type: bevy::input::gamepad::GamepadButtonType, + value: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadButtonInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadButtonInput { + button: bevy::input::gamepad::GamepadButton, + state: bevy::input::ButtonState, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadConnection", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadConnection {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadConnectionEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a [`GamepadConnectionEvent`]. + + #[lua()] + fn new( + gamepad: LuaReflectValProxy, + connection: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Is the gamepad connected? + + #[lua()] + fn connected( + _self: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Is the gamepad disconnected? + + #[lua()] + fn disconnected( + _self: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadConnectionEvent { + gamepad: bevy::input::gamepad::Gamepad, + connection: bevy::input::gamepad::GamepadConnection, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadEvent {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadSettings { + default_button_settings: bevy::input::gamepad::ButtonSettings, + default_axis_settings: bevy::input::gamepad::AxisSettings, + default_button_axis_settings: bevy::input::gamepad::ButtonAxisSettings, + button_settings: ReflectReference, + axis_settings: ReflectReference, + button_axis_settings: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::ButtonState", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Is this button pressed? + + #[lua()] + fn is_pressed(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ButtonState {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::input::gamepad::GamepadInfo", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GamepadInfo { + name: std::string::String, +} +#[derive(Default)] +pub(crate) struct Globals; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "Gamepad", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "GamepadAxis", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "GamepadButton", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "GamepadAxisChangedEvent", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "GamepadButtonChangedEvent", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "GamepadConnectionEvent", + crate::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +fn bevy_input_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyInputScriptingPlugin; +impl bevy::app::Plugin for BevyInputScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_input_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( + "BevyInputAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy< + LuaGamepadButtonChangedEvent, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + }, + ), + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs new file mode 100644 index 00000000..66a8a679 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs @@ -0,0 +1,25682 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::utils::Duration", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new `Duration` from the specified number of whole seconds and +/// additional nanoseconds. +/// If the number of nanoseconds is greater than 1 billion (the number of +/// nanoseconds in a second), then it will carry over into the seconds provided. +/// # Panics +/// This constructor will panic if the carry from the nanoseconds overflows +/// the seconds counter. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let five_seconds = Duration::new(5, 0); +/// ``` + + #[lua()] + fn new(secs: u64, nanos: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new `Duration` from the specified number of whole seconds. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_secs(5); +/// assert_eq!(5, duration.as_secs()); +/// assert_eq!(0, duration.subsec_nanos()); +/// ``` + + #[lua()] + fn from_secs(secs: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new `Duration` from the specified number of milliseconds. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_millis(2569); +/// assert_eq!(2, duration.as_secs()); +/// assert_eq!(569_000_000, duration.subsec_nanos()); +/// ``` + + #[lua()] + fn from_millis(millis: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new `Duration` from the specified number of microseconds. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_micros(1_000_002); +/// assert_eq!(1, duration.as_secs()); +/// assert_eq!(2000, duration.subsec_nanos()); +/// ``` + + #[lua()] + fn from_micros(micros: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new `Duration` from the specified number of nanoseconds. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_nanos(1_000_000_123); +/// assert_eq!(1, duration.as_secs()); +/// assert_eq!(123, duration.subsec_nanos()); +/// ``` + + #[lua()] + fn from_nanos(nanos: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if this `Duration` spans no time. +/// # Examples +/// ``` +/// use std::time::Duration; +/// assert!(Duration::ZERO.is_zero()); +/// assert!(Duration::new(0, 0).is_zero()); +/// assert!(Duration::from_nanos(0).is_zero()); +/// assert!(Duration::from_secs(0).is_zero()); +/// assert!(!Duration::new(1, 1).is_zero()); +/// assert!(!Duration::from_nanos(1).is_zero()); +/// assert!(!Duration::from_secs(1).is_zero()); +/// ``` + + #[lua()] + fn is_zero(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the number of _whole_ seconds contained by this `Duration`. +/// The returned value does not include the fractional (nanosecond) part of the +/// duration, which can be obtained using [`subsec_nanos`]. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730023852); +/// assert_eq!(duration.as_secs(), 5); +/// ``` +/// To determine the total number of seconds represented by the `Duration` +/// including the fractional part, use [`as_secs_f64`] or [`as_secs_f32`] +/// [`as_secs_f64`]: Duration::as_secs_f64 +/// [`as_secs_f32`]: Duration::as_secs_f32 +/// [`subsec_nanos`]: Duration::subsec_nanos + + #[lua()] + fn as_secs(_self: LuaReflectRefProxy) -> u64; + +"#, + r#" +/// Returns the fractional part of this `Duration`, in whole milliseconds. +/// This method does **not** return the length of the duration when +/// represented by milliseconds. The returned number always represents a +/// fractional portion of a second (i.e., it is less than one thousand). +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_millis(5432); +/// assert_eq!(duration.as_secs(), 5); +/// assert_eq!(duration.subsec_millis(), 432); +/// ``` + + #[lua()] + fn subsec_millis(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// Returns the fractional part of this `Duration`, in whole microseconds. +/// This method does **not** return the length of the duration when +/// represented by microseconds. The returned number always represents a +/// fractional portion of a second (i.e., it is less than one million). +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_micros(1_234_567); +/// assert_eq!(duration.as_secs(), 1); +/// assert_eq!(duration.subsec_micros(), 234_567); +/// ``` + + #[lua()] + fn subsec_micros(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// Returns the fractional part of this `Duration`, in nanoseconds. +/// This method does **not** return the length of the duration when +/// represented by nanoseconds. The returned number always represents a +/// fractional portion of a second (i.e., it is less than one billion). +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_millis(5010); +/// assert_eq!(duration.as_secs(), 5); +/// assert_eq!(duration.subsec_nanos(), 10_000_000); +/// ``` + + #[lua()] + fn subsec_nanos(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// Returns the total number of whole milliseconds contained by this `Duration`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730023852); +/// assert_eq!(duration.as_millis(), 5730); +/// ``` + + #[lua()] + fn as_millis(_self: LuaReflectRefProxy) -> u128; + +"#, + r#" +/// Returns the total number of whole microseconds contained by this `Duration`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730023852); +/// assert_eq!(duration.as_micros(), 5730023); +/// ``` + + #[lua()] + fn as_micros(_self: LuaReflectRefProxy) -> u128; + +"#, + r#" +/// Returns the total number of nanoseconds contained by this `Duration`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730023852); +/// assert_eq!(duration.as_nanos(), 5730023852); +/// ``` + + #[lua()] + fn as_nanos(_self: LuaReflectRefProxy) -> u128; + +"#, + r#" +/// Saturating `Duration` addition. Computes `self + other`, returning [`Duration::MAX`] +/// if overflow occurred. +/// # Examples +/// ``` +/// #![feature(duration_constants)] +/// use std::time::Duration; +/// assert_eq!(Duration::new(0, 0).saturating_add(Duration::new(0, 1)), Duration::new(0, 1)); +/// assert_eq!(Duration::new(1, 0).saturating_add(Duration::new(u64::MAX, 0)), Duration::MAX); +/// ``` + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating `Duration` subtraction. Computes `self - other`, returning [`Duration::ZERO`] +/// if the result would be negative or if overflow occurred. +/// # Examples +/// ``` +/// use std::time::Duration; +/// assert_eq!(Duration::new(0, 1).saturating_sub(Duration::new(0, 0)), Duration::new(0, 1)); +/// assert_eq!(Duration::new(0, 0).saturating_sub(Duration::new(0, 1)), Duration::ZERO); +/// ``` + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating `Duration` multiplication. Computes `self * other`, returning +/// [`Duration::MAX`] if overflow occurred. +/// # Examples +/// ``` +/// #![feature(duration_constants)] +/// use std::time::Duration; +/// assert_eq!(Duration::new(0, 500_000_001).saturating_mul(2), Duration::new(1, 2)); +/// assert_eq!(Duration::new(u64::MAX - 1, 0).saturating_mul(2), Duration::MAX); +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the number of seconds contained by this `Duration` as `f64`. +/// The returned value does include the fractional (nanosecond) part of the duration. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.as_secs_f64(), 2.7); +/// ``` + + #[lua()] + fn as_secs_f64(_self: LuaReflectRefProxy) -> f64; + +"#, + r#" +/// Returns the number of seconds contained by this `Duration` as `f32`. +/// The returned value does include the fractional (nanosecond) part of the duration. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.as_secs_f32(), 2.7); +/// ``` + + #[lua()] + fn as_secs_f32(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Creates a new `Duration` from the specified number of seconds represented +/// as `f64`. +/// # Panics +/// This constructor will panic if `secs` is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let res = Duration::from_secs_f64(0.0); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f64(1e-20); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f64(4.2e-7); +/// assert_eq!(res, Duration::new(0, 420)); +/// let res = Duration::from_secs_f64(2.7); +/// assert_eq!(res, Duration::new(2, 700_000_000)); +/// let res = Duration::from_secs_f64(3e10); +/// assert_eq!(res, Duration::new(30_000_000_000, 0)); +/// // subnormal float +/// let res = Duration::from_secs_f64(f64::from_bits(1)); +/// assert_eq!(res, Duration::new(0, 0)); +/// // conversion uses rounding +/// let res = Duration::from_secs_f64(0.999e-9); +/// assert_eq!(res, Duration::new(0, 1)); +/// ``` + + #[lua()] + fn from_secs_f64(secs: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new `Duration` from the specified number of seconds represented +/// as `f32`. +/// # Panics +/// This constructor will panic if `secs` is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let res = Duration::from_secs_f32(0.0); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f32(1e-20); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f32(4.2e-7); +/// assert_eq!(res, Duration::new(0, 420)); +/// let res = Duration::from_secs_f32(2.7); +/// assert_eq!(res, Duration::new(2, 700_000_048)); +/// let res = Duration::from_secs_f32(3e10); +/// assert_eq!(res, Duration::new(30_000_001_024, 0)); +/// // subnormal float +/// let res = Duration::from_secs_f32(f32::from_bits(1)); +/// assert_eq!(res, Duration::new(0, 0)); +/// // conversion uses rounding +/// let res = Duration::from_secs_f32(0.999e-9); +/// assert_eq!(res, Duration::new(0, 1)); +/// ``` + + #[lua()] + fn from_secs_f32(secs: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies `Duration` by `f64`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.mul_f64(3.14), Duration::new(8, 478_000_000)); +/// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0)); +/// ``` + + #[lua()] + fn mul_f64( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies `Duration` by `f32`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.mul_f32(3.14), Duration::new(8, 478_000_641)); +/// assert_eq!(dur.mul_f32(3.14e5), Duration::new(847800, 0)); +/// ``` + + #[lua()] + fn mul_f32( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Divide `Duration` by `f64`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.div_f64(3.14), Duration::new(0, 859_872_611)); +/// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_599)); +/// ``` + + #[lua()] + fn div_f64( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Divide `Duration` by `f32`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// // note that due to rounding errors result is slightly +/// // different from 0.859_872_611 +/// assert_eq!(dur.div_f32(3.14), Duration::new(0, 859_872_580)); +/// assert_eq!(dur.div_f32(3.14e5), Duration::new(0, 8_599)); +/// ``` + + #[lua()] + fn div_f32( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Duration {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::utils::Instant", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// # Panics +/// This function may panic if the resulting point in time cannot be represented by the +/// underlying data structure. See [`Instant::checked_add`] for a version without panic. + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns an instant corresponding to "now". +/// # Examples +/// ``` +/// use std::time::Instant; +/// let now = Instant::now(); +/// ``` + + #[lua()] + fn now() -> LuaReflectValProxy; + +"#, + r#" +/// Returns the amount of time elapsed from another instant to this one, +/// or zero duration if that instant is later than this one. +/// # Panics +/// Previous rust versions panicked when `earlier` was later than `self`. Currently this +/// method saturates. Future versions may reintroduce the panic in some circumstances. +/// See [Monotonicity]. +/// [Monotonicity]: Instant#monotonicity +/// # Examples +/// ```no_run +/// use std::time::{Duration, Instant}; +/// use std::thread::sleep; +/// let now = Instant::now(); +/// sleep(Duration::new(1, 0)); +/// let new_now = Instant::now(); +/// println!("{:?}", new_now.duration_since(now)); +/// println!("{:?}", now.duration_since(new_now)); // 0ns +/// ``` + + #[lua()] + fn duration_since( + _self: LuaReflectRefProxy, + earlier: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the amount of time elapsed from another instant to this one, +/// or zero duration if that instant is later than this one. +/// # Examples +/// ```no_run +/// use std::time::{Duration, Instant}; +/// use std::thread::sleep; +/// let now = Instant::now(); +/// sleep(Duration::new(1, 0)); +/// let new_now = Instant::now(); +/// println!("{:?}", new_now.saturating_duration_since(now)); +/// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns +/// ``` + + #[lua()] + fn saturating_duration_since( + _self: LuaReflectRefProxy, + earlier: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the amount of time elapsed since this instant. +/// # Panics +/// Previous rust versions panicked when the current time was earlier than self. Currently this +/// method returns a Duration of zero in that case. Future versions may reintroduce the panic. +/// See [Monotonicity]. +/// [Monotonicity]: Instant#monotonicity +/// # Examples +/// ```no_run +/// use std::thread::sleep; +/// use std::time::{Duration, Instant}; +/// let instant = Instant::now(); +/// let three_secs = Duration::from_secs(3); +/// sleep(three_secs); +/// assert!(instant.elapsed() >= three_secs); +/// ``` + + #[lua()] + fn elapsed( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the amount of time elapsed from another instant to this one, +/// or zero duration if that instant is later than this one. +/// # Panics +/// Previous rust versions panicked when `other` was later than `self`. Currently this +/// method saturates. Future versions may reintroduce the panic in some circumstances. +/// See [Monotonicity]. +/// [Monotonicity]: Instant#monotonicity + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Instant(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroI128", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: i128) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> i128; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI128::new(-1i128).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI128::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the absolute value of self. +///See [`i128::abs`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI128::new(1)?; +///let neg = NonZeroI128::new(-1)?; +/// assert_eq!(pos, pos.abs()); +/// assert_eq!(pos, neg.abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating absolute value, see +///[`i128::saturating_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI128::new(1)?; +///let neg = NonZeroI128::new(-1)?; +///let min = NonZeroI128::new(i128::MIN)?; +///let min_plus = NonZeroI128::new(i128::MIN + 1)?; +///let max = NonZeroI128::new(i128::MAX)?; +/// assert_eq!(pos, pos.saturating_abs()); +/// assert_eq!(pos, neg.saturating_abs()); +/// assert_eq!(max, min.saturating_abs()); +/// assert_eq!(max, min_plus.saturating_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping absolute value, see +///[`i128::wrapping_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI128::new(1)?; +///let neg = NonZeroI128::new(-1)?; +///let min = NonZeroI128::new(i128::MIN)?; +///# let max = NonZeroI128::new(i128::MAX)?; +/// assert_eq!(pos, pos.wrapping_abs()); +/// assert_eq!(pos, neg.wrapping_abs()); +/// assert_eq!(min, min.wrapping_abs()); +/// assert_eq!(max, (-max).wrapping_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the absolute value of self +/// without any wrapping or panicking. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +///# use std::num::NonZeroU128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let u_pos = NonZeroU128::new(1)?; +///let i_pos = NonZeroI128::new(1)?; +///let i_neg = NonZeroI128::new(-1)?; +///let i_min = NonZeroI128::new(i128::MIN)?; +///let u_max = NonZeroU128::new(u128::MAX / 2 + 1)?; +/// assert_eq!(u_pos, i_pos.unsigned_abs()); +/// assert_eq!(u_pos, i_neg.unsigned_abs()); +/// assert_eq!(u_max, i_min.unsigned_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn unsigned_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if `self` is positive and `false` if the +/// number is negative. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI128::new(5)?; +///let neg_five = NonZeroI128::new(-5)?; +/// assert!(pos_five.is_positive()); +/// assert!(!neg_five.is_positive()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_positive(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if `self` is negative and `false` if the +/// number is positive. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI128::new(5)?; +///let neg_five = NonZeroI128::new(-5)?; +/// assert!(neg_five.is_negative()); +/// assert!(!pos_five.is_negative()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_negative(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Saturating negation. Computes `-self`, +///returning [`NonZeroI128::MAX`] +///if `self == NonZeroI128::MIN` +/// instead of overflowing. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI128::new(5)?; +///let neg_five = NonZeroI128::new(-5)?; +///let min = NonZeroI128::new(i128::MIN)?; +///let min_plus_one = NonZeroI128::new(i128::MIN + 1)?; +///let max = NonZeroI128::new(i128::MAX)?; +/// assert_eq!(pos_five.saturating_neg(), neg_five); +/// assert_eq!(min.saturating_neg(), max); +/// assert_eq!(max.saturating_neg(), min_plus_one); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary +/// of the type. +///See [`i128::wrapping_neg`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI128::new(5)?; +///let neg_five = NonZeroI128::new(-5)?; +///let min = NonZeroI128::new(i128::MIN)?; +/// assert_eq!(pos_five.wrapping_neg(), neg_five); +/// assert_eq!(min.wrapping_neg(), min); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroI128::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroI128::new(2)?; +///let four = NonZeroI128::new(4)?; +///let max = NonZeroI128::new(i128::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroI128::MIN`] or [`NonZeroI128::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroI128::new(3)?; +///let twenty_seven = NonZeroI128::new(27)?; +///let max = NonZeroI128::new(i128::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroI128(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroI16", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: i16) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> i16; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI16::new(-1i16).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI16::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the absolute value of self. +///See [`i16::abs`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI16::new(1)?; +///let neg = NonZeroI16::new(-1)?; +/// assert_eq!(pos, pos.abs()); +/// assert_eq!(pos, neg.abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating absolute value, see +///[`i16::saturating_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI16::new(1)?; +///let neg = NonZeroI16::new(-1)?; +///let min = NonZeroI16::new(i16::MIN)?; +///let min_plus = NonZeroI16::new(i16::MIN + 1)?; +///let max = NonZeroI16::new(i16::MAX)?; +/// assert_eq!(pos, pos.saturating_abs()); +/// assert_eq!(pos, neg.saturating_abs()); +/// assert_eq!(max, min.saturating_abs()); +/// assert_eq!(max, min_plus.saturating_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping absolute value, see +///[`i16::wrapping_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI16::new(1)?; +///let neg = NonZeroI16::new(-1)?; +///let min = NonZeroI16::new(i16::MIN)?; +///# let max = NonZeroI16::new(i16::MAX)?; +/// assert_eq!(pos, pos.wrapping_abs()); +/// assert_eq!(pos, neg.wrapping_abs()); +/// assert_eq!(min, min.wrapping_abs()); +/// assert_eq!(max, (-max).wrapping_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the absolute value of self +/// without any wrapping or panicking. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +///# use std::num::NonZeroU16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let u_pos = NonZeroU16::new(1)?; +///let i_pos = NonZeroI16::new(1)?; +///let i_neg = NonZeroI16::new(-1)?; +///let i_min = NonZeroI16::new(i16::MIN)?; +///let u_max = NonZeroU16::new(u16::MAX / 2 + 1)?; +/// assert_eq!(u_pos, i_pos.unsigned_abs()); +/// assert_eq!(u_pos, i_neg.unsigned_abs()); +/// assert_eq!(u_max, i_min.unsigned_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn unsigned_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if `self` is positive and `false` if the +/// number is negative. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI16::new(5)?; +///let neg_five = NonZeroI16::new(-5)?; +/// assert!(pos_five.is_positive()); +/// assert!(!neg_five.is_positive()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_positive(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if `self` is negative and `false` if the +/// number is positive. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI16::new(5)?; +///let neg_five = NonZeroI16::new(-5)?; +/// assert!(neg_five.is_negative()); +/// assert!(!pos_five.is_negative()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_negative(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Saturating negation. Computes `-self`, +///returning [`NonZeroI16::MAX`] +///if `self == NonZeroI16::MIN` +/// instead of overflowing. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI16::new(5)?; +///let neg_five = NonZeroI16::new(-5)?; +///let min = NonZeroI16::new(i16::MIN)?; +///let min_plus_one = NonZeroI16::new(i16::MIN + 1)?; +///let max = NonZeroI16::new(i16::MAX)?; +/// assert_eq!(pos_five.saturating_neg(), neg_five); +/// assert_eq!(min.saturating_neg(), max); +/// assert_eq!(max.saturating_neg(), min_plus_one); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary +/// of the type. +///See [`i16::wrapping_neg`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI16::new(5)?; +///let neg_five = NonZeroI16::new(-5)?; +///let min = NonZeroI16::new(i16::MIN)?; +/// assert_eq!(pos_five.wrapping_neg(), neg_five); +/// assert_eq!(min.wrapping_neg(), min); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroI16::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroI16::new(2)?; +///let four = NonZeroI16::new(4)?; +///let max = NonZeroI16::new(i16::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroI16::MIN`] or [`NonZeroI16::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroI16::new(3)?; +///let twenty_seven = NonZeroI16::new(27)?; +///let max = NonZeroI16::new(i16::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroI16(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroI32", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI32::new(-1i32).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI32::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the absolute value of self. +///See [`i32::abs`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI32::new(1)?; +///let neg = NonZeroI32::new(-1)?; +/// assert_eq!(pos, pos.abs()); +/// assert_eq!(pos, neg.abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating absolute value, see +///[`i32::saturating_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI32::new(1)?; +///let neg = NonZeroI32::new(-1)?; +///let min = NonZeroI32::new(i32::MIN)?; +///let min_plus = NonZeroI32::new(i32::MIN + 1)?; +///let max = NonZeroI32::new(i32::MAX)?; +/// assert_eq!(pos, pos.saturating_abs()); +/// assert_eq!(pos, neg.saturating_abs()); +/// assert_eq!(max, min.saturating_abs()); +/// assert_eq!(max, min_plus.saturating_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping absolute value, see +///[`i32::wrapping_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI32::new(1)?; +///let neg = NonZeroI32::new(-1)?; +///let min = NonZeroI32::new(i32::MIN)?; +///# let max = NonZeroI32::new(i32::MAX)?; +/// assert_eq!(pos, pos.wrapping_abs()); +/// assert_eq!(pos, neg.wrapping_abs()); +/// assert_eq!(min, min.wrapping_abs()); +/// assert_eq!(max, (-max).wrapping_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the absolute value of self +/// without any wrapping or panicking. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +///# use std::num::NonZeroU32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let u_pos = NonZeroU32::new(1)?; +///let i_pos = NonZeroI32::new(1)?; +///let i_neg = NonZeroI32::new(-1)?; +///let i_min = NonZeroI32::new(i32::MIN)?; +///let u_max = NonZeroU32::new(u32::MAX / 2 + 1)?; +/// assert_eq!(u_pos, i_pos.unsigned_abs()); +/// assert_eq!(u_pos, i_neg.unsigned_abs()); +/// assert_eq!(u_max, i_min.unsigned_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn unsigned_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if `self` is positive and `false` if the +/// number is negative. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI32::new(5)?; +///let neg_five = NonZeroI32::new(-5)?; +/// assert!(pos_five.is_positive()); +/// assert!(!neg_five.is_positive()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_positive(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if `self` is negative and `false` if the +/// number is positive. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI32::new(5)?; +///let neg_five = NonZeroI32::new(-5)?; +/// assert!(neg_five.is_negative()); +/// assert!(!pos_five.is_negative()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_negative(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Saturating negation. Computes `-self`, +///returning [`NonZeroI32::MAX`] +///if `self == NonZeroI32::MIN` +/// instead of overflowing. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI32::new(5)?; +///let neg_five = NonZeroI32::new(-5)?; +///let min = NonZeroI32::new(i32::MIN)?; +///let min_plus_one = NonZeroI32::new(i32::MIN + 1)?; +///let max = NonZeroI32::new(i32::MAX)?; +/// assert_eq!(pos_five.saturating_neg(), neg_five); +/// assert_eq!(min.saturating_neg(), max); +/// assert_eq!(max.saturating_neg(), min_plus_one); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary +/// of the type. +///See [`i32::wrapping_neg`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI32::new(5)?; +///let neg_five = NonZeroI32::new(-5)?; +///let min = NonZeroI32::new(i32::MIN)?; +/// assert_eq!(pos_five.wrapping_neg(), neg_five); +/// assert_eq!(min.wrapping_neg(), min); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroI32::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroI32::new(2)?; +///let four = NonZeroI32::new(4)?; +///let max = NonZeroI32::new(i32::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroI32::MIN`] or [`NonZeroI32::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroI32::new(3)?; +///let twenty_seven = NonZeroI32::new(27)?; +///let max = NonZeroI32::new(i32::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroI32(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroI64", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI64::new(-1i64).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI64::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the absolute value of self. +///See [`i64::abs`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI64::new(1)?; +///let neg = NonZeroI64::new(-1)?; +/// assert_eq!(pos, pos.abs()); +/// assert_eq!(pos, neg.abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating absolute value, see +///[`i64::saturating_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI64::new(1)?; +///let neg = NonZeroI64::new(-1)?; +///let min = NonZeroI64::new(i64::MIN)?; +///let min_plus = NonZeroI64::new(i64::MIN + 1)?; +///let max = NonZeroI64::new(i64::MAX)?; +/// assert_eq!(pos, pos.saturating_abs()); +/// assert_eq!(pos, neg.saturating_abs()); +/// assert_eq!(max, min.saturating_abs()); +/// assert_eq!(max, min_plus.saturating_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping absolute value, see +///[`i64::wrapping_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI64::new(1)?; +///let neg = NonZeroI64::new(-1)?; +///let min = NonZeroI64::new(i64::MIN)?; +///# let max = NonZeroI64::new(i64::MAX)?; +/// assert_eq!(pos, pos.wrapping_abs()); +/// assert_eq!(pos, neg.wrapping_abs()); +/// assert_eq!(min, min.wrapping_abs()); +/// assert_eq!(max, (-max).wrapping_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the absolute value of self +/// without any wrapping or panicking. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +///# use std::num::NonZeroU64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let u_pos = NonZeroU64::new(1)?; +///let i_pos = NonZeroI64::new(1)?; +///let i_neg = NonZeroI64::new(-1)?; +///let i_min = NonZeroI64::new(i64::MIN)?; +///let u_max = NonZeroU64::new(u64::MAX / 2 + 1)?; +/// assert_eq!(u_pos, i_pos.unsigned_abs()); +/// assert_eq!(u_pos, i_neg.unsigned_abs()); +/// assert_eq!(u_max, i_min.unsigned_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn unsigned_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if `self` is positive and `false` if the +/// number is negative. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI64::new(5)?; +///let neg_five = NonZeroI64::new(-5)?; +/// assert!(pos_five.is_positive()); +/// assert!(!neg_five.is_positive()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_positive(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if `self` is negative and `false` if the +/// number is positive. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI64::new(5)?; +///let neg_five = NonZeroI64::new(-5)?; +/// assert!(neg_five.is_negative()); +/// assert!(!pos_five.is_negative()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_negative(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Saturating negation. Computes `-self`, +///returning [`NonZeroI64::MAX`] +///if `self == NonZeroI64::MIN` +/// instead of overflowing. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI64::new(5)?; +///let neg_five = NonZeroI64::new(-5)?; +///let min = NonZeroI64::new(i64::MIN)?; +///let min_plus_one = NonZeroI64::new(i64::MIN + 1)?; +///let max = NonZeroI64::new(i64::MAX)?; +/// assert_eq!(pos_five.saturating_neg(), neg_five); +/// assert_eq!(min.saturating_neg(), max); +/// assert_eq!(max.saturating_neg(), min_plus_one); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary +/// of the type. +///See [`i64::wrapping_neg`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI64::new(5)?; +///let neg_five = NonZeroI64::new(-5)?; +///let min = NonZeroI64::new(i64::MIN)?; +/// assert_eq!(pos_five.wrapping_neg(), neg_five); +/// assert_eq!(min.wrapping_neg(), min); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroI64::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroI64::new(2)?; +///let four = NonZeroI64::new(4)?; +///let max = NonZeroI64::new(i64::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroI64::MIN`] or [`NonZeroI64::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroI64::new(3)?; +///let twenty_seven = NonZeroI64::new(27)?; +///let max = NonZeroI64::new(i64::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroI64(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroI8", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: i8) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> i8; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI8::new(-1i8).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroI8::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the absolute value of self. +///See [`i8::abs`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI8::new(1)?; +///let neg = NonZeroI8::new(-1)?; +/// assert_eq!(pos, pos.abs()); +/// assert_eq!(pos, neg.abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating absolute value, see +///[`i8::saturating_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI8::new(1)?; +///let neg = NonZeroI8::new(-1)?; +///let min = NonZeroI8::new(i8::MIN)?; +///let min_plus = NonZeroI8::new(i8::MIN + 1)?; +///let max = NonZeroI8::new(i8::MAX)?; +/// assert_eq!(pos, pos.saturating_abs()); +/// assert_eq!(pos, neg.saturating_abs()); +/// assert_eq!(max, min.saturating_abs()); +/// assert_eq!(max, min_plus.saturating_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping absolute value, see +///[`i8::wrapping_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroI8::new(1)?; +///let neg = NonZeroI8::new(-1)?; +///let min = NonZeroI8::new(i8::MIN)?; +///# let max = NonZeroI8::new(i8::MAX)?; +/// assert_eq!(pos, pos.wrapping_abs()); +/// assert_eq!(pos, neg.wrapping_abs()); +/// assert_eq!(min, min.wrapping_abs()); +/// assert_eq!(max, (-max).wrapping_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the absolute value of self +/// without any wrapping or panicking. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +///# use std::num::NonZeroU8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let u_pos = NonZeroU8::new(1)?; +///let i_pos = NonZeroI8::new(1)?; +///let i_neg = NonZeroI8::new(-1)?; +///let i_min = NonZeroI8::new(i8::MIN)?; +///let u_max = NonZeroU8::new(u8::MAX / 2 + 1)?; +/// assert_eq!(u_pos, i_pos.unsigned_abs()); +/// assert_eq!(u_pos, i_neg.unsigned_abs()); +/// assert_eq!(u_max, i_min.unsigned_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn unsigned_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if `self` is positive and `false` if the +/// number is negative. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI8::new(5)?; +///let neg_five = NonZeroI8::new(-5)?; +/// assert!(pos_five.is_positive()); +/// assert!(!neg_five.is_positive()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_positive(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if `self` is negative and `false` if the +/// number is positive. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI8::new(5)?; +///let neg_five = NonZeroI8::new(-5)?; +/// assert!(neg_five.is_negative()); +/// assert!(!pos_five.is_negative()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_negative(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Saturating negation. Computes `-self`, +///returning [`NonZeroI8::MAX`] +///if `self == NonZeroI8::MIN` +/// instead of overflowing. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI8::new(5)?; +///let neg_five = NonZeroI8::new(-5)?; +///let min = NonZeroI8::new(i8::MIN)?; +///let min_plus_one = NonZeroI8::new(i8::MIN + 1)?; +///let max = NonZeroI8::new(i8::MAX)?; +/// assert_eq!(pos_five.saturating_neg(), neg_five); +/// assert_eq!(min.saturating_neg(), max); +/// assert_eq!(max.saturating_neg(), min_plus_one); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary +/// of the type. +///See [`i8::wrapping_neg`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroI8::new(5)?; +///let neg_five = NonZeroI8::new(-5)?; +///let min = NonZeroI8::new(i8::MIN)?; +/// assert_eq!(pos_five.wrapping_neg(), neg_five); +/// assert_eq!(min.wrapping_neg(), min); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroI8::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroI8::new(2)?; +///let four = NonZeroI8::new(4)?; +///let max = NonZeroI8::new(i8::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroI8::MIN`] or [`NonZeroI8::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroI8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroI8::new(3)?; +///let twenty_seven = NonZeroI8::new(27)?; +///let max = NonZeroI8::new(i8::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroI8(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroU128", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: u128) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> u128; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU128::new(u128::MAX).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU128::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Adds an unsigned integer to a non-zero value. +///Return [`NonZeroU128::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let one = NonZeroU128::new(1)?; +///let two = NonZeroU128::new(2)?; +///let max = NonZeroU128::new(u128::MAX)?; +/// assert_eq!(two, one.saturating_add(1)); +/// assert_eq!(max, max.saturating_add(1)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + other: u128, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the base 2 logarithm of the number, rounded down. +/// This is the same operation as +///[`u128::ilog2`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU128; +///assert_eq!(NonZeroU128::new(7).unwrap().ilog2(), 2); +///assert_eq!(NonZeroU128::new(8).unwrap().ilog2(), 3); +///assert_eq!(NonZeroU128::new(9).unwrap().ilog2(), 3); +/// ``` + + #[lua()] + fn ilog2(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the base 10 logarithm of the number, rounded down. +/// This is the same operation as +///[`u128::ilog10`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU128; +///assert_eq!(NonZeroU128::new(99).unwrap().ilog10(), 1); +///assert_eq!(NonZeroU128::new(100).unwrap().ilog10(), 2); +///assert_eq!(NonZeroU128::new(101).unwrap().ilog10(), 2); +/// ``` + + #[lua()] + fn ilog10(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if and only if `self == (1 << k)` for some `k`. +/// On many architectures, this function can perform better than `is_power_of_two()` +/// on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let eight = std::num::NonZeroU128::new(8).unwrap(); +/// assert!(eight.is_power_of_two()); +///let ten = std::num::NonZeroU128::new(10).unwrap(); +/// assert!(!ten.is_power_of_two()); +/// ``` + + #[lua()] + fn is_power_of_two(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroU128::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroU128::new(2)?; +///let four = NonZeroU128::new(4)?; +///let max = NonZeroU128::new(u128::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroU128::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU128; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroU128::new(3)?; +///let twenty_seven = NonZeroU128::new(27)?; +///let max = NonZeroU128::new(u128::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroU128(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroU16", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: u16) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> u16; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU16::new(u16::MAX).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU16::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Adds an unsigned integer to a non-zero value. +///Return [`NonZeroU16::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let one = NonZeroU16::new(1)?; +///let two = NonZeroU16::new(2)?; +///let max = NonZeroU16::new(u16::MAX)?; +/// assert_eq!(two, one.saturating_add(1)); +/// assert_eq!(max, max.saturating_add(1)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + other: u16, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the base 2 logarithm of the number, rounded down. +/// This is the same operation as +///[`u16::ilog2`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU16; +///assert_eq!(NonZeroU16::new(7).unwrap().ilog2(), 2); +///assert_eq!(NonZeroU16::new(8).unwrap().ilog2(), 3); +///assert_eq!(NonZeroU16::new(9).unwrap().ilog2(), 3); +/// ``` + + #[lua()] + fn ilog2(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the base 10 logarithm of the number, rounded down. +/// This is the same operation as +///[`u16::ilog10`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU16; +///assert_eq!(NonZeroU16::new(99).unwrap().ilog10(), 1); +///assert_eq!(NonZeroU16::new(100).unwrap().ilog10(), 2); +///assert_eq!(NonZeroU16::new(101).unwrap().ilog10(), 2); +/// ``` + + #[lua()] + fn ilog10(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if and only if `self == (1 << k)` for some `k`. +/// On many architectures, this function can perform better than `is_power_of_two()` +/// on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let eight = std::num::NonZeroU16::new(8).unwrap(); +/// assert!(eight.is_power_of_two()); +///let ten = std::num::NonZeroU16::new(10).unwrap(); +/// assert!(!ten.is_power_of_two()); +/// ``` + + #[lua()] + fn is_power_of_two(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroU16::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroU16::new(2)?; +///let four = NonZeroU16::new(4)?; +///let max = NonZeroU16::new(u16::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroU16::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU16; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroU16::new(3)?; +///let twenty_seven = NonZeroU16::new(27)?; +///let max = NonZeroU16::new(u16::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroU16(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroU32", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU32::new(u32::MAX).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU32::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Adds an unsigned integer to a non-zero value. +///Return [`NonZeroU32::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let one = NonZeroU32::new(1)?; +///let two = NonZeroU32::new(2)?; +///let max = NonZeroU32::new(u32::MAX)?; +/// assert_eq!(two, one.saturating_add(1)); +/// assert_eq!(max, max.saturating_add(1)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the base 2 logarithm of the number, rounded down. +/// This is the same operation as +///[`u32::ilog2`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU32; +///assert_eq!(NonZeroU32::new(7).unwrap().ilog2(), 2); +///assert_eq!(NonZeroU32::new(8).unwrap().ilog2(), 3); +///assert_eq!(NonZeroU32::new(9).unwrap().ilog2(), 3); +/// ``` + + #[lua()] + fn ilog2(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the base 10 logarithm of the number, rounded down. +/// This is the same operation as +///[`u32::ilog10`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU32; +///assert_eq!(NonZeroU32::new(99).unwrap().ilog10(), 1); +///assert_eq!(NonZeroU32::new(100).unwrap().ilog10(), 2); +///assert_eq!(NonZeroU32::new(101).unwrap().ilog10(), 2); +/// ``` + + #[lua()] + fn ilog10(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if and only if `self == (1 << k)` for some `k`. +/// On many architectures, this function can perform better than `is_power_of_two()` +/// on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let eight = std::num::NonZeroU32::new(8).unwrap(); +/// assert!(eight.is_power_of_two()); +///let ten = std::num::NonZeroU32::new(10).unwrap(); +/// assert!(!ten.is_power_of_two()); +/// ``` + + #[lua()] + fn is_power_of_two(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroU32::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroU32::new(2)?; +///let four = NonZeroU32::new(4)?; +///let max = NonZeroU32::new(u32::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroU32::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU32; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroU32::new(3)?; +///let twenty_seven = NonZeroU32::new(27)?; +///let max = NonZeroU32::new(u32::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroU32(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroU64", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU64::new(u64::MAX).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU64::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Adds an unsigned integer to a non-zero value. +///Return [`NonZeroU64::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let one = NonZeroU64::new(1)?; +///let two = NonZeroU64::new(2)?; +///let max = NonZeroU64::new(u64::MAX)?; +/// assert_eq!(two, one.saturating_add(1)); +/// assert_eq!(max, max.saturating_add(1)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + other: u64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the base 2 logarithm of the number, rounded down. +/// This is the same operation as +///[`u64::ilog2`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU64; +///assert_eq!(NonZeroU64::new(7).unwrap().ilog2(), 2); +///assert_eq!(NonZeroU64::new(8).unwrap().ilog2(), 3); +///assert_eq!(NonZeroU64::new(9).unwrap().ilog2(), 3); +/// ``` + + #[lua()] + fn ilog2(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the base 10 logarithm of the number, rounded down. +/// This is the same operation as +///[`u64::ilog10`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU64; +///assert_eq!(NonZeroU64::new(99).unwrap().ilog10(), 1); +///assert_eq!(NonZeroU64::new(100).unwrap().ilog10(), 2); +///assert_eq!(NonZeroU64::new(101).unwrap().ilog10(), 2); +/// ``` + + #[lua()] + fn ilog10(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if and only if `self == (1 << k)` for some `k`. +/// On many architectures, this function can perform better than `is_power_of_two()` +/// on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let eight = std::num::NonZeroU64::new(8).unwrap(); +/// assert!(eight.is_power_of_two()); +///let ten = std::num::NonZeroU64::new(10).unwrap(); +/// assert!(!ten.is_power_of_two()); +/// ``` + + #[lua()] + fn is_power_of_two(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroU64::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroU64::new(2)?; +///let four = NonZeroU64::new(4)?; +///let max = NonZeroU64::new(u64::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroU64::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU64; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroU64::new(3)?; +///let twenty_seven = NonZeroU64::new(27)?; +///let max = NonZeroU64::new(u64::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroU64(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroU8", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: u8) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> u8; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU8::new(u8::MAX).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroU8::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Adds an unsigned integer to a non-zero value. +///Return [`NonZeroU8::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let one = NonZeroU8::new(1)?; +///let two = NonZeroU8::new(2)?; +///let max = NonZeroU8::new(u8::MAX)?; +/// assert_eq!(two, one.saturating_add(1)); +/// assert_eq!(max, max.saturating_add(1)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + other: u8, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the base 2 logarithm of the number, rounded down. +/// This is the same operation as +///[`u8::ilog2`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU8; +///assert_eq!(NonZeroU8::new(7).unwrap().ilog2(), 2); +///assert_eq!(NonZeroU8::new(8).unwrap().ilog2(), 3); +///assert_eq!(NonZeroU8::new(9).unwrap().ilog2(), 3); +/// ``` + + #[lua()] + fn ilog2(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the base 10 logarithm of the number, rounded down. +/// This is the same operation as +///[`u8::ilog10`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroU8; +///assert_eq!(NonZeroU8::new(99).unwrap().ilog10(), 1); +///assert_eq!(NonZeroU8::new(100).unwrap().ilog10(), 2); +///assert_eq!(NonZeroU8::new(101).unwrap().ilog10(), 2); +/// ``` + + #[lua()] + fn ilog10(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if and only if `self == (1 << k)` for some `k`. +/// On many architectures, this function can perform better than `is_power_of_two()` +/// on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let eight = std::num::NonZeroU8::new(8).unwrap(); +/// assert!(eight.is_power_of_two()); +///let ten = std::num::NonZeroU8::new(10).unwrap(); +/// assert!(!ten.is_power_of_two()); +/// ``` + + #[lua()] + fn is_power_of_two(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroU8::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroU8::new(2)?; +///let four = NonZeroU8::new(4)?; +///let max = NonZeroU8::new(u8::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroU8::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroU8; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroU8::new(3)?; +///let twenty_seven = NonZeroU8::new(27)?; +///let max = NonZeroU8::new(u8::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroU8(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroUsize", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: usize) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> usize; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroUsize::new(usize::MAX).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroUsize::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Adds an unsigned integer to a non-zero value. +///Return [`NonZeroUsize::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroUsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let one = NonZeroUsize::new(1)?; +///let two = NonZeroUsize::new(2)?; +///let max = NonZeroUsize::new(usize::MAX)?; +/// assert_eq!(two, one.saturating_add(1)); +/// assert_eq!(max, max.saturating_add(1)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + other: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the base 2 logarithm of the number, rounded down. +/// This is the same operation as +///[`usize::ilog2`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroUsize; +///assert_eq!(NonZeroUsize::new(7).unwrap().ilog2(), 2); +///assert_eq!(NonZeroUsize::new(8).unwrap().ilog2(), 3); +///assert_eq!(NonZeroUsize::new(9).unwrap().ilog2(), 3); +/// ``` + + #[lua()] + fn ilog2(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the base 10 logarithm of the number, rounded down. +/// This is the same operation as +///[`usize::ilog10`], +/// except that it has no failure cases to worry about +/// since this value can never be zero. +/// # Examples +/// ``` +///# use std::num::NonZeroUsize; +///assert_eq!(NonZeroUsize::new(99).unwrap().ilog10(), 1); +///assert_eq!(NonZeroUsize::new(100).unwrap().ilog10(), 2); +///assert_eq!(NonZeroUsize::new(101).unwrap().ilog10(), 2); +/// ``` + + #[lua()] + fn ilog10(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if and only if `self == (1 << k)` for some `k`. +/// On many architectures, this function can perform better than `is_power_of_two()` +/// on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let eight = std::num::NonZeroUsize::new(8).unwrap(); +/// assert!(eight.is_power_of_two()); +///let ten = std::num::NonZeroUsize::new(10).unwrap(); +/// assert!(!ten.is_power_of_two()); +/// ``` + + #[lua()] + fn is_power_of_two(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroUsize::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroUsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroUsize::new(2)?; +///let four = NonZeroUsize::new(4)?; +///let max = NonZeroUsize::new(usize::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroUsize::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroUsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroUsize::new(3)?; +///let twenty_seven = NonZeroUsize::new(27)?; +///let max = NonZeroUsize::new(usize::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroUsize(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::path::PathBuf", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone_from( + _self: LuaReflectRefMutProxy, + source: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +/// Allocates an empty `PathBuf`. +/// # Examples +/// ``` +/// use std::path::PathBuf; +/// let path = PathBuf::new(); +/// ``` + + #[lua()] + fn new() -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new `PathBuf` with a given capacity used to create the +/// internal [`OsString`]. See [`with_capacity`] defined on [`OsString`]. +/// # Examples +/// ``` +/// use std::path::PathBuf; +/// let mut path = PathBuf::with_capacity(10); +/// let capacity = path.capacity(); +/// // This push is done without reallocating +/// path.push(r"C:\"); +/// assert_eq!(capacity, path.capacity()); +/// ``` +/// [`with_capacity`]: OsString::with_capacity + + #[lua()] + fn with_capacity(capacity: usize) -> LuaReflectValProxy; + +"#, + r#" +/// Truncates `self` to [`self.parent`]. +/// Returns `false` and does nothing if [`self.parent`] is [`None`]. +/// Otherwise, returns `true`. +/// [`self.parent`]: Path::parent +/// # Examples +/// ``` +/// use std::path::{Path, PathBuf}; +/// let mut p = PathBuf::from("/spirited/away.rs"); +/// p.pop(); +/// assert_eq!(Path::new("/spirited"), p); +/// p.pop(); +/// assert_eq!(Path::new("/"), p); +/// ``` + + #[lua()] + fn pop(_self: LuaReflectRefMutProxy) -> bool; + +"#, + r#" +/// Invokes [`capacity`] on the underlying instance of [`OsString`]. +/// [`capacity`]: OsString::capacity + + #[lua()] + fn capacity(_self: LuaReflectRefProxy) -> usize; + +"#, + r#" +/// Invokes [`clear`] on the underlying instance of [`OsString`]. +/// [`clear`]: OsString::clear + + #[lua()] + fn clear(_self: LuaReflectRefMutProxy) -> (); + +"#, + r#" +/// Invokes [`reserve`] on the underlying instance of [`OsString`]. +/// [`reserve`]: OsString::reserve + + #[lua()] + fn reserve( + _self: LuaReflectRefMutProxy, + additional: usize, + ) -> (); + +"#, + r#" +/// Invokes [`reserve_exact`] on the underlying instance of [`OsString`]. +/// [`reserve_exact`]: OsString::reserve_exact + + #[lua()] + fn reserve_exact( + _self: LuaReflectRefMutProxy, + additional: usize, + ) -> (); + +"#, + r#" +/// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`]. +/// [`shrink_to_fit`]: OsString::shrink_to_fit + + #[lua()] + fn shrink_to_fit(_self: LuaReflectRefMutProxy) -> (); + +"#, + r#" +/// Invokes [`shrink_to`] on the underlying instance of [`OsString`]. +/// [`shrink_to`]: OsString::shrink_to + + #[lua()] + fn shrink_to( + _self: LuaReflectRefMutProxy, + min_capacity: usize, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct PathBuf {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::ops::RangeFull", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct RangeFull {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Quat", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Rotates the [`Direction3d`] using a [`Quat`]. + + #[lua( + as_trait = "std::ops::Mul::", + composite = "mul", + )] + fn mul( + _self: LuaReflectValProxy, + direction: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly +/// normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two quaternions. +/// The sum is not guaranteed to be normalized. +/// Note that addition is not the same as combining the rotations represented by the +/// two quaternions! That corresponds to multiplication. + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts the `rhs` quaternion from `self`. +/// The difference is not guaranteed to be normalized. + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Divides a quaternion by a scalar value. +/// The quotient is not guaranteed to be normalized. + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new rotation quaternion. +/// This should generally not be called manually unless you know what you are doing. +/// Use one of the other constructors instead such as `identity` or `from_axis_angle`. +/// `from_xyzw` is mostly used by unit tests and `serde` deserialization. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua()] + fn from_xyzw(x: f32, y: f32, z: f32, w: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a rotation quaternion from an array. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua()] + fn from_array(a: [f32; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new rotation quaternion from a 4D vector. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua()] + fn from_vec4( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a quaternion for a normalized rotation `axis` and `angle` (in radians). +/// The axis must be a unit vector. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. +/// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + + #[lua()] + fn from_scaled_axis( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the x axis. + + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the y axis. + + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the z axis. + + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + + #[lua()] + fn from_euler( + euler: LuaReflectValProxy, + a: f32, + b: f32, + c: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix. + + #[lua()] + fn from_mat3( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from a 3x3 SIMD aligned rotation matrix. + + #[lua()] + fn from_mat3a( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + + #[lua()] + fn from_mat4( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The rotation is in the +/// plane spanned by the two vectors. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_arc( + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means +/// that the resulting quaternion will rotate `from` so that it is colinear with `to`. +/// The rotation is in the plane spanned by the two vectors. Will rotate at most 90 +/// degrees. +/// The inputs must be unit vectors. +/// `to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_arc_colinear( + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is +/// around the z axis. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc_2d(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_arc_2d( + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the rotation axis scaled by the rotation in radians. + + #[lua()] + fn to_scaled_axis( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the rotation angles for the given euler rotation sequence. + + #[lua()] + fn to_euler( + _self: LuaReflectValProxy, + euler: LuaReflectValProxy, + ) -> (f32, f32, f32); + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 4]; + +"#, + r#" +/// Returns the vector part of the quaternion. + + #[lua()] + fn xyz( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the quaternion conjugate of `self`. For a unit quaternion the +/// conjugate is also the inverse. + + #[lua()] + fn conjugate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the inverse of a normalized quaternion. +/// Typically quaternion inverse returns the conjugate of a normalized quaternion. +/// Because `self` is assumed to already be unit length this method *does not* normalize +/// before returning the conjugate. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. The dot product is +/// equal to the cosine of the angle between two quaternion rotations. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is generally faster than `length()` as it avoids a square +/// root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns whether `self` of length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" + + #[lua()] + fn is_near_identity(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the angle (in radians) for the minimal rotation +/// for transforming this quaternion into another. +/// Both quaternions must be normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two quaternions contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on +/// the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `rhs`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `end` +/// based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `end`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn slerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn mul_vec3( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn mul_quat( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + + #[lua()] + fn from_affine3( + a: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. + + #[lua()] + fn mul_vec3a( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua()] + fn as_dquat( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua()] + fn as_f64( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a quaternion by a scalar value. +/// The product is not guaranteed to be normalized. + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct Quat(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Vec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: f32, y: f32, z: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [f32; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector, e.g. `self - +/// self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max` +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no more than `max` + + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no less than `min` + + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua()] + fn mul_add( + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the angle (in radians) between two vectors. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns some vector that is orthogonal to the given one. +/// The input vector must be finite and non-zero. +/// The output vector is not necessarily unit length. For that use +/// [`Self::any_orthonormal_vector()`] instead. + + #[lua()] + fn any_orthogonal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns any unit vector that is orthogonal to the given one. +/// The input vector must be unit length. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn any_orthonormal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct Vec3 { + x: f32, + y: f32, + z: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::IVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i32, y: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i32; 2]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i32; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: i32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i32::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: i32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct IVec2 { + x: i32, + y: i32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::IVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i32, y: i32, z: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i32; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i32; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: i32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i32::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: i32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct IVec3 { + x: i32, + y: i32, + z: i32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::IVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i32, y: i32, z: i32, w: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i32; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i32; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`IVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i32::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: i32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct IVec4 { + x: i32, + y: i32, + z: i32, + w: i32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::I64Vec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i64, y: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i64; 2]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: i64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i64::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct I64Vec2 { + x: i64, + y: i64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::I64Vec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i64, y: i64, z: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i64; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: i64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i64::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct I64Vec3 { + x: i64, + y: i64, + z: i64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::I64Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i64, y: i64, z: i64, w: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i64; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`I64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i64::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct I64Vec4 { + x: i64, + y: i64, + z: i64, + w: i64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::UVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: u32, y: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [u32; 2]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u32; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: u32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct UVec2 { + x: u32, + y: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::UVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: u32, y: u32, z: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [u32; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u32; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: u32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct UVec3 { + x: u32, + y: u32, + z: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::UVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: u32, y: u32, z: u32, w: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [u32; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u32; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`UVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: u32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct UVec4 { + x: u32, + y: u32, + z: u32, + w: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::U64Vec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: u64, y: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [u64; 2]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u64; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: u64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct U64Vec2 { + x: u64, + y: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::U64Vec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: u64, y: u64, z: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [u64; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u64; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: u64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct U64Vec3 { + x: u64, + y: u64, + z: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::U64Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a new vector. + + #[lua()] + fn new(x: u64, y: u64, z: u64, w: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: u64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [u64; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u64; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`U64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u64; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct U64Vec4 { + x: u64, + y: u64, + z: u64, + w: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Vec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: f32, y: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [f32; 2]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector, e.g. `self - +/// self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max` +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no more than `max` + + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no less than `min` + + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua()] + fn mul_add( + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in +/// conjunction with the [`rotate()`][Self::rotate()] method, e.g. +/// `Vec2::from_angle(PI).rotate(Vec2::Y)` will create the vector `[-1, 0]` +/// and rotate [`Vec2::Y`] around it returning `-Vec2::Y`. + + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the angle (in radians) of this vector in the range `[-π, +π]`. +/// The input does not need to be a unit vector however it must be non-zero. + + #[lua()] + fn to_angle(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns the angle (in radians) between `self` and `rhs` in the range `[-π, +π]`. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct Vec2 { + x: f32, + y: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Vec3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: f32, y: f32, z: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [f32; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector, e.g. `self - +/// self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max` +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no more than `max` + + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no less than `min` + + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua()] + fn mul_add( + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the angle (in radians) between two vectors. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns some vector that is orthogonal to the given one. +/// The input vector must be finite and non-zero. +/// The output vector is not necessarily unit length. For that use +/// [`Self::any_orthonormal_vector()`] instead. + + #[lua()] + fn any_orthogonal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns any unit vector that is orthogonal to the given one. +/// The input vector must be unit length. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn any_orthonormal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct Vec3A(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: f32, y: f32, z: f32, w: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [f32; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. +/// To truncate to [`Vec3A`] use [`Vec3A::from()`]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector, e.g. `self - +/// self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max` +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no more than `max` + + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no less than `min` + + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua()] + fn mul_add( + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct Vec4(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::BVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector mask. + + #[lua()] + fn new(x: bool, y: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 1. + + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 1. + + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct BVec2 { + x: bool, + y: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::BVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" +/// Creates a new vector mask. + + #[lua()] + fn new(x: bool, y: bool, z: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 2. + + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 2. + + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct BVec3 { + x: bool, + y: bool, + z: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::BVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" +/// Creates a new vector mask. + + #[lua()] + fn new(x: bool, y: bool, z: bool, w: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 3. + + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 3. + + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct BVec4 { + x: bool, + y: bool, + z: bool, + w: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: f64, y: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [f64; 2]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f64::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector, e.g. `self - +/// self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max` +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f64, + max: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no more than `max` + + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no less than `min` + + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua()] + fn mul_add( + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in +/// conjunction with the [`rotate()`][Self::rotate()] method, e.g. +/// `DVec2::from_angle(PI).rotate(DVec2::Y)` will create the vector `[-1, 0]` +/// and rotate [`DVec2::Y`] around it returning `-DVec2::Y`. + + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the angle (in radians) of this vector in the range `[-π, +π]`. +/// The input does not need to be a unit vector however it must be non-zero. + + #[lua()] + fn to_angle(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns the angle (in radians) between `self` and `rhs` in the range `[-π, +π]`. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f64) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct DVec2 { + x: f64, + y: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: f64, y: f64, z: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [f64; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f64::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector, e.g. `self - +/// self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max` +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f64, + max: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no more than `max` + + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no less than `min` + + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua()] + fn mul_add( + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the angle (in radians) between two vectors. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns some vector that is orthogonal to the given one. +/// The input vector must be finite and non-zero. +/// The output vector is not necessarily unit length. For that use +/// [`Self::any_orthonormal_vector()`] instead. + + #[lua()] + fn any_orthogonal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns any unit vector that is orthogonal to the given one. +/// The input vector must be unit length. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn any_orthonormal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f64) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct DVec3 { + x: f64, + y: f64, + z: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: f64, y: f64, z: f64, w: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [f64; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`DVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f64::rem_euclid + + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector, e.g. `self - +/// self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max` +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f64, + max: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no more than `max` + + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a vector with a length no less than `min` + + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua()] + fn mul_add( + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f64) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct DVec4 { + x: f64, + y: f64, + z: f64, + w: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Mat2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix from two column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f32; 4]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 4]; + +"#, + r#" +/// Creates a `[[f32; 2]; 2]` 2D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 2]; 2]; + +"#, + r#" +/// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of +/// `angle` (in radians). + + #[lua()] + fn from_scale_angle( + scale: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix containing a rotation of `angle` (in radians). + + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + + #[lua()] + fn from_mat3a( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a 2D vector. + + #[lua()] + fn mul_vec2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two 2x2 matrices. + + #[lua()] + fn mul_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two 2x2 matrices. + + #[lua()] + fn add_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts two 2x2 matrices. + + #[lua()] + fn sub_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a 2x2 matrix by a scalar. + + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" + + #[lua()] + fn as_dmat2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec2(curr_ref) +} +"#] +)] +pub struct Mat2(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Mat3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3x3 matrix from three column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f32; 9]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 9]; + +"#, + r#" +/// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 3]; 3]; + +"#, + r#" +/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. + + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from the given quaternion. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in +/// radians). +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in +/// radians). + + #[lua()] + fn from_euler( + order: LuaReflectValProxy, + a: f32, + b: f32, + c: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D rotation `angle` (in +/// radians). +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in +/// radians) and `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_scale_angle_translation( + scale: LuaReflectValProxy, + angle: f32, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2x2 matrix. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_mat2( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 2D vector as a point. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Rotates the given 2D vector. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a 3D vector. + + #[lua()] + fn mul_vec3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a [`Vec3A`]. + + #[lua()] + fn mul_vec3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two 3x3 matrices. + + #[lua()] + fn mul_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two 3x3 matrices. + + #[lua()] + fn add_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts two 3x3 matrices. + + #[lua()] + fn sub_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a 3x3 matrix by a scalar. + + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" + + #[lua()] + fn as_dmat3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec3(curr_ref) +} +"#] +)] +pub struct Mat3 { + x_axis: bevy::math::Vec3, + y_axis: bevy::math::Vec3, + z_axis: bevy::math::Vec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Mat3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3x3 matrix from three column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f32; 9]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 9]; + +"#, + r#" +/// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 3]; 3]; + +"#, + r#" +/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. + + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from the given quaternion. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in +/// radians). +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in +/// radians). + + #[lua()] + fn from_euler( + order: LuaReflectValProxy, + a: f32, + b: f32, + c: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D rotation `angle` (in +/// radians). +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in +/// radians) and `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_scale_angle_translation( + scale: LuaReflectValProxy, + angle: f32, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2x2 matrix. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_mat2( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 2D vector as a point. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Rotates the given 2D vector. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a 3D vector. + + #[lua()] + fn mul_vec3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a [`Vec3A`]. + + #[lua()] + fn mul_vec3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two 3x3 matrices. + + #[lua()] + fn mul_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two 3x3 matrices. + + #[lua()] + fn add_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts two 3x3 matrices. + + #[lua()] + fn sub_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a 3x3 matrix by a scalar. + + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" + + #[lua()] + fn as_dmat3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec3A(curr_ref) +} +"#] +)] +pub struct Mat3A { + x_axis: bevy::math::Vec3A, + y_axis: bevy::math::Vec3A, + z_axis: bevy::math::Vec3A, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Mat4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 4x4 matrix from four column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f32; 16]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 16]; + +"#, + r#" +/// Creates a `[[f32; 4]; 4]` 4D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 4]; 4]; + +"#, + r#" +/// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `scale`, `rotation` and +/// `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_scale_rotation_translation( + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_translation( + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given `rotation` quaternion. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3x3 linear transformation +/// matrix. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3x3 linear transformation +/// matrix. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_mat3a( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a affine transformation matrix containing a rotation from the given euler +/// rotation sequence and angles (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_euler( + order: LuaReflectValProxy, + a: f32, + b: f32, + c: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the x axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the y axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the z axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing the given 3D non-uniform `scale`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua()] + fn look_to_lh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua()] + fn look_to_rh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_lh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_rh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with [-1,1] depth range. +/// This is the same as the OpenGL `gluPerspective` function. +/// See + + #[lua()] + fn perspective_rh_gl( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + z_far: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua()] + fn perspective_lh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + z_far: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua()] + fn perspective_rh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + z_far: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua()] + fn perspective_infinite_lh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua()] + fn perspective_infinite_reverse_lh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite right-handed perspective projection matrix with +/// `[0,1]` depth range. + + #[lua()] + fn perspective_infinite_rh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite reverse right-handed perspective projection matrix +/// with `[0,1]` depth range. + + #[lua()] + fn perspective_infinite_reverse_rh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[-1,1]` depth +/// range. This is the same as the OpenGL `glOrtho` function in OpenGL. +/// See +/// + + #[lua()] + fn orthographic_rh_gl( + left: f32, + right: f32, + bottom: f32, + top: f32, + near: f32, + far: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + + #[lua()] + fn orthographic_lh( + left: f32, + right: f32, + bottom: f32, + top: f32, + near: f32, + far: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + + #[lua()] + fn orthographic_rh( + left: f32, + right: f32, + bottom: f32, + top: f32, + near: f32, + far: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D vector as a point, applying perspective correction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. +/// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. +/// This method assumes that `self` contains a projective transform. + + #[lua()] + fn project_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D vector as a point. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `1.0`. +/// This method assumes that `self` contains a valid affine transform. It does not perform +/// a persective divide, if `self` contains a perspective transform, or if you are unsure, +/// the [`Self::project_point3()`] method should be used instead. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the give 3D vector as a direction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `0.0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given [`Vec3A`] as 3D point. +/// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `1.0`. + + #[lua()] + fn transform_point3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the give [`Vec3A`] as 3D vector. +/// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `0.0`. + + #[lua()] + fn transform_vector3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a 4D vector. + + #[lua()] + fn mul_vec4( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two 4x4 matrices. + + #[lua()] + fn mul_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two 4x4 matrices. + + #[lua()] + fn add_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts two 4x4 matrices. + + #[lua()] + fn sub_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a 4x4 matrix by a scalar. + + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" + + #[lua()] + fn as_dmat4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec4(curr_ref) +} +"#] +)] +pub struct Mat4 { + x_axis: bevy::math::Vec4, + y_axis: bevy::math::Vec4, + z_axis: bevy::math::Vec4, + w_axis: bevy::math::Vec4, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DMat2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Creates a 2x2 matrix from two column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f64; 4]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 4]; + +"#, + r#" +/// Creates a `[[f64; 2]; 2]` 2D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f64; 2]; 2]; + +"#, + r#" +/// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of +/// `angle` (in radians). + + #[lua()] + fn from_scale_angle( + scale: LuaReflectValProxy, + angle: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix containing a rotation of `angle` (in radians). + + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f64; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a 2D vector. + + #[lua()] + fn mul_vec2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two 2x2 matrices. + + #[lua()] + fn mul_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two 2x2 matrices. + + #[lua()] + fn add_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts two 2x2 matrices. + + #[lua()] + fn sub_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a 2x2 matrix by a scalar. + + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" + + #[lua()] + fn as_mat2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaDVec2(curr_ref) +} +"#] +)] +pub struct DMat2 { + x_axis: bevy::math::DVec2, + y_axis: bevy::math::DVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DMat3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3x3 matrix from three column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f64; 9]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 9]; + +"#, + r#" +/// Creates a `[[f64; 3]; 3]` 3D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f64; 3]; 3]; + +"#, + r#" +/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. + + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from the given quaternion. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in +/// radians). +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in +/// radians). + + #[lua()] + fn from_euler( + order: LuaReflectValProxy, + a: f64, + b: f64, + c: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D rotation `angle` (in +/// radians). +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in +/// radians) and `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_scale_angle_translation( + scale: LuaReflectValProxy, + angle: f64, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2x2 matrix. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua()] + fn from_mat2( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f64; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 2D vector as a point. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Rotates the given 2D vector. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a 3D vector. + + #[lua()] + fn mul_vec3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two 3x3 matrices. + + #[lua()] + fn mul_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two 3x3 matrices. + + #[lua()] + fn add_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts two 3x3 matrices. + + #[lua()] + fn sub_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a 3x3 matrix by a scalar. + + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" + + #[lua()] + fn as_mat3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaDVec3(curr_ref) +} +"#] +)] +pub struct DMat3 { + x_axis: bevy::math::DVec3, + y_axis: bevy::math::DVec3, + z_axis: bevy::math::DVec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DMat4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 4x4 matrix from four column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f64; 16]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 16]; + +"#, + r#" +/// Creates a `[[f64; 4]; 4]` 4D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f64; 4]; 4]; + +"#, + r#" +/// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `scale`, `rotation` and +/// `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_scale_rotation_translation( + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_translation( + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given `rotation` quaternion. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3x3 linear transformation +/// matrix. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a affine transformation matrix containing a rotation from the given euler +/// rotation sequence and angles (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_euler( + order: LuaReflectValProxy, + a: f64, + b: f64, + c: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the x axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the y axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the z axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation matrix containing the given 3D non-uniform `scale`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f64; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua()] + fn look_to_lh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua()] + fn look_to_rh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_lh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_rh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with [-1,1] depth range. +/// This is the same as the OpenGL `gluPerspective` function. +/// See + + #[lua()] + fn perspective_rh_gl( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + z_far: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua()] + fn perspective_lh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + z_far: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua()] + fn perspective_rh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + z_far: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua()] + fn perspective_infinite_lh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua()] + fn perspective_infinite_reverse_lh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite right-handed perspective projection matrix with +/// `[0,1]` depth range. + + #[lua()] + fn perspective_infinite_rh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an infinite reverse right-handed perspective projection matrix +/// with `[0,1]` depth range. + + #[lua()] + fn perspective_infinite_reverse_rh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[-1,1]` depth +/// range. This is the same as the OpenGL `glOrtho` function in OpenGL. +/// See +/// + + #[lua()] + fn orthographic_rh_gl( + left: f64, + right: f64, + bottom: f64, + top: f64, + near: f64, + far: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + + #[lua()] + fn orthographic_lh( + left: f64, + right: f64, + bottom: f64, + top: f64, + near: f64, + far: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + + #[lua()] + fn orthographic_rh( + left: f64, + right: f64, + bottom: f64, + top: f64, + near: f64, + far: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D vector as a point, applying perspective correction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. +/// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. +/// This method assumes that `self` contains a projective transform. + + #[lua()] + fn project_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D vector as a point. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `1.0`. +/// This method assumes that `self` contains a valid affine transform. It does not perform +/// a persective divide, if `self` contains a perspective transform, or if you are unsure, +/// the [`Self::project_point3()`] method should be used instead. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the give 3D vector as a direction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `0.0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms a 4D vector. + + #[lua()] + fn mul_vec4( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two 4x4 matrices. + + #[lua()] + fn mul_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Adds two 4x4 matrices. + + #[lua()] + fn add_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts two 4x4 matrices. + + #[lua()] + fn sub_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a 4x4 matrix by a scalar. + + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" + + #[lua()] + fn as_mat4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaDVec4(curr_ref) +} +"#] +)] +pub struct DMat4 { + x_axis: bevy::math::DVec4, + y_axis: bevy::math::DVec4, + z_axis: bevy::math::DVec4, + w_axis: bevy::math::DVec4, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Affine2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates an affine transform from three column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f32; 6]` array storing data in column major order. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 6]; + +"#, + r#" +/// Creates a `[[f32; 2]; 3]` 2D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 2]; 3]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given rotation `angle`. + + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation from the given 2D `translation`. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + + #[lua()] + fn from_mat2( + matrix2: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a +/// translation vector. +/// Equivalent to +/// `Affine2::from_translation(translation) * Affine2::from_mat2(mat2)` + + #[lua()] + fn from_mat2_translation( + matrix2: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `Affine2::from_translation(translation) * +/// Affine2::from_angle(angle) * Affine2::from_scale(scale)` + + #[lua()] + fn from_scale_angle_translation( + scale: LuaReflectValProxy, + angle: f32, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 2D rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `Affine2::from_translation(translation) * Affine2::from_angle(angle)` + + #[lua()] + fn from_angle_translation( + angle: f32, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The given `Mat3` must be an affine transform, + + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The given [`Mat3A`] must be an affine transform, + + #[lua()] + fn from_mat3a( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 2D point, applying shear, scale, rotation and translation. + + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 2D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point2()`] instead. + + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct Affine2 { + matrix2: bevy::math::Mat2, + translation: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Affine3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from three column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f32; 12]` array storing data in column major order. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 12]; + +"#, + r#" +/// Creates a `[[f32; 3]; 4]` 3D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d( + _self: LuaReflectRefProxy, + ) -> [[f32; 3]; 4]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given `rotation` quaternion. + + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the x axis of +/// `angle` (in radians). + + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the y axis of +/// `angle` (in radians). + + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the z axis of +/// `angle` (in radians). + + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation from the given 3D `translation`. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and +/// rotation) + + #[lua()] + fn from_mat3( + mat3: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) +/// and a translation vector. +/// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_mat3(mat3)` + + #[lua()] + fn from_mat3_translation( + mat3: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 3D `scale`, `rotation` and +/// `translation`. +/// Equivalent to `Affine3A::from_translation(translation) * +/// Affine3A::from_quat(rotation) * Affine3A::from_scale(scale)` + + #[lua()] + fn from_scale_rotation_translation( + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 3D `rotation` and `translation`. +/// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_quat(rotation)` + + #[lua()] + fn from_rotation_translation( + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The given `Mat4` must be an affine transform, +/// i.e. contain no perspective transform. + + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua()] + fn look_to_lh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua()] + fn look_to_rh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_lh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_rh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D points, applying shear, scale, rotation and translation. + + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point3()`] instead. + + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given [`Vec3A`], applying shear, scale, rotation and translation. + + #[lua()] + fn transform_point3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given [`Vec3A`], applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point3a()`] instead. + + #[lua()] + fn transform_vector3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct Affine3A { + matrix3: bevy::math::Mat3A, + translation: bevy::math::Vec3A, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DAffine2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Creates an affine transform from three column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f64; 6]` array storing data in column major order. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 6]; + +"#, + r#" +/// Creates a `[[f64; 2]; 3]` 2D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d( + _self: LuaReflectRefProxy, + ) -> [[f64; 2]; 3]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given rotation `angle`. + + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation from the given 2D `translation`. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + + #[lua()] + fn from_mat2( + matrix2: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a +/// translation vector. +/// Equivalent to +/// `DAffine2::from_translation(translation) * DAffine2::from_mat2(mat2)` + + #[lua()] + fn from_mat2_translation( + matrix2: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `DAffine2::from_translation(translation) * +/// DAffine2::from_angle(angle) * DAffine2::from_scale(scale)` + + #[lua()] + fn from_scale_angle_translation( + scale: LuaReflectValProxy, + angle: f64, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 2D rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `DAffine2::from_translation(translation) * DAffine2::from_angle(angle)` + + #[lua()] + fn from_angle_translation( + angle: f64, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The given `DMat3` must be an affine transform, + + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 2D point, applying shear, scale, rotation and translation. + + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 2D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point2()`] instead. + + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct DAffine2 { + matrix2: bevy::math::DMat2, + translation: bevy::math::DVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DAffine3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from three column vectors. + + #[lua()] + fn from_cols( + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a `[f64; 12]` array storing data in column major order. + + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 12]; + +"#, + r#" +/// Creates a `[[f64; 3]; 4]` 3D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua()] + fn to_cols_array_2d( + _self: LuaReflectRefProxy, + ) -> [[f64; 3]; 4]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given `rotation` quaternion. + + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the x axis of +/// `angle` (in radians). + + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the y axis of +/// `angle` (in radians). + + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the z axis of +/// `angle` (in radians). + + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transformation from the given 3D `translation`. + + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and +/// rotation) + + #[lua()] + fn from_mat3( + mat3: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) +/// and a translation vector. +/// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` + + #[lua()] + fn from_mat3_translation( + mat3: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 3D `scale`, `rotation` and +/// `translation`. +/// Equivalent to `DAffine3::from_translation(translation) * +/// DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` + + #[lua()] + fn from_scale_rotation_translation( + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates an affine transform from the given 3D `rotation` and `translation`. +/// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` + + #[lua()] + fn from_rotation_translation( + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The given `DMat4` must be an affine transform, +/// i.e. contain no perspective transform. + + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua()] + fn look_to_lh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua()] + fn look_to_rh( + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_lh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn look_at_rh( + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D points, applying shear, scale, rotation and translation. + + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Transforms the given 3D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point3()`] instead. + + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct DAffine3 { + matrix3: bevy::math::DMat3, + translation: bevy::math::DVec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DQuat", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Adds two quaternions. +/// The sum is not guaranteed to be normalized. +/// Note that addition is not the same as combining the rotations represented by the +/// two quaternions! That corresponds to multiplication. + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Divides a quaternion by a scalar value. +/// The quotient is not guaranteed to be normalized. + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly +/// normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Subtracts the `rhs` quaternion from `self`. +/// The difference is not guaranteed to be normalized. + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a quaternion by a scalar value. +/// The product is not guaranteed to be normalized. + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new rotation quaternion. +/// This should generally not be called manually unless you know what you are doing. +/// Use one of the other constructors instead such as `identity` or `from_axis_angle`. +/// `from_xyzw` is mostly used by unit tests and `serde` deserialization. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua()] + fn from_xyzw( + x: f64, + y: f64, + z: f64, + w: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a rotation quaternion from an array. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua()] + fn from_array(a: [f64; 4]) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new rotation quaternion from a 4D vector. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua()] + fn from_vec4( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a quaternion for a normalized rotation `axis` and `angle` (in radians). +/// The axis must be a unit vector. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. +/// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + + #[lua()] + fn from_scaled_axis( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the x axis. + + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the y axis. + + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the z axis. + + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + + #[lua()] + fn from_euler( + euler: LuaReflectValProxy, + a: f64, + b: f64, + c: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix. + + #[lua()] + fn from_mat3( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + + #[lua()] + fn from_mat4( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The rotation is in the +/// plane spanned by the two vectors. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_arc( + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means +/// that the resulting quaternion will rotate `from` so that it is colinear with `to`. +/// The rotation is in the plane spanned by the two vectors. Will rotate at most 90 +/// degrees. +/// The inputs must be unit vectors. +/// `to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_arc_colinear( + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is +/// around the z axis. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc_2d(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn from_rotation_arc_2d( + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the rotation axis scaled by the rotation in radians. + + #[lua()] + fn to_scaled_axis( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the rotation angles for the given euler rotation sequence. + + #[lua()] + fn to_euler( + _self: LuaReflectValProxy, + euler: LuaReflectValProxy, + ) -> (f64, f64, f64); + +"#, + r#" +/// `[x, y, z, w]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 4]; + +"#, + r#" +/// Returns the vector part of the quaternion. + + #[lua()] + fn xyz( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the quaternion conjugate of `self`. For a unit quaternion the +/// conjugate is also the inverse. + + #[lua()] + fn conjugate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the inverse of a normalized quaternion. +/// Typically quaternion inverse returns the conjugate of a normalized quaternion. +/// Because `self` is assumed to already be unit length this method *does not* normalize +/// before returning the conjugate. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn inverse( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. The dot product is +/// equal to the cosine of the angle between two quaternion rotations. + + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Computes the length of `self`. + + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is generally faster than `length()` as it avoids a square +/// root operation. + + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; + +"#, + r#" + + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns whether `self` of length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; + +"#, + r#" + + #[lua()] + fn is_near_identity(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns the angle (in radians) for the minimal rotation +/// for transforming this quaternion into another. +/// Both quaternions must be normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two quaternions contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on +/// the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `rhs`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `end` +/// based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `end`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn slerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua()] + fn mul_vec3( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua()] + fn mul_quat( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + + #[lua()] + fn from_affine3( + a: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua()] + fn as_quat( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua()] + fn as_f32( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct DQuat { + x: f64, + y: f64, + z: f64, + w: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::EulerRot", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct EulerRot {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::BVec3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector mask. + + #[lua()] + fn new(x: bool, y: bool, z: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 2. + + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 2. + + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct BVec3A(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::BVec4A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector mask. + + #[lua()] + fn new(x: bool, y: bool, z: bool, w: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 3. + + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 3. + + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct BVec4A(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Direction2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a [`Direction2d`] from a [`Vec2`] that is already normalized. +/// # Warning +/// `value` must be normalized, i.e it's length must be `1.0`. + + #[lua()] + fn new_unchecked( + value: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Direction2d(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Circle", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Create a new [`Circle`] from a `radius` + + #[lua()] + fn new(radius: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Get the diameter of the circle + + #[lua()] + fn diameter(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the area of the circle + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the perimeter or circumference of the circle + + #[lua()] + fn perimeter(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Finds the point on the circle that is closest to the given `point`. +/// If the point is outside the circle, the returned point will be on the perimeter of the circle. +/// Otherwise, it will be inside the circle and returned as is. + + #[lua()] + fn closest_point( + _self: LuaReflectRefProxy, + point: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Circle { + radius: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Ellipse", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Create a new `Ellipse` from half of its width and height. +/// This corresponds to the two perpendicular radii defining the ellipse. + + #[lua()] + fn new( + half_width: f32, + half_height: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Ellipse` from a given full size. +/// `size.x` is the diameter along the X axis, and `size.y` is the diameter along the Y axis. + + #[lua()] + fn from_size( + size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the length of the semi-major axis. This corresponds to the longest radius of the ellipse. + + #[lua()] + fn semi_major(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Returns the length of the semi-minor axis. This corresponds to the shortest radius of the ellipse. + + #[lua()] + fn semi_minor(_self: LuaReflectValProxy) -> f32; + +"#, + r#" +/// Get the area of the ellipse + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Ellipse { + half_size: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Plane2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Create a new `Plane2d` from a normal +/// # Panics +/// Panics if the given `normal` is zero (or very close to zero), or non-finite. + + #[lua()] + fn new( + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Plane2d { + normal: bevy::math::primitives::Direction2d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Line2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Line2d { + direction: bevy::math::primitives::Direction2d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Segment2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a new `Segment2d` from a direction and full length of the segment + + #[lua()] + fn new( + direction: LuaReflectValProxy, + length: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the position of the first point on the line segment + + #[lua()] + fn point1( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the position of the second point on the line segment + + #[lua()] + fn point2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Segment2d { + direction: bevy::math::primitives::Direction2d, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Triangle2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Triangle2d` from points `a`, `b`, and `c` + + #[lua()] + fn new( + a: LuaReflectValProxy, + b: LuaReflectValProxy, + c: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the area of the triangle + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the perimeter of the triangle + + #[lua()] + fn perimeter(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Reverse the [`WindingOrder`] of the triangle +/// by swapping the second and third vertices + + #[lua()] + fn reverse(_self: LuaReflectRefMutProxy) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Triangle2d { + vertices: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Rectangle", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a new `Rectangle` from a full width and height + + #[lua()] + fn new( + width: f32, + height: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Rectangle` from a given full size + + #[lua()] + fn from_size( + size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Rectangle` from two corner points + + #[lua()] + fn from_corners( + point1: LuaReflectValProxy, + point2: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the size of the rectangle + + #[lua()] + fn size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the area of the rectangle + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the perimeter of the rectangle + + #[lua()] + fn perimeter(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Finds the point on the rectangle that is closest to the given `point`. +/// If the point is outside the rectangle, the returned point will be on the perimeter of the rectangle. +/// Otherwise, it will be inside the rectangle and returned as is. + + #[lua()] + fn closest_point( + _self: LuaReflectRefProxy, + point: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Rectangle { + half_size: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::RegularPolygon", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Create a new `RegularPolygon` +/// from the radius of the circumcircle and a number of sides +/// # Panics +/// Panics if `circumradius` is non-positive + + #[lua()] + fn new( + circumradius: f32, + sides: usize, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the radius of the circumcircle on which all vertices +/// of the regular polygon lie + + #[lua()] + fn circumradius( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Get the inradius or apothem of the regular polygon. +/// This is the radius of the largest circle that can +/// be drawn within the polygon + + #[lua()] + fn inradius( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Get the length of one side of the regular polygon + + #[lua()] + fn side_length( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Get the area of the regular polygon + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the perimeter of the regular polygon. +/// This is the sum of its sides + + #[lua()] + fn perimeter( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Get the internal angle of the regular polygon in degrees. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the interior of the polygon + + #[lua()] + fn internal_angle_degrees( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Get the internal angle of the regular polygon in radians. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the interior of the polygon + + #[lua()] + fn internal_angle_radians( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Get the external angle of the regular polygon in degrees. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the exterior of the polygon + + #[lua()] + fn external_angle_degrees( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// Get the external angle of the regular polygon in radians. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the exterior of the polygon + + #[lua()] + fn external_angle_radians( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct RegularPolygon { + circumcircle: bevy::math::primitives::Circle, + sides: usize, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Capsule2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Create a new `Capsule2d` from a radius and length + + #[lua()] + fn new( + radius: f32, + length: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Capsule2d { + radius: f32, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Direction3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a [`Direction3d`] from a [`Vec3`] that is already normalized. +/// # Warning +/// `value` must be normalized, i.e it's length must be `1.0`. + + #[lua()] + fn new_unchecked( + value: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Direction3d(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Sphere", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new [`Sphere`] from a `radius` + + #[lua()] + fn new(radius: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Get the diameter of the sphere + + #[lua()] + fn diameter(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the surface area of the sphere + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the volume of the sphere + + #[lua()] + fn volume(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Finds the point on the sphere that is closest to the given `point`. +/// If the point is outside the sphere, the returned point will be on the surface of the sphere. +/// Otherwise, it will be inside the sphere and returned as is. + + #[lua()] + fn closest_point( + _self: LuaReflectRefProxy, + point: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Sphere { + radius: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Plane3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Plane3d` from a normal +/// # Panics +/// Panics if the given `normal` is zero (or very close to zero), or non-finite. + + #[lua()] + fn new( + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Plane3d { + normal: bevy::math::primitives::Direction3d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Line3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Line3d { + direction: bevy::math::primitives::Direction3d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Segment3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a new `Segment3d` from a direction and full length of the segment + + #[lua()] + fn new( + direction: LuaReflectValProxy, + length: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the position of the first point on the line segment + + #[lua()] + fn point1( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the position of the second point on the line segment + + #[lua()] + fn point2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Segment3d { + direction: bevy::math::primitives::Direction3d, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Cuboid", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Cuboid` from a full x, y, and z length + + #[lua()] + fn new( + x_length: f32, + y_length: f32, + z_length: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Cuboid` from a given full size + + #[lua()] + fn from_size( + size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Cuboid` from two corner points + + #[lua()] + fn from_corners( + point1: LuaReflectValProxy, + point2: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the size of the cuboid + + #[lua()] + fn size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the surface area of the cuboid + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the volume of the cuboid + + #[lua()] + fn volume(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Finds the point on the cuboid that is closest to the given `point`. +/// If the point is outside the cuboid, the returned point will be on the surface of the cuboid. +/// Otherwise, it will be inside the cuboid and returned as is. + + #[lua()] + fn closest_point( + _self: LuaReflectRefProxy, + point: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Cuboid { + half_size: bevy::math::Vec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Cylinder", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Create a new `Cylinder` from a radius and full height + + #[lua()] + fn new( + radius: f32, + height: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the base of the cylinder as a [`Circle`] + + #[lua()] + fn base( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the surface area of the side of the cylinder, +/// also known as the lateral area + + #[lua()] + fn lateral_area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the surface area of one base of the cylinder + + #[lua()] + fn base_area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the total surface area of the cylinder + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the volume of the cylinder + + #[lua()] + fn volume(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Cylinder { + radius: f32, + half_height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Capsule3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new `Capsule3d` from a radius and length + + #[lua()] + fn new( + radius: f32, + length: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the part connecting the hemispherical ends +/// of the capsule as a [`Cylinder`] + + #[lua()] + fn to_cylinder( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the surface area of the capsule + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the volume of the capsule + + #[lua()] + fn volume(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Capsule3d { + radius: f32, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Cone", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the base of the cone as a [`Circle`] + + #[lua()] + fn base( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the slant height of the cone, the length of the line segment +/// connecting a point on the base to the apex + + #[lua()] + fn slant_height(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the surface area of the side of the cone, +/// also known as the lateral area + + #[lua()] + fn lateral_area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the surface area of the base of the cone + + #[lua()] + fn base_area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the total surface area of the cone + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the volume of the cone + + #[lua()] + fn volume(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Cone { + radius: f32, + height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::ConicalFrustum", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ConicalFrustum { + radius_top: f32, + radius_bottom: f32, + height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::primitives::Torus", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a new `Torus` from an inner and outer radius. +/// The inner radius is the radius of the hole, and the outer radius +/// is the radius of the entire object + + #[lua()] + fn new( + inner_radius: f32, + outer_radius: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Get the inner radius of the torus. +/// For a ring torus, this corresponds to the radius of the hole, +/// or `major_radius - minor_radius` + + #[lua()] + fn inner_radius(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the outer radius of the torus. +/// This corresponds to the overall radius of the entire object, +/// or `major_radius + minor_radius` + + #[lua()] + fn outer_radius(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the surface area of the torus. Note that this only produces +/// the expected result when the torus has a ring and isn't self-intersecting + + #[lua()] + fn area(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Get the volume of the torus. Note that this only produces +/// the expected result when the torus has a ring and isn't self-intersecting + + #[lua()] + fn volume(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Torus { + minor_radius: f32, + major_radius: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::IRect", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 4, 10, 6); // w=10 h=2 +/// let r = IRect::new(2, 3, 5, -1); // w=3 h=4 +/// ``` + + #[lua()] + fn new(x0: i32, y0: i32, x1: i32, y1: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// // Unit rect from [0,0] to [1,1] +/// let r = IRect::from_corners(IVec2::ZERO, IVec2::ONE); // w=1 h=1 +/// // Same; the points do not need to be ordered +/// let r = IRect::from_corners(IVec2::ONE, IVec2::ZERO); // w=1 h=1 +/// ``` + + #[lua()] + fn from_corners( + p0: LuaReflectValProxy, + p1: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from its center and size. +/// # Rounding Behaviour +/// If the size contains odd numbers they will be rounded down to the nearest whole number. +/// # Panics +/// This method panics if any of the components of the size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::from_center_size(IVec2::ZERO, IVec2::new(3, 2)); // w=2 h=2 +/// assert_eq!(r.min, IVec2::splat(-1)); +/// assert_eq!(r.max, IVec2::splat(1)); +/// ``` + + #[lua()] + fn from_center_size( + origin: LuaReflectValProxy, + size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from its center and half-size. +/// # Panics +/// This method panics if any of the components of the half-size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::from_center_half_size(IVec2::ZERO, IVec2::ONE); // w=2 h=2 +/// assert_eq!(r.min, IVec2::splat(-1)); +/// assert_eq!(r.max, IVec2::splat(1)); +/// ``` + + #[lua()] + fn from_center_half_size( + origin: LuaReflectValProxy, + half_size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Check if the rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::from_corners(IVec2::ZERO, IVec2::new(0, 1)); // w=0 h=1 +/// assert!(r.is_empty()); +/// ``` + + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Rectangle width (max.x - min.x). +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.width(), 5); +/// ``` + + #[lua()] + fn width(_self: LuaReflectRefProxy) -> i32; + +"#, + r#" +/// Rectangle height (max.y - min.y). +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.height(), 1); +/// ``` + + #[lua()] + fn height(_self: LuaReflectRefProxy) -> i32; + +"#, + r#" +/// Rectangle size. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.size(), IVec2::new(5, 1)); +/// ``` + + #[lua()] + fn size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Rectangle half-size. +/// # Rounding Behaviour +/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 4, 3); // w=4 h=3 +/// assert_eq!(r.half_size(), IVec2::new(2, 1)); +/// ``` + + #[lua()] + fn half_size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The center point of the rectangle. +/// # Rounding Behaviour +/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 2); // w=5 h=2 +/// assert_eq!(r.center(), IVec2::new(2, 1)); +/// ``` + + #[lua()] + fn center( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Check if a point lies within this rectangle, inclusive of its edges. +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert!(r.contains(r.center())); +/// assert!(r.contains(r.min)); +/// assert!(r.contains(r.max)); +/// ``` + + #[lua()] + fn contains( + _self: LuaReflectRefProxy, + point: LuaReflectValProxy, + ) -> bool; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and another rectangle. +/// The union is the smallest rectangle enclosing both rectangles. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r1 = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = IRect::new(1, -1, 3, 3); // w=2 h=4 +/// let r = r1.union(r2); +/// assert_eq!(r.min, IVec2::new(0, -1)); +/// assert_eq!(r.max, IVec2::new(5, 3)); +/// ``` + + #[lua()] + fn union( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and a point. +/// The union is the smallest rectangle enclosing both the rectangle and the point. If the +/// point is already inside the rectangle, this method returns a copy of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let u = r.union_point(IVec2::new(3, 6)); +/// assert_eq!(u.min, IVec2::ZERO); +/// assert_eq!(u.max, IVec2::new(5, 6)); +/// ``` + + #[lua()] + fn union_point( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. +/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection +/// is empty, this method returns an empty rectangle ([`IRect::is_empty()`] returns `true`), but +/// the actual values of [`IRect::min`] and [`IRect::max`] are implementation-dependent. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r1 = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = IRect::new(1, -1, 3, 3); // w=2 h=4 +/// let r = r1.intersect(r2); +/// assert_eq!(r.min, IVec2::new(1, 0)); +/// assert_eq!(r.max, IVec2::new(3, 1)); +/// ``` + + #[lua()] + fn intersect( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle with a constant inset. +/// The inset is the extra border on all sides. A positive inset produces a larger rectangle, +/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative +/// and its absolute value is larger than the rectangle half-size, the created rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = r.inset(3); // w=11 h=7 +/// assert_eq!(r2.min, IVec2::splat(-3)); +/// assert_eq!(r2.max, IVec2::new(8, 4)); +/// let r = IRect::new(0, -1, 4, 3); // w=4 h=4 +/// let r2 = r.inset(-1); // w=2 h=2 +/// assert_eq!(r2.min, IVec2::new(1, 0)); +/// assert_eq!(r2.max, IVec2::new(3, 2)); +/// ``` + + #[lua()] + fn inset( + _self: LuaReflectRefProxy, + inset: i32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns self as [`Rect`] (f32) + + #[lua()] + fn as_rect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns self as [`URect`] (u32) + + #[lua()] + fn as_urect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct IRect { + min: bevy::math::IVec2, + max: bevy::math::IVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Rect", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 4., 10., 6.); // w=10 h=2 +/// let r = Rect::new(2., 3., 5., -1.); // w=3 h=4 +/// ``` + + #[lua()] + fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// // Unit rect from [0,0] to [1,1] +/// let r = Rect::from_corners(Vec2::ZERO, Vec2::ONE); // w=1 h=1 +/// // Same; the points do not need to be ordered +/// let r = Rect::from_corners(Vec2::ONE, Vec2::ZERO); // w=1 h=1 +/// ``` + + #[lua()] + fn from_corners( + p0: LuaReflectValProxy, + p1: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from its center and size. +/// # Panics +/// This method panics if any of the components of the size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::from_center_size(Vec2::ZERO, Vec2::ONE); // w=1 h=1 +/// assert!(r.min.abs_diff_eq(Vec2::splat(-0.5), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::splat(0.5), 1e-5)); +/// ``` + + #[lua()] + fn from_center_size( + origin: LuaReflectValProxy, + size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from its center and half-size. +/// # Panics +/// This method panics if any of the components of the half-size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::from_center_half_size(Vec2::ZERO, Vec2::ONE); // w=2 h=2 +/// assert!(r.min.abs_diff_eq(Vec2::splat(-1.), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::splat(1.), 1e-5)); +/// ``` + + #[lua()] + fn from_center_half_size( + origin: LuaReflectValProxy, + half_size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Check if the rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::from_corners(Vec2::ZERO, Vec2::new(0., 1.)); // w=0 h=1 +/// assert!(r.is_empty()); +/// ``` + + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Rectangle width (max.x - min.x). +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!((r.width() - 5.).abs() <= 1e-5); +/// ``` + + #[lua()] + fn width(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Rectangle height (max.y - min.y). +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!((r.height() - 1.).abs() <= 1e-5); +/// ``` + + #[lua()] + fn height(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// Rectangle size. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.size().abs_diff_eq(Vec2::new(5., 1.), 1e-5)); +/// ``` + + #[lua()] + fn size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Rectangle half-size. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.half_size().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); +/// ``` + + #[lua()] + fn half_size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The center point of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.center().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); +/// ``` + + #[lua()] + fn center( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Check if a point lies within this rectangle, inclusive of its edges. +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.contains(r.center())); +/// assert!(r.contains(r.min)); +/// assert!(r.contains(r.max)); +/// ``` + + #[lua()] + fn contains( + _self: LuaReflectRefProxy, + point: LuaReflectValProxy, + ) -> bool; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and another rectangle. +/// The union is the smallest rectangle enclosing both rectangles. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r1 = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let r2 = Rect::new(1., -1., 3., 3.); // w=2 h=4 +/// let r = r1.union(r2); +/// assert!(r.min.abs_diff_eq(Vec2::new(0., -1.), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::new(5., 3.), 1e-5)); +/// ``` + + #[lua()] + fn union( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and a point. +/// The union is the smallest rectangle enclosing both the rectangle and the point. If the +/// point is already inside the rectangle, this method returns a copy of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let u = r.union_point(Vec2::new(3., 6.)); +/// assert!(u.min.abs_diff_eq(Vec2::ZERO, 1e-5)); +/// assert!(u.max.abs_diff_eq(Vec2::new(5., 6.), 1e-5)); +/// ``` + + #[lua()] + fn union_point( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. +/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection +/// is empty, this method returns an empty rectangle ([`Rect::is_empty()`] returns `true`), but +/// the actual values of [`Rect::min`] and [`Rect::max`] are implementation-dependent. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r1 = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let r2 = Rect::new(1., -1., 3., 3.); // w=2 h=4 +/// let r = r1.intersect(r2); +/// assert!(r.min.abs_diff_eq(Vec2::new(1., 0.), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::new(3., 1.), 1e-5)); +/// ``` + + #[lua()] + fn intersect( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle with a constant inset. +/// The inset is the extra border on all sides. A positive inset produces a larger rectangle, +/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative +/// and its absolute value is larger than the rectangle half-size, the created rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let r2 = r.inset(3.); // w=11 h=7 +/// assert!(r2.min.abs_diff_eq(Vec2::splat(-3.), 1e-5)); +/// assert!(r2.max.abs_diff_eq(Vec2::new(8., 4.), 1e-5)); +/// let r = Rect::new(0., -1., 6., 7.); // w=6 h=8 +/// let r2 = r.inset(-2.); // w=11 h=7 +/// assert!(r2.min.abs_diff_eq(Vec2::new(2., 1.), 1e-5)); +/// assert!(r2.max.abs_diff_eq(Vec2::new(4., 5.), 1e-5)); +/// ``` + + #[lua()] + fn inset( + _self: LuaReflectRefProxy, + inset: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Build a new rectangle from this one with its coordinates expressed +/// relative to `other` in a normalized ([0..1] x [0..1]) coordinate system. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(2., 3., 4., 6.); +/// let s = Rect::new(0., 0., 10., 10.); +/// let n = r.normalize(s); +/// assert_eq!(n.min.x, 0.2); +/// assert_eq!(n.min.y, 0.3); +/// assert_eq!(n.max.x, 0.4); +/// assert_eq!(n.max.y, 0.6); +/// ``` + + #[lua()] + fn normalize( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns self as [`IRect`] (i32) + + #[lua()] + fn as_irect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns self as [`URect`] (u32) + + #[lua()] + fn as_urect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Rect { + min: bevy::math::Vec2, + max: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::URect", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 4, 10, 6); // w=10 h=2 +/// let r = URect::new(2, 4, 5, 0); // w=3 h=4 +/// ``` + + #[lua()] + fn new(x0: u32, y0: u32, x1: u32, y1: u32) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// // Unit rect from [0,0] to [1,1] +/// let r = URect::from_corners(UVec2::ZERO, UVec2::ONE); // w=1 h=1 +/// // Same; the points do not need to be ordered +/// let r = URect::from_corners(UVec2::ONE, UVec2::ZERO); // w=1 h=1 +/// ``` + + #[lua()] + fn from_corners( + p0: LuaReflectValProxy, + p1: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from its center and size. +/// # Rounding Behaviour +/// If the size contains odd numbers they will be rounded down to the nearest whole number. +/// # Panics +/// This method panics if any of the components of the size is negative or if `origin - (size / 2)` results in any negatives. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::from_center_size(UVec2::ONE, UVec2::splat(2)); // w=2 h=2 +/// assert_eq!(r.min, UVec2::splat(0)); +/// assert_eq!(r.max, UVec2::splat(2)); +/// ``` + + #[lua()] + fn from_center_size( + origin: LuaReflectValProxy, + size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle from its center and half-size. +/// # Panics +/// This method panics if any of the components of the half-size is negative or if `origin - half_size` results in any negatives. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::from_center_half_size(UVec2::ONE, UVec2::ONE); // w=2 h=2 +/// assert_eq!(r.min, UVec2::splat(0)); +/// assert_eq!(r.max, UVec2::splat(2)); +/// ``` + + #[lua()] + fn from_center_half_size( + origin: LuaReflectValProxy, + half_size: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Check if the rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::from_corners(UVec2::ZERO, UVec2::new(0, 1)); // w=0 h=1 +/// assert!(r.is_empty()); +/// ``` + + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Rectangle width (max.x - min.x). +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.width(), 5); +/// ``` + + #[lua()] + fn width(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// Rectangle height (max.y - min.y). +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.height(), 1); +/// ``` + + #[lua()] + fn height(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// Rectangle size. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.size(), UVec2::new(5, 1)); +/// ``` + + #[lua()] + fn size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Rectangle half-size. +/// # Rounding Behaviour +/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 +/// assert_eq!(r.half_size(), UVec2::new(2, 1)); +/// ``` + + #[lua()] + fn half_size( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The center point of the rectangle. +/// # Rounding Behaviour +/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 +/// assert_eq!(r.center(), UVec2::new(2, 1)); +/// ``` + + #[lua()] + fn center( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Check if a point lies within this rectangle, inclusive of its edges. +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert!(r.contains(r.center())); +/// assert!(r.contains(r.min)); +/// assert!(r.contains(r.max)); +/// ``` + + #[lua()] + fn contains( + _self: LuaReflectRefProxy, + point: LuaReflectValProxy, + ) -> bool; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and another rectangle. +/// The union is the smallest rectangle enclosing both rectangles. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r1 = URect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = URect::new(1, 0, 3, 8); // w=2 h=4 +/// let r = r1.union(r2); +/// assert_eq!(r.min, UVec2::new(0, 0)); +/// assert_eq!(r.max, UVec2::new(5, 8)); +/// ``` + + #[lua()] + fn union( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and a point. +/// The union is the smallest rectangle enclosing both the rectangle and the point. If the +/// point is already inside the rectangle, this method returns a copy of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// let u = r.union_point(UVec2::new(3, 6)); +/// assert_eq!(u.min, UVec2::ZERO); +/// assert_eq!(u.max, UVec2::new(5, 6)); +/// ``` + + #[lua()] + fn union_point( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. +/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection +/// is empty, this method returns an empty rectangle ([`URect::is_empty()`] returns `true`), but +/// the actual values of [`URect::min`] and [`URect::max`] are implementation-dependent. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r1 = URect::new(0, 0, 2, 2); // w=2 h=2 +/// let r2 = URect::new(1, 1, 3, 3); // w=2 h=2 +/// let r = r1.intersect(r2); +/// assert_eq!(r.min, UVec2::new(1, 1)); +/// assert_eq!(r.max, UVec2::new(2, 2)); +/// ``` + + #[lua()] + fn intersect( + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a new rectangle with a constant inset. +/// The inset is the extra border on all sides. A positive inset produces a larger rectangle, +/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative +/// and its absolute value is larger than the rectangle half-size, the created rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(4, 4, 6, 6); // w=2 h=2 +/// let r2 = r.inset(1); // w=4 h=4 +/// assert_eq!(r2.min, UVec2::splat(3)); +/// assert_eq!(r2.max, UVec2::splat(7)); +/// let r = URect::new(4, 4, 8, 8); // w=4 h=4 +/// let r2 = r.inset(-1); // w=2 h=2 +/// assert_eq!(r2.min, UVec2::splat(5)); +/// assert_eq!(r2.max, UVec2::splat(7)); +/// ``` + + #[lua()] + fn inset( + _self: LuaReflectRefProxy, + inset: i32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns self as [`Rect`] (f32) + + #[lua()] + fn as_rect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns self as [`IRect`] (i32) + + #[lua()] + fn as_irect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct URect { + min: bevy::math::UVec2, + max: bevy::math::UVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "smol_str::SmolStr", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua()] + fn to_string(_self: LuaReflectRefProxy) -> std::string::String; + +"#, + r#" + + #[lua()] + fn len(_self: LuaReflectRefProxy) -> usize; + +"#, + r#" + + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" + + #[lua()] + fn is_heap_allocated(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct SmolStr(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "std::num::NonZeroIsize", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +/// Creates a non-zero without checking whether the value is non-zero. +/// This results in undefined behaviour if the value is zero. +/// # Safety +/// The value must not be zero. + + #[lua()] + unsafe fn new_unchecked(n: isize) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the value as a primitive type. + + #[lua()] + fn get(_self: LuaReflectValProxy) -> isize; + +"#, + r#" +/// Returns the number of leading zeros in the binary representation of `self`. +/// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroIsize::new(-1isize).unwrap(); +/// assert_eq!(n.leading_zeros(), 0); +/// ``` + + #[lua()] + fn leading_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Returns the number of trailing zeros in the binary representation +/// of `self`. +/// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided. +/// # Examples +/// Basic usage: +/// ``` +///let n = std::num::NonZeroIsize::new(0b0101000).unwrap(); +/// assert_eq!(n.trailing_zeros(), 3); +/// ``` + + #[lua()] + fn trailing_zeros(_self: LuaReflectValProxy) -> u32; + +"#, + r#" +/// Computes the absolute value of self. +///See [`isize::abs`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroIsize::new(1)?; +///let neg = NonZeroIsize::new(-1)?; +/// assert_eq!(pos, pos.abs()); +/// assert_eq!(pos, neg.abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Saturating absolute value, see +///[`isize::saturating_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroIsize::new(1)?; +///let neg = NonZeroIsize::new(-1)?; +///let min = NonZeroIsize::new(isize::MIN)?; +///let min_plus = NonZeroIsize::new(isize::MIN + 1)?; +///let max = NonZeroIsize::new(isize::MAX)?; +/// assert_eq!(pos, pos.saturating_abs()); +/// assert_eq!(pos, neg.saturating_abs()); +/// assert_eq!(max, min.saturating_abs()); +/// assert_eq!(max, min_plus.saturating_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping absolute value, see +///[`isize::wrapping_abs`]. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos = NonZeroIsize::new(1)?; +///let neg = NonZeroIsize::new(-1)?; +///let min = NonZeroIsize::new(isize::MIN)?; +///# let max = NonZeroIsize::new(isize::MAX)?; +/// assert_eq!(pos, pos.wrapping_abs()); +/// assert_eq!(pos, neg.wrapping_abs()); +/// assert_eq!(min, min.wrapping_abs()); +/// assert_eq!(max, (-max).wrapping_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Computes the absolute value of self +/// without any wrapping or panicking. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +///# use std::num::NonZeroUsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let u_pos = NonZeroUsize::new(1)?; +///let i_pos = NonZeroIsize::new(1)?; +///let i_neg = NonZeroIsize::new(-1)?; +///let i_min = NonZeroIsize::new(isize::MIN)?; +///let u_max = NonZeroUsize::new(usize::MAX / 2 + 1)?; +/// assert_eq!(u_pos, i_pos.unsigned_abs()); +/// assert_eq!(u_pos, i_neg.unsigned_abs()); +/// assert_eq!(u_max, i_min.unsigned_abs()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn unsigned_abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if `self` is positive and `false` if the +/// number is negative. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroIsize::new(5)?; +///let neg_five = NonZeroIsize::new(-5)?; +/// assert!(pos_five.is_positive()); +/// assert!(!neg_five.is_positive()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_positive(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Returns `true` if `self` is negative and `false` if the +/// number is positive. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroIsize::new(5)?; +///let neg_five = NonZeroIsize::new(-5)?; +/// assert!(neg_five.is_negative()); +/// assert!(!pos_five.is_negative()); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn is_negative(_self: LuaReflectValProxy) -> bool; + +"#, + r#" +/// Saturating negation. Computes `-self`, +///returning [`NonZeroIsize::MAX`] +///if `self == NonZeroIsize::MIN` +/// instead of overflowing. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroIsize::new(5)?; +///let neg_five = NonZeroIsize::new(-5)?; +///let min = NonZeroIsize::new(isize::MIN)?; +///let min_plus_one = NonZeroIsize::new(isize::MIN + 1)?; +///let max = NonZeroIsize::new(isize::MAX)?; +/// assert_eq!(pos_five.saturating_neg(), neg_five); +/// assert_eq!(min.saturating_neg(), max); +/// assert_eq!(max.saturating_neg(), min_plus_one); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary +/// of the type. +///See [`isize::wrapping_neg`] +/// for documentation on overflow behaviour. +/// # Example +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let pos_five = NonZeroIsize::new(5)?; +///let neg_five = NonZeroIsize::new(-5)?; +///let min = NonZeroIsize::new(isize::MIN)?; +/// assert_eq!(pos_five.wrapping_neg(), neg_five); +/// assert_eq!(min.wrapping_neg(), min); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn wrapping_neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies two non-zero integers together. +///Return [`NonZeroIsize::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let two = NonZeroIsize::new(2)?; +///let four = NonZeroIsize::new(4)?; +///let max = NonZeroIsize::new(isize::MAX)?; +/// assert_eq!(four, two.saturating_mul(two)); +/// assert_eq!(max, four.saturating_mul(max)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Raise non-zero value to an integer power. +///Return [`NonZeroIsize::MIN`] or [`NonZeroIsize::MAX`] on overflow. +/// # Examples +/// ``` +///# use std::num::NonZeroIsize; +/// # fn main() { test().unwrap(); } +/// # fn test() -> Option<()> { +///let three = NonZeroIsize::new(3)?; +///let twenty_seven = NonZeroIsize::new(27)?; +///let max = NonZeroIsize::new(isize::MAX)?; +/// assert_eq!(twenty_seven, three.saturating_pow(3)); +/// assert_eq!(max, max.saturating_pow(3)); +/// # Some(()) +/// # } +/// ``` + + #[lua()] + fn saturating_pow( + _self: LuaReflectValProxy, + other: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct NonZeroIsize(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::utils::Uuid", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Creates a random UUID. +/// This uses the [`getrandom`] crate to utilise the operating system's RNG +/// as the source of random numbers. If you'd like to use a custom +/// generator, don't use this method: generate random bytes using your +/// custom generator and pass them to the +/// [`uuid::Builder::from_random_bytes`][from_random_bytes] function +/// instead. +/// Note that usage of this method requires the `v4` feature of this crate +/// to be enabled. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::{Uuid, Version}; +/// let uuid = Uuid::new_v4(); +/// assert_eq!(Some(Version::Random), uuid.get_version()); +/// ``` +/// # References +/// * [Version 4 UUIDs in RFC4122](https://www.rfc-editor.org/rfc/rfc4122#section-4.4) +/// [`getrandom`]: https://crates.io/crates/getrandom +/// [from_random_bytes]: struct.Builder.html#method.from_random_bytes + + #[lua()] + fn new_v4() -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the version number of the UUID. +/// This represents the algorithm used to generate the value. +/// This method is the future-proof alternative to [`Uuid::get_version`]. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?; +/// assert_eq!(3, my_uuid.get_version_num()); +/// # Ok(()) +/// # } +/// ``` +/// # References +/// * [Version in RFC4122](https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.3) + + #[lua()] + fn get_version_num(_self: LuaReflectRefProxy) -> usize; + +"#, + r#" +/// Returns a 128bit value containing the value. +/// The bytes in the UUID will be packed directly into a `u128`. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.as_u128(), +/// 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8, +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua()] + fn as_u128(_self: LuaReflectRefProxy) -> u128; + +"#, + r#" +/// Returns a 128bit little-endian value containing the value. +/// The bytes in the `u128` will be flipped to convert into big-endian +/// order. This is based on the endianness of the UUID, rather than the +/// target environment so bytes will be flipped on both big and little +/// endian machines. +/// Note that this will produce a different result than +/// [`Uuid::to_fields_le`], because the entire UUID is reversed, rather +/// than reversing the individual fields in-place. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.to_u128_le(), +/// 0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1, +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua()] + fn to_u128_le(_self: LuaReflectRefProxy) -> u128; + +"#, + r#" +/// Returns two 64bit values containing the value. +/// The bytes in the UUID will be split into two `u64`. +/// The first u64 represents the 64 most significant bits, +/// the second one represents the 64 least significant. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.as_u64_pair(), +/// (0xa1a2a3a4b1b2c1c2, 0xd1d2d3d4d5d6d7d8), +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua()] + fn as_u64_pair(_self: LuaReflectRefProxy) -> (u64, u64); + +"#, + r#" +/// Consumes self and returns the underlying byte value of the UUID. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// let bytes = [ +/// 0xa1, 0xa2, 0xa3, 0xa4, +/// 0xb1, 0xb2, +/// 0xc1, 0xc2, +/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, +/// ]; +/// let uuid = Uuid::from_bytes(bytes); +/// assert_eq!(bytes, uuid.into_bytes()); +/// ``` + + #[lua()] + fn into_bytes(_self: LuaReflectValProxy) -> [u8; 16]; + +"#, + r#" +/// Returns the bytes of the UUID in little-endian order. +/// The bytes will be flipped to convert into little-endian order. This is +/// based on the endianness of the UUID, rather than the target environment +/// so bytes will be flipped on both big and little endian machines. +/// # Examples +/// ``` +/// use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.to_bytes_le(), +/// ([ +/// 0xa4, 0xa3, 0xa2, 0xa1, 0xb2, 0xb1, 0xc2, 0xc1, 0xd1, 0xd2, +/// 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 +/// ]) +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua()] + fn to_bytes_le(_self: LuaReflectRefProxy) -> [u8; 16]; + +"#, + r#" +/// Tests if the UUID is nil (all zeros). + + #[lua()] + fn is_nil(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// Tests if the UUID is max (all ones). + + #[lua()] + fn is_max(_self: LuaReflectRefProxy) -> bool; + +"#, + r#" +/// A buffer that can be used for `encode_...` calls, that is +/// guaranteed to be long enough for any of the format adapters. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// let uuid = Uuid::nil(); +/// assert_eq!( +/// uuid.simple().encode_lower(&mut Uuid::encode_buffer()), +/// "00000000000000000000000000000000" +/// ); +/// assert_eq!( +/// uuid.hyphenated() +/// .encode_lower(&mut Uuid::encode_buffer()), +/// "00000000-0000-0000-0000-000000000000" +/// ); +/// assert_eq!( +/// uuid.urn().encode_lower(&mut Uuid::encode_buffer()), +/// "urn:uuid:00000000-0000-0000-0000-000000000000" +/// ); +/// ``` + + #[lua()] + fn encode_buffer() -> [u8; 45]; + +"#, + r#" +/// The 'nil UUID' (all zeros). +/// The nil UUID is a special form of UUID that is specified to have all +/// 128 bits set to zero. +/// # References +/// * [Nil UUID in RFC4122](https://tools.ietf.org/html/rfc4122.html#section-4.1.7) +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let uuid = Uuid::nil(); +/// assert_eq!( +/// "00000000-0000-0000-0000-000000000000", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua()] + fn nil() -> LuaReflectValProxy; + +"#, + r#" +/// The 'max UUID' (all ones). +/// The max UUID is a special form of UUID that is specified to have all +/// 128 bits set to one. +/// # References +/// * [Max UUID in Draft RFC: New UUID Formats, Version 4](https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.4) +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let uuid = Uuid::max(); +/// assert_eq!( +/// "ffffffff-ffff-ffff-ffff-ffffffffffff", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua()] + fn max() -> LuaReflectValProxy; + +"#, + r#" +/// Creates a UUID from a 128bit value. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128; +/// let uuid = Uuid::from_u128(v); +/// assert_eq!( +/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua()] + fn from_u128(v: u128) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a UUID from a 128bit value in little-endian order. +/// The entire value will be flipped to convert into big-endian order. +/// This is based on the endianness of the UUID, rather than the target +/// environment so bytes will be flipped on both big and little endian +/// machines. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128; +/// let uuid = Uuid::from_u128_le(v); +/// assert_eq!( +/// "d8d7d6d5-d4d3-d2d1-c2c1-b2b1a4a3a2a1", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua()] + fn from_u128_le(v: u128) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a UUID from two 64bit values. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let hi = 0xa1a2a3a4b1b2c1c2u64; +/// let lo = 0xd1d2d3d4d5d6d7d8u64; +/// let uuid = Uuid::from_u64_pair(hi, lo); +/// assert_eq!( +/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua()] + fn from_u64_pair( + high_bits: u64, + low_bits: u64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a UUID using the supplied bytes. +/// # Examples +/// Basic usage: +/// ``` +/// # fn main() -> Result<(), uuid::Error> { +/// # use uuid::Uuid; +/// let bytes = [ +/// 0xa1, 0xa2, 0xa3, 0xa4, +/// 0xb1, 0xb2, +/// 0xc1, 0xc2, +/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, +/// ]; +/// let uuid = Uuid::from_bytes(bytes); +/// assert_eq!( +/// uuid.hyphenated().to_string(), +/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8" +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua()] + fn from_bytes(bytes: [u8; 16]) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a UUID using the supplied bytes in little endian order. +/// The individual fields encoded in the buffer will be flipped. +/// # Examples +/// Basic usage: +/// ``` +/// # fn main() -> Result<(), uuid::Error> { +/// # use uuid::Uuid; +/// let bytes = [ +/// 0xa1, 0xa2, 0xa3, 0xa4, +/// 0xb1, 0xb2, +/// 0xc1, 0xc2, +/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, +/// ]; +/// let uuid = Uuid::from_bytes_le(bytes); +/// assert_eq!( +/// "a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8", +/// uuid.hyphenated().to_string(), +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua()] + fn from_bytes_le(b: [u8; 16]) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +pub struct Uuid(); +#[derive(Default)] +pub(crate) struct Globals; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "Duration", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Instant", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroI128", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroI16", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroI32", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroI64", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroI8", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroU128", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroU16", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroU32", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroU64", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroU8", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "NonZeroUsize", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "PathBuf", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Quat", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Vec3", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("IVec2", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("IVec3", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("IVec4", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "I64Vec2", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "I64Vec3", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "I64Vec4", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("UVec2", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("UVec3", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("UVec4", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "U64Vec2", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "U64Vec3", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "U64Vec4", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Vec2", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Vec3A", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Vec4", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("BVec2", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("BVec3", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("BVec4", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("DVec2", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("DVec3", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("DVec4", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Mat2", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Mat3", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Mat3A", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Mat4", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("DMat2", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("DMat3", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("DMat4", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "Affine2", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Affine3A", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DAffine2", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DAffine3", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("DQuat", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("BVec3A", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("BVec4A", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "Direction2d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Circle", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "Ellipse", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Plane2d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Segment2d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Triangle2d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Rectangle", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "RegularPolygon", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Capsule2d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Direction3d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Sphere", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "Plane3d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Segment3d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Cuboid", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "Cylinder", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Capsule3d", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Torus", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("IRect", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("Rect", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance("URect", crate::tealr::mlu::UserDataProxy::::new)?; + instances + .add_instance( + "NonZeroIsize", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance("Uuid", crate::tealr::mlu::UserDataProxy::::new)?; + Ok(()) + } +} +fn bevy_reflect_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyReflectScriptingPlugin; +impl bevy::app::Plugin for BevyReflectScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_reflect_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( + "BevyReflectAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + }, + ), + ); + } +} diff --git a/crates/bevy_script_api/src/providers/bevy_time.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs similarity index 50% rename from crates/bevy_script_api/src/providers/bevy_time.rs rename to crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs index 34c0cff2..100f3222 100644 --- a/crates/bevy_script_api/src/providers/bevy_time.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs @@ -4,22 +4,31 @@ #![cfg_attr(rustfmt, rustfmt_skip)] use super::bevy_ecs::*; use super::bevy_reflect::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Fixed", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Fixed; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } @@ -28,16 +37,19 @@ fn index(&self) -> String { pub struct Fixed {} #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Real", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Real; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } @@ -46,36 +58,15 @@ fn index(&self) -> String { pub struct Real {} #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Timer", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Timer; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &timer::Timer) -> bool; - -"#, - r#" -/// Creates a new timer with a given duration. -/// See also [`Timer::from_seconds`](Timer::from_seconds). - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - duration: bevy::utils::Duration, - #[proxy] - mode: bevy::time::prelude::TimerMode, - ) -> bevy::time::prelude::Timer; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -86,12 +77,11 @@ pub struct Real {} /// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); /// ``` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_seconds( duration: f32, - #[proxy] - mode: bevy::time::prelude::TimerMode, - ) -> bevy::time::prelude::Timer; + mode: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -115,8 +105,8 @@ pub struct Real {} /// assert!(timer_repeating.finished()); /// ``` - #[lua(kind = "Method")] - fn finished(&self) -> bool; + #[lua()] + fn finished(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -132,80 +122,16 @@ pub struct Real {} /// assert!(!timer.just_finished()); /// ``` - #[lua(kind = "Method")] - fn just_finished(&self) -> bool; - -"#, - r#" -/// Returns the time elapsed on the timer. Guaranteed to be between 0.0 and `duration`. -/// Will only equal `duration` when the timer is finished and non repeating. -/// See also [`Stopwatch::elapsed`](Stopwatch::elapsed). -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); -/// timer.tick(Duration::from_secs_f32(0.5)); -/// assert_eq!(timer.elapsed(), Duration::from_secs_f32(0.5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn elapsed(&self) -> bevy::utils::Duration; + #[lua()] + fn just_finished(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the time elapsed on the timer as an `f32`. /// See also [`Timer::elapsed`](Timer::elapsed). - #[lua(kind = "Method")] - fn elapsed_secs(&self) -> f32; - -"#, - r#" -/// Sets the elapsed time of the timer without any other considerations. -/// See also [`Stopwatch::set`](Stopwatch::set). -/// # -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); -/// timer.set_elapsed(Duration::from_secs(2)); -/// assert_eq!(timer.elapsed(), Duration::from_secs(2)); -/// // the timer is not finished even if the elapsed time is greater than the duration. -/// assert!(!timer.finished()); -/// ``` - - #[lua(kind = "MutatingMethod")] - fn set_elapsed(&mut self, #[proxy] time: bevy::utils::Duration) -> (); - -"#, - r#" -/// Returns the duration of the timer. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let timer = Timer::new(Duration::from_secs(1), TimerMode::Once); -/// assert_eq!(timer.duration(), Duration::from_secs(1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn duration(&self) -> bevy::utils::Duration; - -"#, - r#" -/// Sets the duration of the timer. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(1.5, TimerMode::Once); -/// timer.set_duration(Duration::from_secs(1)); -/// assert_eq!(timer.duration(), Duration::from_secs(1)); -/// ``` - - #[lua(kind = "MutatingMethod")] - fn set_duration(&mut self, #[proxy] duration: bevy::utils::Duration) -> (); + #[lua()] + fn elapsed_secs(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -217,8 +143,10 @@ pub struct Real {} /// assert_eq!(timer.mode(), TimerMode::Repeating); /// ``` - #[lua(kind = "Method", output(proxy))] - fn mode(&self) -> bevy::time::prelude::TimerMode; + #[lua()] + fn mode( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -231,8 +159,11 @@ pub struct Real {} /// assert_eq!(timer.mode(), TimerMode::Once); /// ``` - #[lua(kind = "MutatingMethod")] - fn set_mode(&mut self, #[proxy] mode: bevy::time::prelude::TimerMode) -> (); + #[lua()] + fn set_mode( + _self: LuaReflectRefMutProxy, + mode: LuaReflectValProxy, + ) -> (); "#, r#" @@ -248,8 +179,8 @@ pub struct Real {} /// assert_eq!(timer.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn pause(&mut self) -> (); + #[lua()] + fn pause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -267,8 +198,8 @@ pub struct Real {} /// assert_eq!(timer.elapsed_secs(), 0.5); /// ``` - #[lua(kind = "MutatingMethod")] - fn unpause(&mut self) -> (); + #[lua()] + fn unpause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -285,8 +216,8 @@ pub struct Real {} /// assert!(!timer.paused()); /// ``` - #[lua(kind = "Method")] - fn paused(&self) -> bool; + #[lua()] + fn paused(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -304,8 +235,8 @@ pub struct Real {} /// assert_eq!(timer.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn reset(&mut self) -> (); + #[lua()] + fn reset(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -319,8 +250,8 @@ pub struct Real {} /// assert_eq!(timer.fraction(), 0.25); /// ``` - #[lua(kind = "Method")] - fn fraction(&self) -> f32; + #[lua()] + fn fraction(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -334,8 +265,8 @@ pub struct Real {} /// assert_eq!(timer.fraction_remaining(), 0.75); /// ``` - #[lua(kind = "Method")] - fn fraction_remaining(&self) -> f32; + #[lua()] + fn fraction_remaining(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -351,23 +282,8 @@ pub struct Real {} /// assert_eq!(Ordering::Equal, result); /// ``` - #[lua(kind = "Method")] - fn remaining_secs(&self) -> f32; - -"#, - r#" -/// Returns the remaining time using Duration -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); -/// timer.tick(Duration::from_secs_f32(0.5)); -/// assert_eq!(timer.remaining(), Duration::from_secs_f32(1.5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn remaining(&self) -> bevy::utils::Duration; + #[lua()] + fn remaining_secs(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -388,18 +304,34 @@ pub struct Real {} /// assert_eq!(timer.times_finished_this_tick(), 0); /// ``` - #[lua(kind = "Method")] - fn times_finished_this_tick(&self) -> u32; + #[lua()] + fn times_finished_this_tick( + _self: LuaReflectRefProxy, + ) -> u32; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } @@ -408,33 +340,39 @@ fn index(&self) -> String { pub struct Timer {} #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::TimerMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &timer::TimerMode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::TimerMode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } @@ -443,16 +381,19 @@ fn index(&self) -> String { pub struct TimerMode {} #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Virtual", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Virtual; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } @@ -461,45 +402,46 @@ fn index(&self) -> String { pub struct Virtual {} #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::Stopwatch", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -/// Create a new unpaused `Stopwatch` with no elapsed time. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// let stopwatch = Stopwatch::new(); -/// assert_eq!(stopwatch.elapsed_secs(), 0.0); -/// assert_eq!(stopwatch.paused(), false); -/// ``` - #[lua(kind = "Function", output(proxy))] - fn new() -> bevy::time::Stopwatch; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Returns the elapsed time since the last [`reset`](Stopwatch::reset) -/// of the stopwatch. + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +/// Create a new unpaused `Stopwatch` with no elapsed time. /// # Examples /// ``` /// # use bevy_time::*; -/// use std::time::Duration; -/// let mut stopwatch = Stopwatch::new(); -/// stopwatch.tick(Duration::from_secs(1)); -/// assert_eq!(stopwatch.elapsed(), Duration::from_secs(1)); +/// let stopwatch = Stopwatch::new(); +/// assert_eq!(stopwatch.elapsed_secs(), 0.0); +/// assert_eq!(stopwatch.paused(), false); /// ``` -/// # See Also -/// [`elapsed_secs`](Stopwatch::elapsed_secs) - if an `f32` value is desirable instead. -/// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if an `f64` is desirable instead. - #[lua(kind = "Method", output(proxy))] - fn elapsed(&self) -> bevy::utils::Duration; + #[lua()] + fn new() -> LuaReflectValProxy; "#, r#" @@ -517,8 +459,8 @@ pub struct Virtual {} /// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. /// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if an `f64` is desirable instead. - #[lua(kind = "Method")] - fn elapsed_secs(&self) -> f32; + #[lua()] + fn elapsed_secs(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -528,23 +470,8 @@ pub struct Virtual {} /// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. /// [`elapsed_secs`](Stopwatch::elapsed_secs) - if an `f32` is desirable instead. - #[lua(kind = "Method")] - fn elapsed_secs_f64(&self) -> f64; - -"#, - r#" -/// Sets the elapsed time of the stopwatch. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut stopwatch = Stopwatch::new(); -/// stopwatch.set_elapsed(Duration::from_secs_f32(1.0)); -/// assert_eq!(stopwatch.elapsed_secs(), 1.0); -/// ``` - - #[lua(kind = "MutatingMethod")] - fn set_elapsed(&mut self, #[proxy] time: bevy::utils::Duration) -> (); + #[lua()] + fn elapsed_secs_f64(_self: LuaReflectRefProxy) -> f64; "#, r#" @@ -561,8 +488,8 @@ pub struct Virtual {} /// assert_eq!(stopwatch.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn pause(&mut self) -> (); + #[lua()] + fn pause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -580,8 +507,8 @@ pub struct Virtual {} /// assert_eq!(stopwatch.elapsed_secs(), 1.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn unpause(&mut self) -> (); + #[lua()] + fn unpause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -597,8 +524,8 @@ pub struct Virtual {} /// assert!(!stopwatch.paused()); /// ``` - #[lua(kind = "Method")] - fn paused(&self) -> bool; + #[lua()] + fn paused(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -613,29 +540,12 @@ pub struct Virtual {} /// assert_eq!(stopwatch.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn reset(&mut self) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::Stopwatch; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &stopwatch::Stopwatch) -> bool; + #[lua()] + fn reset(_self: LuaReflectRefMutProxy) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } @@ -644,42 +554,40 @@ fn index(&self) -> String { pub struct Stopwatch {} #[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<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances - .add_instance( - "Timer", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Timer", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Stopwatch", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; Ok(()) } } -pub struct BevyTimeAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyTimeAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - 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 { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_time_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyTimeScriptingPlugin; +impl bevy::app::Plugin for BevyTimeScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_time_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyTimeAPI", |tw| { tw.document_global_instance::() @@ -687,42 +595,13 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyTimeAPIProvider { .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaStopwatch, - >, - >() + .process_type::>() }, ), - ) - } - 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::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs new file mode 100644 index 00000000..16449985 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs @@ -0,0 +1,359 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use super::bevy_core::*; +use super::bevy_hierarchy::*; +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::transform::components::GlobalTransform", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::ops::Mul::", + composite = "mul", + )] + fn mul( + _self: LuaReflectValProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul::", + composite = "mul", + )] + fn mul( + _self: LuaReflectValProxy, + global_transform: LuaReflectValProxy< + bevy::transform::components::GlobalTransform, + >, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua()] + fn from_xyz( + x: f32, + y: f32, + z: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the transformation as a [`Transform`]. +/// The transform is expected to be non-degenerate and without shearing, or the output +/// will be invalid. + + #[lua()] + fn compute_transform( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns the [`Transform`] `self` would have if it was a child of an entity +/// with the `parent` [`GlobalTransform`]. +/// This is useful if you want to "reparent" an [`Entity`](bevy_ecs::entity::Entity). +/// Say you have an entity `e1` that you want to turn into a child of `e2`, +/// but you want `e1` to keep the same global transform, even after re-parenting. You would use: +/// ``` +/// # use bevy_transform::prelude::{GlobalTransform, Transform}; +/// # use bevy_ecs::prelude::{Entity, Query, Component, Commands}; +/// # use bevy_hierarchy::{prelude::Parent, BuildChildren}; +/// #[derive(Component)] +/// struct ToReparent { +/// new_parent: Entity, +/// } +/// fn reparent_system( +/// mut commands: Commands, +/// mut targets: Query<(&mut Transform, Entity, &GlobalTransform, &ToReparent)>, +/// transforms: Query<&GlobalTransform>, +/// ) { +/// for (mut transform, entity, initial, to_reparent) in targets.iter_mut() { +/// if let Ok(parent_transform) = transforms.get(to_reparent.new_parent) { +/// *transform = initial.reparented_to(parent_transform); +/// commands.entity(entity) +/// .remove::() +/// .set_parent(to_reparent.new_parent); +/// } +/// } +/// } +/// ``` +/// The transform is expected to be non-degenerate and without shearing, or the output +/// will be invalid. + + #[lua()] + fn reparented_to( + _self: LuaReflectRefProxy, + parent: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Multiplies `self` with `transform` component by component, returning the +/// resulting [`GlobalTransform`] + + #[lua()] + fn mul_transform( + _self: LuaReflectRefProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct GlobalTransform(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::transform::components::Transform", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul::", + composite = "mul", + )] + fn mul( + _self: LuaReflectValProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component +/// is used for z-ordering elements: higher `z`-value will be in front of lower +/// `z`-value. + + #[lua()] + fn from_xyz( + x: f32, + y: f32, + z: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Rotates this [`Transform`] around the `X` axis by `angle` (in radians). +/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + + #[lua()] + fn rotate_x( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around the `Y` axis by `angle` (in radians). +/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + + #[lua()] + fn rotate_y( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around the `Z` axis by `angle` (in radians). +/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + + #[lua()] + fn rotate_z( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around its local `X` axis by `angle` (in radians). + + #[lua()] + fn rotate_local_x( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around its local `Y` axis by `angle` (in radians). + + #[lua()] + fn rotate_local_y( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around its local `Z` axis by `angle` (in radians). + + #[lua()] + fn rotate_local_z( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); + +"#, + r#" +/// Multiplies `self` with `transform` component by component, returning the +/// resulting [`Transform`] + + #[lua()] + fn mul_transform( + _self: LuaReflectRefProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Returns `true` if, and only if, translation, rotation and scale all are +/// finite. If any of them contains a `NaN`, positive or negative infinity, +/// this will return `false`. + + #[lua()] + fn is_finite( + _self: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul::", + composite = "mul", + )] + fn mul( + _self: LuaReflectValProxy, + global_transform: LuaReflectValProxy< + bevy::transform::components::GlobalTransform, + >, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Transform { + translation: ReflectReference, + rotation: ReflectReference, + scale: ReflectReference, +} +#[derive(Default)] +pub(crate) struct Globals; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "GlobalTransform", + crate::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Transform", + crate::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +fn bevy_transform_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyTransformScriptingPlugin; +impl bevy::app::Plugin for BevyTransformScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_transform_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( + "BevyTransformAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::>() + }, + ), + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs new file mode 100644 index 00000000..c23f2b0d --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs @@ -0,0 +1,1816 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use super::bevy_input::*; +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, +}; +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::CursorEntered", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct CursorEntered { + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::CursorIcon", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct CursorIcon {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::CursorLeft", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct CursorLeft { + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::CursorMoved", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct CursorMoved { + window: ReflectReference, + position: ReflectReference, + delta: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::FileDragAndDrop", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct FileDragAndDrop {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::Ime", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Ime {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::MonitorSelection", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct MonitorSelection {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::ReceivedCharacter", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ReceivedCharacter { + window: ReflectReference, + char: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::Window", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Setting to true will attempt to maximize the window. +/// Setting to false will attempt to un-maximize the window. + + #[lua()] + fn set_maximized( + _self: LuaReflectRefMutProxy, + maximized: bool, + ) -> (); + +"#, + r#" +/// Setting to true will attempt to minimize the window. +/// Setting to false will attempt to un-minimize the window. + + #[lua()] + fn set_minimized( + _self: LuaReflectRefMutProxy, + minimized: bool, + ) -> (); + +"#, + r#" +/// The window's client area width in logical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua()] + fn width(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// The window's client area height in logical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua()] + fn height(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// The window's client area width in physical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua()] + fn physical_width(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// The window's client area height in physical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua()] + fn physical_height(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// The window's scale factor. +/// Ratio of physical size to logical size, see [`WindowResolution`]. + + #[lua()] + fn scale_factor(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Window { + cursor: bevy::window::Cursor, + present_mode: bevy::window::PresentMode, + mode: bevy::window::WindowMode, + position: bevy::window::prelude::WindowPosition, + resolution: bevy::window::WindowResolution, + title: std::string::String, + name: std::option::Option, + composite_alpha_mode: bevy::window::CompositeAlphaMode, + resize_constraints: bevy::window::prelude::WindowResizeConstraints, + resizable: bool, + enabled_buttons: bevy::window::EnabledButtons, + decorations: bool, + transparent: bool, + focused: bool, + window_level: bevy::window::WindowLevel, + canvas: std::option::Option, + prevent_default_event_handling: bool, + internal: bevy::window::InternalWindowState, + ime_enabled: bool, + ime_position: ReflectReference, + window_theme: ReflectReference, + visible: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::WindowMoved", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowMoved { + window: ReflectReference, + position: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::WindowPosition", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Set the window to a specific monitor. + + #[lua()] + fn center( + _self: LuaReflectRefMutProxy, + monitor: LuaReflectValProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowPosition {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::prelude::WindowResizeConstraints", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Checks if the constraints are valid. +/// Will output warnings if it isn't. + + #[lua()] + fn check_constraints( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowResizeConstraints { + min_width: f32, + min_height: f32, + max_width: f32, + max_height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowResized", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowResized { + window: ReflectReference, + width: f32, + height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowCreated", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowCreated { + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowClosed", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowClosed { + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowCloseRequested", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowCloseRequested { + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowDestroyed", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowDestroyed { + window: ReflectReference, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::RequestRedraw", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct RequestRedraw {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowFocused", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowFocused { + window: ReflectReference, + focused: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowOccluded", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowOccluded { + window: ReflectReference, + occluded: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowScaleFactorChanged", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowScaleFactorChanged { + window: ReflectReference, + scale_factor: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowBackendScaleFactorChanged", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowBackendScaleFactorChanged { + window: ReflectReference, + scale_factor: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowThemeChanged", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowThemeChanged { + window: ReflectReference, + theme: bevy::window::WindowTheme, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::ApplicationLifetime", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct ApplicationLifetime {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::PrimaryWindow", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct PrimaryWindow {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::Cursor", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Cursor { + icon: bevy::window::prelude::CursorIcon, + visible: bool, + grab_mode: bevy::window::CursorGrabMode, + hit_test: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::CursorGrabMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct CursorGrabMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::CompositeAlphaMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct CompositeAlphaMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowResolution", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new [`WindowResolution`]. + + #[lua()] + fn new( + logical_width: f32, + logical_height: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Builder method for adding a scale factor override to the resolution. + + #[lua()] + fn with_scale_factor_override( + _self: LuaReflectValProxy, + scale_factor_override: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// The window's client area width in logical pixels. + + #[lua()] + fn width(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// The window's client area height in logical pixels. + + #[lua()] + fn height(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// The window's client area width in physical pixels. + + #[lua()] + fn physical_width(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// The window's client area height in physical pixels. + + #[lua()] + fn physical_height(_self: LuaReflectRefProxy) -> u32; + +"#, + r#" +/// The ratio of physical pixels to logical pixels. +/// `physical_pixels = logical_pixels * scale_factor` + + #[lua()] + fn scale_factor(_self: LuaReflectRefProxy) -> f32; + +"#, + r#" +/// The window scale factor as reported by the window backend. +/// This value is unaffected by [`WindowResolution::scale_factor_override`]. + + #[lua()] + fn base_scale_factor( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" +/// The scale factor set with [`WindowResolution::set_scale_factor_override`]. +/// This value may be different from the scale factor reported by the window backend. + + #[lua()] + fn scale_factor_override( + _self: LuaReflectRefProxy, + ) -> std::option::Option; + +"#, + r#" +/// Set the window's logical resolution. + + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + width: f32, + height: f32, + ) -> (); + +"#, + r#" +/// Set the window's physical resolution. +/// This will ignore the scale factor setting, so most of the time you should +/// prefer to use [`WindowResolution::set`]. + + #[lua()] + fn set_physical_resolution( + _self: LuaReflectRefMutProxy, + width: u32, + height: u32, + ) -> (); + +"#, + r#" +/// Set the window's scale factor, this may get overridden by the backend. + + #[lua()] + fn set_scale_factor( + _self: LuaReflectRefMutProxy, + scale_factor: f32, + ) -> (); + +"#, + r#" +/// Set the window's scale factor, this will be used over what the backend decides. +/// This can change the logical and physical sizes if the resulting physical +/// size is not within the limits. + + #[lua()] + fn set_scale_factor_override( + _self: LuaReflectRefMutProxy, + scale_factor_override: std::option::Option, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowResolution {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowLevel", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowLevel {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::PresentMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct PresentMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::InternalWindowState", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Consumes the current maximize request, if it exists. This should only be called by window backends. + + #[lua()] + fn take_maximize_request( + _self: LuaReflectRefMutProxy, + ) -> std::option::Option; + +"#, + r#" +/// Consumes the current minimize request, if it exists. This should only be called by window backends. + + #[lua()] + fn take_minimize_request( + _self: LuaReflectRefMutProxy, + ) -> std::option::Option; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct InternalWindowState {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowTheme", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowTheme {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::EnabledButtons", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct EnabledButtons { + minimize: bool, + maximize: bool, + close: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::WindowRef", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct WindowRef {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + remote = "bevy::window::NormalizedWindowRef", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct NormalizedWindowRef(); +#[derive(Default)] +pub(crate) struct Globals; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "WindowResolution", + crate::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +fn bevy_window_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyWindowScriptingPlugin; +impl bevy::app::Plugin for BevyWindowScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_window_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( + "BevyWindowAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + crate::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + }, + ), + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs new file mode 100644 index 00000000..bd8adc3d --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs @@ -0,0 +1,25 @@ +// @generated by cargo bevy-api-gen collect, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +pub(crate) mod bevy_ecs; +pub(crate) mod bevy_transform; +pub(crate) mod bevy_input; +pub(crate) mod bevy_core; +pub(crate) mod bevy_time; +pub(crate) mod bevy_hierarchy; +pub(crate) mod bevy_window; +pub(crate) mod bevy_reflect; +pub struct LuaBevyScriptingPlugin; +impl bevy::app::Plugin for LuaBevyScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + bevy_ecs::BevyEcsScriptingPlugin.build(app); + bevy_transform::BevyTransformScriptingPlugin.build(app); + bevy_input::BevyInputScriptingPlugin.build(app); + bevy_core::BevyCoreScriptingPlugin.build(app); + bevy_time::BevyTimeScriptingPlugin.build(app); + bevy_hierarchy::BevyHierarchyScriptingPlugin.build(app); + bevy_window::BevyWindowScriptingPlugin.build(app); + bevy_reflect::BevyReflectScriptingPlugin.build(app); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs new file mode 100644 index 00000000..cc383a7c --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs @@ -0,0 +1,189 @@ +//! Set of traits used to define how types are turned into and from proxies in Lua. +//! Proxies can either be logical "copies" or owned "direct representations" of the instance, or references to one via the [`bevy_mod_scripting_core::bindings::ReflectReference`] construct. + +use bevy::reflect::{FromReflect, Reflect, TypeRegistry}; +use bevy_mod_scripting_core::{ + bindings::{ + Proxy, ReflectAllocator, ReflectRefMutProxy, ReflectRefProxy, ReflectReference, + ReflectValProxy, Unproxy, ValProxy, WorldAccessGuard, WorldAccessUnit, WorldAccessWrite, + }, + error::{ScriptError, ScriptResult}, +}; +use tealr::{ + mlu::mlua::{Error, FromLua, IntoLua, Lua, Value}, + ToTypename, +}; + +/// Local trait alias for the [`Proxied`] trait. +pub trait LuaProxied { + type Proxy; +} + +/// Convenience for proxying a type into lua via itself without implementing [`Proxy`] on it. +/// Converts to Lua via T's implementation of IntoLua directly +pub struct LuaIdentityProxy(pub Option); + +impl Proxy for LuaIdentityProxy { + type Input<'i> = T; + fn proxy<'i>(value: Self::Input<'i>) -> ScriptResult { + Ok(Self(Some(value))) + } +} + +impl Unproxy for LuaIdentityProxy { + type Output<'o> = T where + Self: 'o; + + fn unproxy<'o>(&'o mut self) -> ScriptResult> { + Ok(self + .0 + .take() + .expect("IdentityProxy was already unproxied before")) + } +} + +impl ToTypename for LuaIdentityProxy { + fn to_typename() -> tealr::Type { + T::to_typename() + } +} + +impl<'a, T: IntoLua<'a>> IntoLua<'a> for LuaIdentityProxy { + fn into_lua(self, lua: &'a Lua) -> tealr::mlu::mlua::prelude::LuaResult> { + self.0.into_lua(lua) + } +} + +impl<'a, T: FromLua<'a>> FromLua<'a> for LuaIdentityProxy { + fn from_lua(value: Value<'a>, lua: &'a Lua) -> Result { + Ok(Self(Some(T::from_lua(value, lua)?))) + } +} + +/// Proxy which uses [`ValProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and that the proxy implements [`From`] for the type. +/// +/// Used for types which are copied into lua rather than references to originals in the world. +/// Use when your type does not implement Reflect or if it's a simple type that can be copied into lua. +pub struct LuaValProxy(pub ValProxy); + +/// Proxy which uses [`ReflectValProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and [`FromReflect`] and that the proxy implements [`AsRef`]. +/// Think of the proxy as just a container for a [`ReflectReference`]. +/// +/// Semantically equivalent to `T`, use it where you would use the `T` type. +pub struct LuaReflectValProxy(pub ReflectValProxy); + +/// Proxy which uses [`ReflectRefProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and [`Reflect`] and that the proxy implements [`AsRef`]. +/// Think of the proxy as just a container for a [`ReflectReference`]. +/// +/// Semantically equivalent to `&T`, use it where you would use the `&T` type. +pub struct LuaReflectRefProxy(pub ReflectRefProxy); + +/// Proxy which uses [`ReflectRefMutProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and [`Reflect`] and that the proxy implements [`AsRef`]. +/// Think of the proxy as just a container for a [`ReflectReference`]. +/// +/// Semantically equivalent to `&mut T`, use it where you would use the `&mut T` type. +pub struct LuaReflectRefMutProxy(pub ReflectRefMutProxy); + +macro_rules! impl_lua_unproxy { + ($ty:ident as $as:ident ($generic:tt) $($bound_var:path : ($($bounds:tt)+),)*) => { + impl <$generic> Unproxy for $ty<$generic> + where + $($bound_var : $($bounds)+),* + { + type Output<'b> = <$as<$generic,$generic::Proxy> as Unproxy>::Output<'b> where Self: 'b; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut bevy::utils::smallvec::SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + self.0.collect_accesses(guard, accesses) + } + + fn unproxy(&mut self) -> ScriptResult> { + self.0.unproxy() + } + + unsafe fn unproxy_with_world<'w,'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + self.0 + .unproxy_with_world(guard, accesses, type_registry, allocator) + } + + fn accesses_len(&self) -> usize { + self.0.accesses_len() + } + } + + impl<'lua, $generic: LuaProxied> FromLua<'lua> for $ty<$generic> + where + $generic::Proxy: FromLua<'lua>, + { + fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result { + let inner: $generic::Proxy = $generic::Proxy::from_lua(value, lua)?; + let inner = $as::<$generic,$generic::Proxy>::new(inner); + Ok(Self(inner)) + } + } + + impl<'lua, $generic: LuaProxied> IntoLua<'lua> for $ty<$generic> + where + $generic::Proxy: IntoLua<'lua>, + { + fn into_lua(self, lua: &'lua Lua) -> tealr::mlu::mlua::prelude::LuaResult> { + self.0.0.into_lua(lua) + } + } + + impl ToTypename for $ty where T::Proxy: ToTypename { + fn to_typename() -> tealr::Type { + T::Proxy::to_typename() + } + } + }; +} + +macro_rules! impl_lua_proxy { + ($ty:ident as $as:ident => $generic:tt : $($bounds:path),* $(| T::Proxy: $($proxy_bounds:tt)*)?) => { + impl<$generic> bevy_mod_scripting_core::bindings::Proxy for $ty<$generic> + where + T::Proxy: $($($proxy_bounds)*)?, + T: $($bounds+)*, + { + type Input<'i>=<$as<$generic, $generic::Proxy> as bevy_mod_scripting_core::bindings::Proxy>::Input<'i>; + fn proxy<'i>(value: Self::Input<'i>) -> ScriptResult { + Ok(Self($as::<$generic,$generic::Proxy>::proxy(value)?)) + } + } + + + }; +} + +impl_lua_proxy!(LuaValProxy as ValProxy => T : LuaProxied | T::Proxy: From); +impl_lua_proxy!(LuaReflectValProxy as ReflectValProxy => T : LuaProxied,Reflect | T::Proxy: From ); + +impl_lua_unproxy!(LuaValProxy as ValProxy (T) + T: (LuaProxied), + T: (for <'l> From<&'l T::Proxy>), +); +impl_lua_unproxy!(LuaReflectValProxy as ReflectValProxy (T) + T: (FromReflect), + T: (LuaProxied), + T::Proxy: (AsRef), +); +impl_lua_unproxy!(LuaReflectRefProxy as ReflectRefProxy (T) + T: (LuaProxied), + T: (Reflect), + T::Proxy: (AsRef), +); +impl_lua_unproxy!(LuaReflectRefMutProxy as ReflectRefMutProxy (T) + T: (LuaProxied), + T: (Reflect), + T::Proxy: (AsRef), +); diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs new file mode 100644 index 00000000..32093342 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -0,0 +1,422 @@ +use std::{any::Any, error::Error}; + +use bevy::{ + ecs::{reflect::AppTypeRegistry, world::Mut}, + reflect::{OffsetAccess, ParsedPath, ReflectFromReflect}, +}; +use bevy_mod_scripting_core::{ + bindings::{ReflectAllocator, ReflectReference, Unproxy, WorldCallbackAccess}, + error::ScriptError, +}; +use tealr::mlu::{ + mlua::{self, FromLua, IntoLua, Lua, MetaMethod, UserData, Value}, + TealData, +}; + +use crate::{impl_userdata_from_lua, ReflectLuaProxied, ReflectLuaValue}; + +use super::{ + proxy::{LuaProxied, LuaValProxy}, + world::GetWorld, +}; + +/// Lua UserData wrapper for [`bevy_mod_scripting_core::bindings::ReflectReference`]. +/// Acts as a lua reflection interface. Any value which is registered in the type registry can be interacted with using this type. +#[derive(Debug, Clone, tealr::mlu::UserData, tealr::ToTypename)] +pub struct LuaReflectReference(pub ReflectReference); + +impl LuaReflectReference { + /// Queries the reflection system for a proxy registration for the underlying type. + /// If found will convert to lua using this proxy + /// If not found will use ::into_lua to convert to lua + pub fn to_lua_proxy(self, lua: &Lua) -> Result, mlua::Error> { + // note we do not need to refer to LuaWorld here, it does not matter what the proxy is, that's pretty neat, + let world = lua.get_world()?; + // TODO: i don't like the pingponging between errors here, need something more ergonomic + let result: Result = + world.with_resource(|world, type_registry: Mut| { + world.with_resource(|world, allocator: Mut| { + let type_registry = type_registry.read(); + // first we need the type id of the pointed to object to figure out how to work with it + let type_id = + self.0 + .with_reflect(world, &type_registry, Some(&allocator), |r| r.type_id()); + if let Some(type_data) = type_registry.get_type_data::(type_id) + { + self.0 + .with_reflect(world, &type_registry, Some(&allocator), |r| { + Ok((type_data.into_value)(r, lua)?) + }) + } else if let Some(type_data) = + type_registry.get_type_data::(type_id) + { + Ok((type_data.into_proxy)(self.0.clone(), lua)?) + } else { + Ok(self.clone().into_lua(lua)?) + } + }) + }); + result.map_err(mlua::Error::external) + } + + pub fn set_with_lua_proxy(&self, lua: &Lua, value: Value) -> Result<(), mlua::Error> { + let world = lua.get_world()?; + let result: Result<(), ScriptError> = + world.with_resource(|world, type_registry: Mut| { + world.with_resource(|world, allocator: Mut| { + let type_registry = type_registry.read(); + let type_id = + self.0 + .with_reflect(world, &type_registry, Some(&allocator), |r| r.type_id()); + + if let Some(type_data) = type_registry.get_type_data::(type_id) + { + self.0 + .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { + Ok((type_data.set_value)(r, value, lua)?) + }) + } else if let Some(type_data) = + type_registry.get_type_data::(type_id) + { + let other = (type_data.from_proxy)(value, lua)?; + + // first we need to get a copy of the other value + let other = other + .with_reflect(world, &type_registry, Some(&allocator), |r| { + type_registry + .get_type_data::(r.type_id()) + .and_then(|from_reflect_td| from_reflect_td.from_reflect(r)) + }) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Failed to call ReflectFromReflect for type id: {:?}", + type_registry.get_type_info(type_id).map(|t| t.type_path()) + )) + })?; + + // now we can set it + self.0 + .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { + r.set(other).map_err(|e| { + ScriptError::new_runtime_error(format!( + "Invalid assignment `{:?}` = `{:?}`. Wrong type.", + self.0.clone(), + e, + )) + }) + })?; + Ok(()) + } else { + Err(ScriptError::new_runtime_error(format!( + "Invalid assignment `{:?}` = `{:?}`. Wrong type.", + self.0.clone(), + value, + ))) + } + }) + }); + + result.map_err(mlua::Error::external) + } + + /// Adjusts all the numeric accesses in the path from 1-indexed to 0-indexed + pub fn to_host_index(path: &mut ParsedPath) { + path.0.iter_mut().for_each(|a| match a.access { + bevy::reflect::Access::FieldIndex(ref mut i) => *i -= 1, + bevy::reflect::Access::TupleIndex(ref mut i) => *i -= 1, + bevy::reflect::Access::ListIndex(ref mut i) => *i -= 1, + _ => {} + }); + } + + /// Adjusts all the numeric accesses in the path from 0-indexed to 1-indexed + pub fn from_host_index(path: &mut ParsedPath) { + path.0.iter_mut().for_each(|a| match a.access { + bevy::reflect::Access::FieldIndex(ref mut i) => *i += 1, + bevy::reflect::Access::TupleIndex(ref mut i) => *i += 1, + bevy::reflect::Access::ListIndex(ref mut i) => *i += 1, + _ => {} + }); + } + + pub fn parse_value_index(value: Value) -> Result { + if let Some(num) = value.as_usize() { + Ok(vec![OffsetAccess { + access: bevy::reflect::Access::ListIndex(num), + offset: Some(1), + }] + .into()) + } else if let Some(key) = value.as_str() { + if let Some(tuple_struct_index) = key.strip_prefix("_") { + if let Ok(index) = tuple_struct_index.parse::() { + return Ok(vec![OffsetAccess { + access: bevy::reflect::Access::TupleIndex(index), + offset: Some(1), + }] + .into()); + } + } + + ParsedPath::parse(key).map_err(|e| mlua::Error::external(e.to_string())) + } else { + Err(mlua::Error::external("Invalid index")) + } + } +} + +impl_userdata_from_lua!(LuaReflectReference); + +impl LuaProxied for ReflectReference { + type Proxy = LuaReflectReference; +} + +impl TealData for LuaReflectReference { + fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(m: &mut T) { + m.add_meta_function( + MetaMethod::Index, + |l, (mut self_, key): (LuaReflectReference, Value)| { + // catchall, parse the path + let mut elem = Self::parse_value_index(key)?; + Self::to_host_index(&mut elem); + self_.0.index_path(elem); + self_.to_lua_proxy(l) + }, + ); + m.add_meta_function( + MetaMethod::NewIndex, + |l, (mut self_, key, value): (LuaReflectReference, Value, Value)| { + let mut elem = Self::parse_value_index(key)?; + Self::to_host_index(&mut elem); + self_.0.index_path(elem); + self_.set_with_lua_proxy(l, value) + }, + ); + } +} + +#[cfg(test)] +mod test { + + use bevy::{ + app::App, + ecs::{reflect::AppTypeRegistry, world::World}, + reflect::{FromReflect, OffsetAccess, Reflect}, + }; + use bevy_mod_scripting_core::{ + bindings::ReflectAllocator, + bindings::{ReflectBase, ReflectBaseType, WorldAccessGuard, WorldCallbackAccess}, + }; + use bevy_mod_scripting_derive::LuaProxy; + + use crate::{bindings::world::LuaWorld, RegisterLua}; + + use super::*; + + #[derive(Reflect)] + struct TestStruct { + value: usize, + proxy: TestProxied, + proxies: Vec, + } + + #[derive(Reflect)] + struct TestTupleStruct(usize, TestProxied, Vec); + + #[derive(Reflect)] + enum TestTupleEnum { + Value(usize), + Proxy(TestProxied), + Proxies(Vec), + } + + #[derive(Reflect, LuaProxy)] + #[proxy(bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate")] + #[reflect(LuaProxied)] + pub struct TestProxied; + + impl PartialEq for LuaTestProxied { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } + } + + /// asserts that setting then indexing into a LuaReflectReference of type T with the given expression returns the expected value. + /// Provides `t and `world` globals, with t being the LuaReflectReference to the provided value. + fn assert_lua_set_get_returns< + T: Reflect, + F: Fn(ReflectReference) -> O, + O: for<'l> FromLua<'l> + for<'l> IntoLua<'l> + PartialEq + std::fmt::Debug, + >( + world: Option, + val: T, + expr: &'static str, + expected: F, + ) { + let mut world = world.unwrap_or_default(); + let lua = Lua::new(); + let mut allocator = ReflectAllocator::default(); + let reflect_ref = LuaReflectReference(ReflectReference::new_allocated(val, &mut allocator)); + world.insert_resource(allocator); + + WorldCallbackAccess::with_callback_access(&mut world, |access| { + let globals = lua.globals(); + globals.set("test", reflect_ref.clone()).unwrap(); + globals.set("world", LuaWorld(access.clone())).unwrap(); + globals + .set("expected", expected(reflect_ref.0.clone())) + .unwrap(); + + let lua_code = format!( + r#" + {expr} = expected + return {expr} + "# + ); + let result = lua + .load(&lua_code) + .into_function() + .unwrap_or_else(|e| panic!("Could not load lua code into function: `{e}`")) + .call(()) + .unwrap_or_else(|e| { + panic!("Could not convert expression value to expected type: `{e}`") + }); + let result: O = result; + assert_eq!(result, expected(reflect_ref.0)); + }); + } + + #[test] + fn test_index_lua_value() { + // so we have the registry and can just do this + let mut app = App::new(); + app.register_lua_value::(); + + assert_lua_set_get_returns( + Some(app.world), + TestStruct { + value: 123, + proxy: TestProxied, + proxies: vec![], + }, + "test.value", + |_| 123usize, + ); + + let mut app = App::new(); + app.register_lua_value::(); + + assert_lua_set_get_returns( + Some(app.world), + TestTupleStruct(123, TestProxied, vec![]), + "test._1", + |_| 123usize, + ); + + let mut app = App::new(); + app.register_lua_value::(); + + assert_lua_set_get_returns( + Some(app.world), + TestTupleEnum::Value(123usize), + "test._1", + |_| 123usize, + ); + } + + #[test] + fn test_index_lua_proxy() { + // so we have the registry and can just do this + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + Some(app.world), + TestStruct { + value: 123, + proxy: TestProxied, + proxies: vec![], + }, + "test.proxy", + |mut r| { + r.index_path(ParsedPath::parse_static("proxy").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + Some(app.world), + TestTupleStruct(123, TestProxied, vec![]), + "test._2", + |mut r| { + r.index_path(ParsedPath::parse_static(".1").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + Some(app.world), + TestTupleEnum::Proxy(TestProxied), + "test._1", + |mut r| { + r.index_path(ParsedPath::parse_static(".0").unwrap()); + LuaTestProxied(r) + }, + ); + } + + #[test] + fn test_index_lua_proxy_vec() { + // so we have the registry and can just do this + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + Some(app.world), + TestStruct { + value: 123, + proxy: TestProxied, + proxies: vec![TestProxied], + }, + "test.proxies[1]", + |mut r| { + r.index_path(ParsedPath::parse_static("proxies").unwrap()); + r.index_path(ParsedPath::parse_static("[0]").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + Some(app.world), + TestTupleStruct(123, TestProxied, vec![TestProxied]), + "test._3[1]", + |mut r| { + r.index_path(ParsedPath::parse_static(".2").unwrap()); + r.index_path(ParsedPath::parse_static("[0]").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + Some(app.world), + TestTupleEnum::Proxies(vec![TestProxied]), + "test._1[1]", + |mut r| { + r.index_path(ParsedPath::parse_static(".0").unwrap()); + r.index_path(ParsedPath::parse_static("[0]").unwrap()); + LuaTestProxied(r) + }, + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs new file mode 100644 index 00000000..9d6e8763 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs @@ -0,0 +1,39 @@ +use tealr::{ + mlu::{mlua::IntoLua, TealData}, + ToTypename, +}; + +pub struct LuaResult(Result); + +impl TealData for LuaResult +where + T: ToTypename + for<'l> IntoLua<'l>, + E: ToTypename + for<'l> IntoLua<'l>, +{ + fn add_methods<'lua, M: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_method("is_ok", |_, this, _: ()| Ok(this.0.is_ok())); + methods.add_method("is_err", |_, this, _: ()| Ok(this.0.is_err())); + methods.add_function("unwrap", |_, this: LuaResult| match this.0 { + Ok(value) => Ok(value), + Err(_) => Err(tealr::mlu::mlua::Error::RuntimeError( + "called `LuaResult::unwrap()` on an `Err` value".to_string(), + )), + }); + methods.add_method("unwrap_err", |_, this, _: ()| match &this.0 { + Ok(_) => Err(tealr::mlu::mlua::Error::RuntimeError( + "called `LuaResult::unwrap_err()` on an `Ok` value".to_string(), + )), + Err(value) => Ok(value), + }); + } + + fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} +} + +impl ToTypename for LuaResult { + fn to_typename() -> tealr::Type { + let t = std::any::type_name::(); + let e = std::any::type_name::(); + tealr::Type::new_single(format!("LuaResult<{t},{e}>"), tealr::KindOfType::External) + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs new file mode 100644 index 00000000..51d00197 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs @@ -0,0 +1,21 @@ +use std::sync::Arc; + +use bevy::reflect::TypeRegistration; +use bevy_mod_scripting_core::bindings::ScriptTypeRegistration; +use tealr::mlu::TealData; + +use crate::impl_userdata_from_lua; + +/// Caches information about type data +#[derive(Clone, tealr::mlu::UserData, tealr::ToTypename)] +pub struct LuaTypeRegistration(pub ScriptTypeRegistration); + +impl_userdata_from_lua!(LuaTypeRegistration); + +impl TealData for LuaTypeRegistration {} + +impl From for LuaTypeRegistration { + fn from(value: ScriptTypeRegistration) -> Self { + Self(value) + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs new file mode 100644 index 00000000..ace651c9 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -0,0 +1,147 @@ +use std::sync::Arc; + +use bevy::ecs::{reflect::AppTypeRegistry, world::Mut}; +use bevy_mod_scripting_core::{ + bindings::{Unproxy, WorldAccessGuard, WorldCallbackAccess}, + error::ScriptError, +}; +use bevy_mod_scripting_derive::LuaProxy; +use tealr::{ + mlu::{ + mlua::{self, FromLua}, + FromToLua, TealData, + }, + ToTypename, Type, +}; + +use crate::{impl_userdata_from_lua, impl_userdata_with_tealdata}; + +use super::{ + providers::bevy_ecs::LuaEntity, + proxy::{LuaIdentityProxy, LuaProxied, LuaValProxy}, + type_registration::LuaTypeRegistration, +}; + +/// Lua UserData wrapper for [`bevy::ecs::world::World`] +#[derive(LuaProxy)] +#[proxy( + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + get_world_callback_access_fn = "self::LuaWorld::world_callback_access", + proxy_as_type = "self::LuaWorld", + remote = "bevy_mod_scripting_core::bindings::WorldAccessGuard<'_>", + functions [ + r#" + #[lua()] + fn add_default_component(&self, entity: LuaEntity, registration: LuaTypeRegistration) -> Result, ScriptError>; + "#, + // r#" + // #[lua()] + // fn get_type_by_name(&self, type_name: String) -> Result; + // "#, + ] +)] +pub struct LuaWorld(WorldCallbackAccess); + +impl LuaWorld { + pub fn world_callback_access(self) -> WorldCallbackAccess { + self.0.clone() + } +} + +impl ToTypename for LuaWorld { + fn to_typename() -> Type { + Type::Userdata + } +} + +// impl_userdata_from_lua!(LuaWorld); + +// impl LuaProxied for WorldCallbackAccess { +// type Proxy = LuaWorld; +// } + +// impl From<&LuaWorld> for WorldCallbackAccess { +// fn from(value: &LuaWorld) -> Self { +// value.0.clone() +// } +// } + +// impl TealData for LuaWorld { +// fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut T) { +// methods.add_method("get_type_by_name", |_, world, type_name: String| { +// Ok(world +// .0 +// .get_type_by_name(type_name.as_str()) +// .map(Into::::into)) +// }); + +// methods.add_method( +// "add_default_component", +// |_, world, (entity, registration): (LuaEntity, LuaTypeRegistration)| { +// let entity = entity.0.with_reflect(world, type_registry, allocator, f) +// Ok(world +// .0 +// .add_default_component(entity.0.with, registration.0.clone())) +// }, +// ) +// } +// } + +pub trait GetWorld { + fn get_world(&self) -> Result>, mlua::Error>; +} + +impl GetWorld for mlua::Lua { + fn get_world(&self) -> Result>, mlua::Error> { + self.globals() + .get::<_, LuaValProxy>("world")? + .unproxy() + .and_then(|guard| { + guard + .read() + .ok_or_else(|| ScriptError::new_reflection_error("Stale world access")) + }) + .map_err(mlua::Error::external) + } +} + +#[cfg(test)] +mod test { + use std::sync::Arc; + + use bevy::ecs::world::World; + use bevy_mod_scripting_core::{ + bindings::WorldAccessGuard, + bindings::{Unproxy, ValProxy}, + }; + use tealr::mlu::mlua::Lua; + + use super::*; + use crate::bindings::proxy::LuaValProxy; + use tealr::mlu::mlua::IntoLua; + + #[test] + fn test_world_from_to_lua() { + let mut world = World::new(); + let world_access_guard = Arc::new(WorldAccessGuard::new(&mut world)); + let callback_access = unsafe { + bevy_mod_scripting_core::bindings::WorldCallbackAccess::new(Arc::downgrade( + &world_access_guard, + )) + }; + let proxy = LuaValProxy::( + ValProxy::new(LuaWorld(callback_access)), + ); + + let lua = Lua::new(); + let lua_val = proxy.into_lua(&lua).unwrap(); + let mut val = + LuaValProxy::::from_lua( + lua_val, &lua, + ) + .unwrap(); + + let _val = val.unproxy().unwrap(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/docs.rs b/crates/languages/bevy_mod_scripting_lua/src/docs.rs index bc0249e7..78504780 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/docs.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/docs.rs @@ -48,14 +48,14 @@ struct Fragment { builder: TypeWalkerBuilder, } -pub struct LuaDocFragment { +pub struct LuaDocumentationFragment { name: &'static str, walker: Vec, } /// A piece of lua documentation, /// Each piece is combined into one large documentation page, and also a single teal declaration file if the `teal` feature is enabled -impl LuaDocFragment { +impl LuaDocumentationFragment { pub fn new(name: &'static str, f: TypeWalkerBuilder) -> Self { Self { name, @@ -64,7 +64,7 @@ impl LuaDocFragment { } } -impl DocFragment for LuaDocFragment { +impl DocumentationFragment for LuaDocumentationFragment { fn name(&self) -> &'static str { self.name } @@ -74,7 +74,7 @@ impl DocFragment for LuaDocFragment { self } - fn gen_docs(self) -> Result<(), ScriptError> { + fn gen_docs(self) -> Result<(), Box> { let script_asset_path = &FileAssetReader::get_base_path() .join("assets") .join("scripts"); @@ -102,71 +102,47 @@ impl DocFragment for LuaDocFragment { }); // generate json file - let json = serde_json::to_string_pretty(&tw) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; - - // temporary fix for incompatibility in json formats - // json.remove(json.len() - 1); - // json.push_str(",\n\"tealr_version_used\": \"0.9.0-alpha3\",\n\"extra_page\": []\n}"); + let json = serde_json::to_string_pretty(&tw)?; let json_path = script_doc_dir.join(format!("{}.json", docs_name)); - File::create(json_path) - .and_then(|mut file| { - file.write_all(json.as_bytes())?; - file.flush() - }) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; - + (File::create(json_path).and_then(|mut file| { + file.write_all(json.as_bytes())?; + file.flush() + }))?; // generate doc config files if they don't exist if !script_doc_dir.join("tealr_doc_gen_config.json").exists() { let config_path = script_doc_dir.join("tealr_doc_gen_config.json"); - File::create(config_path) - .and_then(|mut file| file.write_all(DEFAULT_DOC_CONFIG(&docs_name).as_bytes())) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; + (File::create(config_path) + .and_then(|mut file| file.write_all(DEFAULT_DOC_CONFIG(&docs_name).as_bytes())))? } // generate docs - Command::new("tealr_doc_gen") + (Command::new("tealr_doc_gen") .current_dir(script_doc_dir) .args(["run"]) - .status() - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; + .status())?; #[cfg(feature = "teal")] { // now manage the definition (d.tl) file let definition_directory = script_asset_path.join("types"); - fs::create_dir_all(&definition_directory).map_err(|e| { - ScriptError::DocGenError(format!( - "Could not create `{}` directories: {e}", - &definition_directory.display() - )) - })?; + (fs::create_dir_all(&definition_directory))?; let definition_file_path = script_doc_dir .join(&docs_name) .join("definitions") .join(docs_name + ".d.tl"); let output_definition_file_path = script_asset_path.join("types").join("types.d.tl"); - fs::copy(&definition_file_path, &output_definition_file_path).map_err(|e| { - ScriptError::DocGenError(format!( - "Could not copy definition file from `{}` to `{}`: {e}", - definition_file_path.display(), - output_definition_file_path.display() - )) - })?; + (fs::copy(&definition_file_path, &output_definition_file_path))?; // finally create a tlconfig.lua file if doesn't exist // we do this to avoid problems with varying teal configurations // keep em settings consistent everywhere let tl_config_path = script_asset_path.join("tlconfig.lua"); if !tl_config_path.exists() { - let mut tl_file = File::create(tl_config_path) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; - tl_file - .write_all(DEFAULT_TEAL_CONFIG.as_bytes()) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; + let mut tl_file = (File::create(tl_config_path))?; + (tl_file.write_all(DEFAULT_TEAL_CONFIG.as_bytes()))?; } } Ok(()) diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index d356fade..7a5dc299 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -1,197 +1,255 @@ -use crate::{ - assets::{LuaFile, LuaLoader}, - docs::LuaDocFragment, -}; -use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; -use bevy_mod_scripting_core::{prelude::*, systems::*, world::WorldPointerGuard}; - -use std::fmt; -use std::marker::PhantomData; -use std::sync::Mutex; -use tealr::mlu::mlua::{prelude::*, Function}; - pub mod assets; pub mod docs; pub mod util; +use bevy::{ + app::{App, Plugin}, + ecs::{entity::Entity, world::World}, + reflect::{FromType, GetTypeRegistration, Reflect, TypePath}, +}; +use bevy_mod_scripting_core::{ + bindings::{ReflectReference, WorldCallbackAccess}, + context::{ContextBuilder, ContextInitializer, ContextPreHandlingInitializer}, + error::ScriptError, + event::CallbackLabel, + handler::Args, + script::ScriptId, + ScriptingPlugin, +}; +use bindings::{proxy::LuaProxied, world::LuaWorld}; pub use tealr; +pub mod bindings; +use tealr::mlu::mlua::{FromLua, Function, IntoLua, IntoLuaMulti, Lua, Value}; + pub mod prelude { - pub use crate::{ - assets::{LuaFile, LuaLoader}, - docs::{LuaDocFragment, TypeWalkerBuilder}, - tealr::{ - self, - mlu::{ - mlua::{self, prelude::*, Value}, - TealData, - }, + pub use crate::tealr::{ + self, + mlu::{ + mlua::{self, prelude::*, Value}, + TealData, }, - LuaEvent, LuaScriptHost, }; } -pub trait LuaArg: for<'lua> IntoLuaMulti<'lua> + Clone + Sync + Send + 'static {} - -impl IntoLuaMulti<'lua> + Clone + Sync + Send + 'static> LuaArg for T {} +pub trait LuaEventArg: Args + for<'l> IntoLuaMulti<'l> {} +impl IntoLuaMulti<'l>> LuaEventArg for T {} -#[derive(Clone, Event)] -/// A Lua Hook. The result of creating this event will be -/// a call to the lua script with the hook_name and the given arguments -pub struct LuaEvent { - pub hook_name: String, - pub args: A, - pub recipients: Recipients, +pub struct LuaScriptingPlugin IntoLuaMulti<'l>> { + pub scripting_plugin: ScriptingPlugin, } -impl fmt::Debug for LuaEvent { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("LuaEvent") - .field("hook_name", &self.hook_name) - .field("recipients", &self.recipients) - .finish() +impl Default for LuaScriptingPlugin { + fn default() -> Self { + LuaScriptingPlugin { + scripting_plugin: ScriptingPlugin { + context_assigner: None, + runtime_builder: None, + callback_handler: Some(lua_handler::), + context_builder: Some(ContextBuilder:: { + load: lua_context_load, + reload: lua_context_reload, + }), + }, + } } } -impl ScriptEvent for LuaEvent { - fn recipients(&self) -> &crate::Recipients { - &self.recipients +impl Plugin for LuaScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + self.scripting_plugin.build(app); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); } } -#[derive(Resource)] -/// Lua script host, enables Lua scripting. -pub struct LuaScriptHost { - _ph: PhantomData, +pub fn lua_context_load( + script_id: &ScriptId, + content: &[u8], + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + _: &mut (), +) -> Result { + #[cfg(feature = "unsafe_lua_modules")] + let context = unsafe { Lua::unsafe_new() }; + #[cfg(not(feature = "unsafe_lua_modules"))] + let mut context = Lua::new(); + + with_world(world, &mut context, |context| { + initializers + .iter() + .try_for_each(|init| init(script_id, context))?; + + pre_handling_initializers + .iter() + .try_for_each(|init| init(script_id, Entity::from_raw(0), context))?; + + context.load(content).exec()?; + Ok(()) + })?; + + Ok(context) } -impl Default for LuaScriptHost { - fn default() -> Self { - Self { - _ph: Default::default(), - } - } +pub fn lua_context_reload( + script: &ScriptId, + content: &[u8], + old_ctxt: &mut Lua, + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + _: &mut (), +) -> Result<(), ScriptError> { + *old_ctxt = lua_context_load( + script, + content, + initializers, + pre_handling_initializers, + world, + &mut (), + )?; + Ok(()) } -impl ScriptHost for LuaScriptHost { - type ScriptContext = Mutex; - type APITarget = Mutex; - type ScriptEvent = LuaEvent; - type ScriptAsset = LuaFile; - type DocTarget = LuaDocFragment; - - fn register_with_app_in_set(app: &mut App, schedule: impl ScheduleLabel, set: impl SystemSet) { - app.add_priority_event::() - .init_asset::() - .init_asset_loader::() - .init_resource::>() - .init_resource::>() - .init_resource::>() - .register_type::>() - .register_type::>() - .register_type::>() - // handle script insertions removal first - // then update their contexts later on script asset changes - .add_systems( - schedule, - ( - script_add_synchronizer::, - script_remove_synchronizer::, - script_hot_reload_handler::, - ) - .chain() - .in_set(set), - ); - } +#[allow(clippy::too_many_arguments)] +pub fn lua_handler IntoLuaMulti<'l>>( + args: A, + entity: bevy::ecs::entity::Entity, + script_id: &ScriptId, + callback_label: &CallbackLabel, + context: &mut Lua, + pre_handling_initializers: &[ContextPreHandlingInitializer], + _: &mut (), + world: &mut bevy::ecs::world::World, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + with_world(world, context, |context| { + pre_handling_initializers + .iter() + .try_for_each(|init| init(script_id, entity, context))?; + + let handler: Function = match context.globals().raw_get(callback_label.as_ref()) { + Ok(handler) => handler, + // not subscribed to this event type + Err(_) => return Ok(()), + }; + + handler.call::<_, ()>(args)?; + Ok(()) + }) +} + +/// Safely scopes world access for a lua context to the given closure's scope +pub fn with_world Result<(), ScriptError>>( + world: &mut World, + context: &mut Lua, + f: F, +) -> Result<(), ScriptError> { + WorldCallbackAccess::with_callback_access(world, |guard| { + context.globals().set("world", LuaWorld(guard.clone()))?; + // TODO set entity + script id as well + f(context) + }) +} - fn load_script( +/// Registers a lua proxy object via the reflection system +pub trait RegisterLua { + fn register_lua_proxy( &mut self, - script: &[u8], - script_data: &ScriptData, - providers: &mut APIProviders, - ) -> Result { - #[cfg(feature = "unsafe_lua_modules")] - let lua = unsafe { Lua::unsafe_new() }; - #[cfg(not(feature = "unsafe_lua_modules"))] - let lua = Lua::new(); - - // init lua api before loading script - let mut lua = Mutex::new(lua); - providers.attach_all(&mut lua)?; - - lua.get_mut() - .map_err(|e| ScriptError::FailedToLoad { - script: script_data.name.to_owned(), - msg: e.to_string(), - })? - .load(script) - .set_name(script_data.name) - .exec() - .map_err(|e| ScriptError::FailedToLoad { - script: script_data.name.to_owned(), - msg: e.to_string(), - })?; - - Ok(lua) - } + ) -> &mut Self + where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef; - fn setup_script( + fn register_lua_value( &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError> { - providers.setup_all(script_data, ctx) + ) -> &mut Self + where + T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>; +} + +impl RegisterLua for App { + fn register_lua_proxy( + &mut self, + ) -> &mut Self + where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef, + { + self.register_type::(); + self.register_type_data::() } - fn handle_events<'a>( + fn register_lua_value( &mut self, - world: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ) { - // safety: - // - we have &mut World access - // - we do not use the original reference again anywhere in this function - let world = unsafe { WorldPointerGuard::new(world) }; - - ctxs.for_each(|(script_data, ctx)| { - providers - .setup_runtime_all(world.clone(), &script_data, ctx) - .expect("Could not setup script runtime"); - - let ctx = ctx.get_mut().expect("Poison error in context"); - - // event order is preserved, but scripts can't rely on any temporal - // guarantees when it comes to other scripts callbacks, - // at least for now. - let globals = ctx.globals(); - for event in events { - // check if this script should handle this event - if !event.recipients().is_recipient(&script_data) { - continue; - } - - let f: Function = match globals.raw_get(event.hook_name.clone()) { - Ok(f) => f, - Err(_) => continue, // not subscribed to this event - }; - - if let Err(error) = f.call::<_, ()>(event.args.clone()) { - let mut world = world.write(); - let mut state: CachedScriptState = world.remove_resource().unwrap(); - - let (_, mut error_wrt, _) = state.event_state.get_mut(&mut world); - - let error = ScriptError::RuntimeError { - script: script_data.name.to_owned(), - msg: error.to_string(), - }; - - error!("{}", error); - error_wrt.send(ScriptErrorEvent { error }); - world.insert_resource(state); - } - } - }); + ) -> &mut Self + where + T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + { + self.register_type::(); + self.register_type_data::() + } +} + +/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented in lua via proxies which store +/// a reference to the actual value. +/// This is used for types which are represented in lua with pass by reference semantics +#[derive(Clone)] +pub struct ReflectLuaProxied { + pub into_proxy: + for<'l> fn(ReflectReference, &'l Lua) -> Result, tealr::mlu::mlua::Error>, + pub from_proxy: + for<'l> fn(Value<'l>, &'l Lua) -> Result, +} + +impl FromType for ReflectLuaProxied +where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef, +{ + fn from_type() -> Self { + Self { + into_proxy: |p, l| T::Proxy::from(p).into_lua(l), + from_proxy: |v, l| T::Proxy::from_lua(v, l).map(|p| p.as_ref().clone()), + } + } +} + +/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented directly in lua with +/// pass by value semantics, These need to implement [`Clone`] +#[derive(Clone)] +pub struct ReflectLuaValue { + pub into_value: for<'l> fn(&dyn Reflect, &'l Lua) -> Result, tealr::mlu::mlua::Error>, + pub set_value: + for<'l> fn(&mut dyn Reflect, Value<'l>, &'l Lua) -> Result<(), tealr::mlu::mlua::Error>, + pub from_value: + for<'l> fn(Value<'l>, &'l Lua) -> Result, tealr::mlu::mlua::Error>, +} + +impl IntoLua<'l> + for<'l> FromLua<'l>> FromType + for ReflectLuaValue +{ + fn from_type() -> Self { + Self { + into_value: |v, l| v.downcast_ref::().unwrap().clone().into_lua(l), + set_value: |t, v, l| { + let mut t = t.downcast_mut::().unwrap(); + *t = T::from_lua(v, l)?; + Ok(()) + }, + from_value: |v, l| T::from_lua(v, l).map(|v| Box::new(v) as Box), + } } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/util.rs b/crates/languages/bevy_mod_scripting_lua/src/util.rs index bbf7bb52..be5faab0 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/util.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/util.rs @@ -153,3 +153,48 @@ macro_rules! __cfg_feature_any_lua52_lua53_lua54_luajit52 { macro_rules! __cfg_feature_any_lua52_lua53_lua54_luajit52 { ( $( $tok:tt )* ) => {}; } + +#[macro_export] +macro_rules! impl_userdata_from_lua { + ($ty:ident) => { + impl<'lua> ::tealr::mlu::mlua::FromLua<'lua> for $ty { + fn from_lua( + value: ::tealr::mlu::mlua::Value<'lua>, + _lua: &::tealr::mlu::mlua::Lua, + ) -> Result { + match value { + tealr::mlu::mlua::Value::UserData(ud) => Ok(ud.borrow::()?.clone()), + _ => { + return Err(::tealr::mlu::mlua::Error::FromLuaConversionError { + from: value.type_name(), + to: stringify!($ty), + message: None, + }) + } + } + } + } + }; +} + +#[macro_export] +macro_rules! impl_userdata_with_tealdata { + ($ty:ident) => { + impl ::tealr::mlu::mlua::UserData for $ty + where + Self: ::tealr::mlu::TealData, + { + fn add_methods<'lua, T: ::tealr::mlu::mlua::UserDataMethods<'lua, Self>>( + methods: &mut T, + ) { + let mut wrapper = tealr::mlu::UserDataWrapper::from_user_data_methods(methods); + ::add_methods(&mut wrapper); + } + + fn add_fields<'lua, T: ::tealr::mlu::mlua::UserDataFields<'lua, Self>>(fields: &mut T) { + let mut wrapper = tealr::mlu::UserDataWrapper::from_user_data_fields(fields); + ::add_fields(&mut wrapper); + } + } + }; +} diff --git a/crates/languages/bevy_mod_scripting_lua_derive/Cargo.toml b/crates/languages/bevy_mod_scripting_lua_derive/Cargo.toml deleted file mode 100644 index 56104dd0..00000000 --- a/crates/languages/bevy_mod_scripting_lua_derive/Cargo.toml +++ /dev/null @@ -1,38 +0,0 @@ -[package] -name = "bevy_mod_scripting_lua_derive" -version = "0.6.0" -authors = ["Maksymilian Mozolewski "] -edition = "2021" -license = "MIT OR Apache-2.0" -description = "Necessary functionality for Lua support with bevy_mod_scripting" -repository = "https://github.com/makspll/bevy_mod_scripting" -homepage = "https://github.com/makspll/bevy_mod_scripting" -keywords = ["bevy", "gamedev", "scripting", "rhai"] -categories = ["game-development"] -readme = "readme.md" - -[package.metadata.release] -pre-release-replacements = [ - { file = "Cargo.toml", search = '^version\s*=\s*.*$', replace = "version = \"{{version}}\"", exactly = 1 }, - { file = "Cargo.toml", search = '^(?Pbevy_mod_scripting_common\s*=.*)version\s*=\s*".*"(?P.*)$', replace = "${h}version = \"{{version}}\"${t}", exactly = 1 }, -] - -[lib] -name = "bevy_mod_scripting_lua_derive" -path = "src/lib.rs" -proc-macro = true - -[dependencies] -bevy_mod_scripting_common = { path = "../../bevy_mod_scripting_common", version = "0.6.0" } -paste = "1.0.7" -darling = "0.20.3" -syn = { version = "2.0.38", features = ["full", "fold", "extra-traits"] } -quote = "1.0.8" -proc-macro2 = "1.0" -convert_case = "0.5.0" -rustdoc-types = "0.11.0" -serde = { version = "1.0", features = ["derive"] } -serde_derive = "1.0.137" -indexmap = { version = "1.9.1", features = ["serde"] } -strum = { version = "0.24.1", features = ["derive"] } -vec1 = "1.10.1" diff --git a/crates/languages/bevy_mod_scripting_lua_derive/src/arg.rs b/crates/languages/bevy_mod_scripting_lua_derive/src/arg.rs deleted file mode 100644 index 9e0cd6d6..00000000 --- a/crates/languages/bevy_mod_scripting_lua_derive/src/arg.rs +++ /dev/null @@ -1,117 +0,0 @@ -use std::collections::HashMap; - -use bevy_mod_scripting_common::input::{SimpleType, VisitSimpleType}; -use darling::FromAttributes; -use proc_macro2::{Ident, Span}; -use quote::{quote, quote_spanned}; -use syn::{parse_quote, token::Mut}; - -use crate::visitor::{LuaSimpleTypeArgumentUnwrapper, LuaTypeConstructorVisitor}; - -#[derive(Debug, FromAttributes)] -#[darling(attributes(proxy))] -pub struct ArgAttributes { - #[darling(default)] - pub map: HashMap, -} - -/// Struct for holding argument/output information in functions passed via `functions[..]` meta -#[derive(Debug)] -pub struct Arg { - pub attrs: ArgAttributes, - pub mutability: Option, - /// the type of the argument, only suported patterns are allowed - pub name: Ident, - /// variant specific data enumeration - pub type_: SimpleType, - /// if an argument is raw, it's passed without any unwrapping to the handler function - /// if an argument isn't annotated with the `proxy` flag it is technically raw, but this is different for receiver and output arguments - pub is_raw: bool, - pub span: Span, -} - -impl Arg { - pub fn new( - attrs: ArgAttributes, - name: Ident, - mutability: Option, - type_: SimpleType, - is_raw: bool, - ) -> Self { - Self { - attrs, - mutability, - span: name.span(), - name, - type_, - is_raw, - } - } - - /// Unpacks non-reference proxy parameters (using the `inner` method) yielding expressions which correspond to the proxied type with conversion errors being - /// handled by the try `?` operator. - pub fn unpack_parameter(&self) -> syn::Result> { - let name = &self.name; - if self.is_raw { - // raw parameters DO NOT get unpacked, they get passed directly to the handling method as is - Ok(None) - } else { - // if a proxy parameter is to be passed by value we use inner (which requires Clone to be supported) - Ok(Some( - LuaSimpleTypeArgumentUnwrapper::new(name.clone(), name.span()) - .visit(&self.type_)?, - )) - } - } - - fn arg_signature_generic( - &self, - expecting_receiver: bool, - expecting_ctxt: bool, - ) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) { - assert!(!(expecting_receiver && expecting_ctxt)); - - let _mut = &self.mutability; - let name = &self.name; - let type_ = if expecting_ctxt { - parse_quote!(&bevy_mod_scripting_lua::prelude::Lua) - } else { - LuaTypeConstructorVisitor::new(true, self.type_.contains_proxy_type()) - .visit(&self.type_) - }; - let forced_ref = expecting_receiver.then(|| { - Some(quote_spanned!(self.span=> - & #_mut - )) - }); - - let name_part = quote_spanned!(self.span=> - #_mut #name - ); - let type_part = quote_spanned!(self.span=> - #forced_ref #type_ - ); - (name_part, type_part) - } - - /// Generates the arg signature in an mlua `UserDataFields` or `UserDataMethods` closure for a receiver type argument. - /// generates using an additional outer reference. - pub fn arg_signature_receiver(&self) -> proc_macro2::TokenStream { - let (name, type_) = self.arg_signature_generic(true, false); - quote!(#name : #type_) - } - - /// Generates the arg signature in an mlua `UserDataFields` or `UserDataMethods` closure for a Lua context type argument. - /// generates using an additional outer reference. - pub fn arg_signature_context(&self) -> proc_macro2::TokenStream { - let (name, type_) = self.arg_signature_generic(false, true); - quote!(#name : #type_) - } - - /// Generates the arg signature in an mlua `UserDataFields` or `UserDataMethods` closure for a non-receiver non-context argument. - /// generates the type to match the argument received. - /// The output is split into the name and type parts - pub fn arg_signature(&self) -> (proc_macro2::TokenStream, proc_macro2::TokenStream) { - self.arg_signature_generic(false, false) - } -} diff --git a/crates/languages/bevy_mod_scripting_lua_derive/src/function.rs b/crates/languages/bevy_mod_scripting_lua_derive/src/function.rs deleted file mode 100644 index 631f4216..00000000 --- a/crates/languages/bevy_mod_scripting_lua_derive/src/function.rs +++ /dev/null @@ -1,601 +0,0 @@ -use bevy_mod_scripting_common::input::{ - DuoPath, IdentifierRenamingVisitor, Reference, SimpleType, VisitSimpleType, -}; -use darling::{util::Flag, FromAttributes, FromMeta}; -use proc_macro2::{Ident, Span}; -use quote::{format_ident, quote, quote_spanned, ToTokens}; -use strum::{Display, EnumIter, EnumString}; -use syn::{ - punctuated::Punctuated, spanned::Spanned, visit_mut::VisitMut, Block, LitInt, LitStr, Meta, - Path, Token, -}; -use vec1::Vec1; - -use crate::{ - arg::Arg, - signature::Signature, - visitor::{LuaSimpleTypeWrapper, LuaTypeConstructorVisitor}, - PROXY_OUT_ALIAS, RAW_OUT_ALIAS, SELF_ALIAS, -}; - -#[derive(Default, FromMeta, Display, EnumString, EnumIter, PartialEq, Eq, Clone, Copy, Debug)] -#[darling(rename_all = "PascalCase")] -pub enum FunctionKind { - Function, - MetaFunction, - #[default] - Method, - MetaMethod, - MutableFunction, - MutableMetaFunction, - MutatingMethod, - MutatingMetaMethod, - FieldGetterMethod, - FieldSetterMethod, -} - -impl FunctionKind { - pub fn expects_receiver(self) -> bool { - self == FunctionKind::Method - || self == FunctionKind::MetaMethod - || self == FunctionKind::MutatingMethod - || self == FunctionKind::MutatingMetaMethod - || self == FunctionKind::FieldGetterMethod - || self == FunctionKind::FieldSetterMethod - } - - pub fn is_field(self) -> bool { - self == FunctionKind::FieldGetterMethod || self == FunctionKind::FieldSetterMethod - } - - pub fn is_field_getter(self) -> bool { - self == FunctionKind::FieldGetterMethod - } - - /// Returns true if the mlua closure signature accepts a tuple for general 'Arguments' to the function - /// I.e. arguments freely passed to the function by the caller. - pub fn expects_arguments_tuple(self) -> bool { - self != FunctionKind::FieldGetterMethod - } - - pub fn get_tealr_function(self) -> &'static str { - match self { - FunctionKind::Function => "add_function", - FunctionKind::MetaFunction => "add_meta_function", - FunctionKind::Method => "add_method", - FunctionKind::MetaMethod => "add_meta_method", - FunctionKind::MutableFunction => "add_function_mut", - FunctionKind::MutableMetaFunction => "add_meta_function_mut", - FunctionKind::MutatingMethod => "add_method_mut", - FunctionKind::MutatingMetaMethod => "add_meta_method_mut", - FunctionKind::FieldGetterMethod => "add_field_method_get", - FunctionKind::FieldSetterMethod => "add_field_method_set", - } - } - - pub fn is_meta(self) -> bool { - self == FunctionKind::MetaMethod - || self == FunctionKind::MetaFunction - || self == FunctionKind::MutatingMetaMethod - || self == FunctionKind::MutableMetaFunction - } -} - -/// The attributes which can be applied to lua functions using the -/// `lua(..)` meta attribute -#[derive(Debug, FromAttributes)] -#[darling(attributes(lua))] -pub struct FunctionAttributes { - /// Marks the function to be treated as raw meaning a lot of the wrapping and unwrapping is skipped, - /// a 'Lua' ctxt argument is then expected - pub raw: Flag, - - /// Marks the function as a composite with the given ID, at least one another function with the same composite - /// ID must exist resulting in a combined function being generated. The actual function to dispatch to will be decided based on - /// the types of arguments. If the signature is invalid (i.e. doesn't allow us to dispatch) an error will be thrown - #[darling(default)] - pub composite: Option, - - /// If passed provides the name of the metamethod to use for metamethod based functions - /// the name of the function is used to decide what rust function to call in this case - #[darling(default)] - pub metamethod: Option, - - /// The kind of function to generate on the proxy - #[darling(default)] - pub kind: FunctionKind, - - /// Marks this to be ignored, only used for fields as functions are opt-in - pub skip: Flag, - - /// Meta to pass down to the output proxy or in case of fields - /// used as the argument meta for type being get/set - pub output: Option, - - /// If passed will generate statement before calling the method - /// on the type - pub as_trait: Option, - - #[darling(multiple)] - pub doc: Vec, -} - -/// A function which combines the signatures of multiple functions, -/// and dispatches to the one which matches the signature if any -/// Useful for binary operators which can accept many types on both sides -#[derive(Debug)] -pub struct CompositeFunction { - pub id: String, - pub functions: Vec1, -} - -/// A struct corresponding to each function in the functions[...] meta list. -/// -#[derive(Debug)] -pub struct Function { - pub name: Ident, - pub attrs: FunctionAttributes, - pub sig: Signature, - pub default: Option, - pub span: Span, - pub is_unsafe: bool, -} - -impl Function { - pub fn new( - name: Ident, - attrs: FunctionAttributes, - default: Option, - sig: Signature, - span: Span, - is_unsafe: bool, - ) -> darling::Result { - Ok(Self { - name, - attrs, - sig, - default, - span, - is_unsafe, - }) - } - - /// Tries to retrieve the receiver argument from functions. - /// If not expected returns None and Some otherwise. - /// If the function is of the wrong kind or does not have the correct signature an error is thrown - pub fn self_arg(&self) -> syn::Result> { - if self.attrs.kind.expects_receiver() { - self.get_self_arg().map(Option::Some) - } else { - Ok(None) - } - } - - /// Returns an error if self arg is not there and returns it otherwise - pub fn get_self_arg(&self) -> syn::Result<&Arg> { - self.sig.inputs.first().ok_or_else(|| { - syn::Error::new( - self.sig.span, - "Expected receiver as first argument in the signature".to_string(), - ) - }) - } - - /// Tries to retrieve the context argument from raw functions. - /// If the function is not raw or doesn't have a correct signature an error is thrown - pub fn ctxt_arg(&self) -> syn::Result> { - if self.attrs.raw.is_present() { - self.get_ctxt_arg().map(Option::Some) - } else { - Ok(None) - } - } - - /// Returns an error if no context argument is found in the correct place or returns it otherwise - pub fn get_ctxt_arg(&self) -> syn::Result<&Arg> { - let ctxt_idx = if self.attrs.kind.expects_receiver() { - 1 - } else { - 0 - }; - self.sig.inputs.get(ctxt_idx).ok_or_else(|| { - syn::Error::new( - self.sig.span, - format!( - "Expected ctxt argument in the signature as argument number: `{}`", - ctxt_idx + 1 - ), - ) - }) - } - - /// Retrieves the rest of the arguments (after the receiver and context args) - /// If they are expected, otherwise returns None. - /// If arguments are expected but none are present Some(vec![]) is returned - /// If input vec is shorter than expected, i.e. if the receiver should be there but isn't returns an Err - pub fn other_arguments(&self) -> syn::Result>> { - if self.attrs.kind.expects_arguments_tuple() { - self.get_other_arguments().map(Option::Some) - } else { - Ok(None) - } - } - - pub fn get_other_arguments(&self) -> syn::Result> { - let other_args_idx = - self.attrs.kind.expects_receiver() as usize + self.attrs.raw.is_present() as usize; - - if self.sig.inputs.len() < other_args_idx { - return Err(syn::Error::new( - self.sig.span, - format!("Signature too short, expected {other_args_idx} arguments before this one"), - )); - } - - Ok(self.sig.inputs.iter().skip(other_args_idx)) - } - - /// Converts the function's arguments into closure arguments for use in the closures given to mlua calls - /// - /// # Example - /// ```rust,ignore - /// // the function: - /// fn foo(self, my_str : String){} - /// // would convert to - /// // | _, my_proxy: MyLua, (my_str): (String) | - /// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <- these bits - /// ``` - pub fn generate_mlua_args(&self) -> syn::Result { - let self_arg = self.self_arg()?.map(Arg::arg_signature_receiver); - - let ctxt_arg = self - .ctxt_arg()? - .map(Arg::arg_signature_context) - .unwrap_or_else(|| quote!(_)); - - let other_args = self.other_arguments()?.map(|args| { - let (other_arg_names, other_arg_types) = - args.map(Arg::arg_signature).unzip::<_, _, Vec<_>, Vec<_>>(); - - quote_spanned!(self.sig.span=> - (#(mut #other_arg_names),*) : (#(#other_arg_types),*) - ) - }); - - Ok(vec![Some(ctxt_arg), self_arg, other_args] - .into_iter() - .filter(Option::is_some) - .collect::, Token![,]>>() - .to_token_stream()) - } - - /// Takes all the argument identifiers passed into the function, generates assignments which shadow the original - /// identifiers but modifies the parameter types if required by unpacking proxies. This is done via `.inner` calls on proxy wrappers - /// - /// For example for the type `MyType` - /// `fn my_fn(self, #[proxy] other_ref: &Self, #[proxy] other: Self)` - /// - /// will generate the following statements: - /// ```rust,ignore - /// let _self : MyType = self.inner(); - /// let other_ref : LuaMyType = other; // note this one is kept as a wrapper, and dealt in another process - /// let other : MyType = other_ref.inner(); - /// ``` - fn generate_mlua_body_unwrapped_parameter_assignments( - &self, - ) -> syn::Result { - Ok(self - .sig - .inputs - .iter() - .map(Arg::unpack_parameter) - .collect::>>()? - .iter() - .zip(self.sig.inputs.iter()) - .filter_map(|(unpacked_param, arg)| { - unpacked_param.as_ref().map(|unpacked_param| { - let name = &arg.name; - quote_spanned! {name.span()=>let mut #name = #unpacked_param;} - }) - }) - .collect::()) - } - - /// Similar to generate_mlua_body_output but for functions, makes some more assumptions and directly generates wrapped/unwrapped output depending on what's necessary - /// Does not require another wrapping step and can be directly put in a result as the final output of an mlua closure - fn generate_mlua_body_output_field( - &self, - raw_output_ident: &Ident, - ) -> syn::Result { - let field_type = if self.attrs.kind.is_field_getter() { - &self.sig.output - } else { - self.get_other_arguments()?.next() - .ok_or_else(|| syn::Error::new(self.sig.span, format!("Setter lua method with no arguments, expected at least one argument in function: `{}`", self.name)))? - }; - // we need to figure out which type of field access this is going to be - let self_name = &self.get_self_arg()?.name; - let ctxt_name = &self.get_ctxt_arg()?.name; - let world_ptr = quote!( - - ::get_world(#ctxt_name)? - ); - - let field_name = { - let str_name = self.name.to_string(); - - if str_name.starts_with('_') && str_name[1..].parse::().is_ok() { - syn::Lit::Int(LitInt::new(&str_name[1..], self.name.span())).to_token_stream() - } else { - self.name.clone().to_token_stream() - } - }; - let field_name_str = syn::Lit::Str(LitStr::new(&self.name.to_string(), self.name.span())); - let proxy_output_type = - LuaTypeConstructorVisitor::new(true, false).visit(&field_type.type_); - - Ok(match &field_type.type_ { - // proxy, need to index into it then wrap the result - // getter - t if t.contains_proxy_type() && self.attrs.kind.is_field_getter() => quote!( - let #raw_output_ident = #proxy_output_type::new_ref(bevy_script_api::script_ref::ValueIndex::index(& #self_name.reflect_ref(#world_ptr), std::borrow::Cow::Borrowed(#field_name_str))); - ), - // setter - t if t.contains_proxy_type() => { - let first_arg_name = &self - .get_other_arguments()? - .next() - .ok_or_else(|| { - syn::Error::new( - self.sig.span, - "Field setter requires a single argument which is missing", - ) - })? - .name; - quote!( - let #raw_output_ident = #first_arg_name.apply_self_to_base(&mut bevy_script_api::script_ref::ValueIndex::index(& #self_name.reflect_ref(#world_ptr), std::borrow::Cow::Borrowed(#field_name_str)))?; - ) - } - - // plain reflection, index into the ReflectReference with the field path - // getter - SimpleType::Type(syn::Type::Path(path)) - if path.path.is_ident("ReflectedValue") && self.attrs.kind.is_field_getter() => - { - quote!( - let #raw_output_ident = bevy_script_api::script_ref::ValueIndex::index(& #self_name.reflect_ref(#world_ptr), std::borrow::Cow::Borrowed(#field_name_str)); - ) - } - // setter - SimpleType::Type(syn::Type::Path(path)) if path.path.is_ident("ReflectedValue") => { - let first_arg_name = &self - .get_other_arguments()? - .next() - .ok_or_else(|| { - syn::Error::new( - self.sig.span, - "Field setter requires a single argument which is missing", - ) - })? - .name; - quote!( - let #raw_output_ident = bevy_script_api::script_ref::ValueIndex::index(& #self_name.reflect_ref(#world_ptr), std::borrow::Cow::Borrowed(#field_name_str)).apply(&#first_arg_name.ref_)?; - ) - } - - // primitive use clone on the value and return it without a wrapper - // getter - _ if self.attrs.kind.is_field_getter() => quote!( - let #raw_output_ident = #self_name.val(|#self_name| #self_name.#field_name.clone())?; - ), - // setter - _ => { - let first_arg_name = &self - .get_other_arguments()? - .next() - .ok_or_else(|| { - syn::Error::new( - self.sig.span, - "Field setter requires a single argument which is missing", - ) - })? - .name; - quote!( - let #raw_output_ident = #self_name.val_mut(|#self_name| #self_name.#field_name = #first_arg_name)?; - ) - } - }) - } - - /// Generates the statement which calls the proxied function with the same argument names as in the function declaration - /// and stores the output in a variable with the given identifier. Static methods, are called against the given `proxied_name` - /// - /// For example for the type `MyType` with proxied ident `__proxied_out` - /// `fn my_fn(self, #[proxy] other_ref: &Self, #[proxy] other: Self) -> Self` - /// - /// will generate the following statement: - /// ```rust,ignore - /// let __proxied_out : MyType = self.my_fn(other_ref, other); - /// ``` - fn generate_mlua_body_raw_output( - &self, - raw_output_ident: &Ident, - proxied_type_path: &Path, - ) -> syn::Result { - // generate function call on proxied type (operating over unwrapped parameters) - // output will be stored in raw_output_ident with the proxied_type_path - - // the type before we wrap it in a proxy - let raw_output_type = - LuaTypeConstructorVisitor::new(false, false).visit(&self.sig.output.type_); - - match &self.default { - Some(body) => { - let stmts = body.stmts.iter().cloned().map(|mut s| { - IdentifierRenamingVisitor { - target: "self", - replacement: SELF_ALIAS, - } - .visit_stmt_mut(&mut s); - s - }); - - Ok(quote_spanned! {body.span()=> - let #raw_output_ident : #raw_output_type = - (||{ - #(#stmts)* - })(); - }) - } - None => { - let function_name = &self.name; - let param_names = self - .sig - .inputs - .iter() - .map(|arg| &arg.name) - .collect::>(); - - // override this span, as otherwise spans propagate weird - let mut proxied_name = proxied_type_path.clone(); - - proxied_name - .segments - .iter_mut() - .for_each(|v| v.ident.set_span(self.sig.span)); - - let method_path = if let Some(trait_path) = &self.attrs.as_trait { - quote_spanned!(self.sig.span=> - #trait_path::#function_name - ) - } else { - quote_spanned!(self.sig.span=> - #proxied_name::#function_name - ) - }; - - Ok(quote_spanned! {self.sig.span=> - let #raw_output_ident : #raw_output_type = - #method_path(#(#param_names),*); - }) - } - } - } - - /// Generates a wrapping statement, which if the type present in the `proxied_output_ident` variable needs to be wrapped into a proxy constructor, will do so and assign - /// the output to the given `proxy_output_ident`. - /// - /// For example for the type: `MyType` with `__proxy_out output` identifier - /// the function: `fn my_fn(self, #[proxy] other_ref: &Self, #[proxy] other: Self) -> Self` - /// will generate the following statement: - /// ```rust,ignore - /// let __proxy_out : LuaMyType = LuaMyType::new(__proxied_out); - /// ``` - fn generate_mlua_body_proxy_output( - &self, - proxied_output_ident: &Ident, - proxy_output_ident: &Ident, - ) -> syn::Result { - if self.sig.output.is_raw { - return Ok(quote_spanned! {self.sig.span=> - let #proxy_output_ident = #proxied_output_ident; - }); - } - - // generate `new` calls as required to build proxy stored in out_ident - let constructor_wrapped_expression = - LuaSimpleTypeWrapper::new(proxied_output_ident.clone(), proxied_output_ident.span()) - .visit(&self.sig.output.type_)?; - - // the type of the wrapped type (if wrapped) - let proxy_output_type = - LuaTypeConstructorVisitor::new(true, false).visit(&self.sig.output.type_); - - // the statement assigning the proxy output to proxy_output_ident - Ok(quote_spanned! {self.sig.span=> - let #proxy_output_ident : #proxy_output_type = #constructor_wrapped_expression; - }) - } - - pub fn generate_mlua_body( - &self, - proxied_type_path: &Path, - ) -> syn::Result { - let unpacked_parameter_declarations = - self.generate_mlua_body_unwrapped_parameter_assignments()?; - - let raw_output_ident = format_ident!("{RAW_OUT_ALIAS}", span = self.sig.span); - let proxy_output_ident = format_ident!("{PROXY_OUT_ALIAS}", span = self.sig.span); - - let raw_output_stmt = if self.attrs.kind.is_field() { - self.generate_mlua_body_output_field(&raw_output_ident)? - } else { - self.generate_mlua_body_raw_output(&raw_output_ident, proxied_type_path)? - }; - - // for fields the output is expected to be raw anyway so this will just performa no-op - let proxy_output_stmt = - self.generate_mlua_body_proxy_output(&raw_output_ident, &proxy_output_ident)?; - - // determine if we need to wrap the output in an Ok() statement - let last_stm = match &self.sig.output.type_ { - SimpleType::DuoPath(DuoPath { ident, .. }) if *ident == "Result" => { - quote_spanned! {self.sig.span=>#proxy_output_ident} - } - _ => quote_spanned! {self.sig.span=>Ok(#proxy_output_ident)}, - }; - - let conversion_body_stms = quote!( - #raw_output_stmt - #proxy_output_stmt - #last_stm - ); - - // for every argument which is a reference, we need a separate sort of call, - // we cannot use `v.inner()` since this operates over values, we must use `val_mut` or `val` to get a reference to the wrapped - // structure for the duration of the call - let conversion_body_surrounded_with_dereferening_stms = - self.sig - .inputs - .iter() - .fold(conversion_body_stms, |acc, arg_meta| { - // only proxy types which are directly inside a reference are supported as references - if !matches!(arg_meta.type_, SimpleType::Reference(Reference{ ref inner, .. }) - if matches!(inner.as_ref(), SimpleType::ProxyType(_))) - { - return acc; - } - // raw arguments are passed directly to the handler function - if arg_meta.is_raw { - return acc; - } - - let method_call = if arg_meta.type_.has_outer_mut_ref() { - format_ident!("val_mut", span = arg_meta.span) - } else { - format_ident!("val", span = arg_meta.span) - }; - - let arg_name = &arg_meta.name; - - quote_spanned! {self.sig.span=>{ - #arg_name.#method_call(|mut #arg_name| {#acc})? - }} - }); - let out = quote!( - #unpacked_parameter_declarations - #conversion_body_surrounded_with_dereferening_stms - ); - - if self.is_unsafe { - Ok(quote_spanned! {self.sig.span=> - unsafe { - #out - } - }) - } else { - Ok(out) - } - } -} diff --git a/crates/languages/bevy_mod_scripting_lua_derive/src/lib.rs b/crates/languages/bevy_mod_scripting_lua_derive/src/lib.rs deleted file mode 100644 index 439075b9..00000000 --- a/crates/languages/bevy_mod_scripting_lua_derive/src/lib.rs +++ /dev/null @@ -1,543 +0,0 @@ -use std::collections::HashMap; - -use arg::Arg; -use bevy_mod_scripting_common::{input::*, utils::doc_attribute_to_string_lit}; -use syn::{parse_macro_input, DeriveInput, Variant}; -use syn::{ - parse_quote, spanned::Spanned, AttrStyle, Attribute, Field, Meta, Path, Token, TraitItemFn, -}; - -use crate::function::*; -use crate::signature::*; -use darling::{FromAttributes, FromDeriveInput}; -use function::FunctionAttributes; -use proc_macro::TokenStream; -use proc_macro2::*; -use quote::*; -use vec1::{vec1, Vec1}; -pub(crate) mod arg; -pub(crate) mod function; -pub(crate) mod signature; -pub(crate) mod visitor; - -const SELF_ALIAS: &str = "_self"; -const RAW_OUT_ALIAS: &str = "__proxied_out"; -const PROXY_OUT_ALIAS: &str = "__proxy_out"; -const PROXY_PREFIX: &str = "Lua"; -const VALID_META_METHODS: [&str; 27] = [ - "Add", "Sub", "Mul", "Div", "Mod", "Pow", "Unm", "IDiv", "BAnd", "BOr", "BXor", "BNot", "Shl", - "Shr", "Concat", "Len", "Eq", "Lt", "Le", "Index", "NewIndex", "Call", "ToString", "Pairs", - "IPairs", "Iter", "Close", -]; - -/// Takes in field with all the required meta and converts it into a -/// TraitItemFn representation -fn convert_field_to_lua_accessor( - idx: usize, - field: &Field, - is_setter: bool, -) -> darling::Result { - let field_name = field - .ident - .clone() - .unwrap_or_else(|| format_ident!("_{}", idx)); - let field_type = &field.ty; - let attrs = &field.attrs; - let mut setter_args: Option = None; - if let Some(attr) = attrs.iter().find(|attr| attr.meta.path().is_ident("lua")) { - attr.parse_nested_meta(|nested| { - if nested.path.is_ident("output") { - nested.parse_nested_meta(|nested| { - setter_args = Some(nested.input.parse()?); - Ok(()) - })? - } - Ok(()) - })?; - } - let setter_arg_attrs = setter_args.map(|tokens| Attribute { - pound_token: Token![#](field.span()), - style: AttrStyle::Outer, - bracket_token: Default::default(), - meta: syn::Meta::List(syn::MetaList { - path: Ident::new("proxy", field.span()).into(), - delimiter: syn::MacroDelimiter::Paren(Default::default()), - tokens, - }), - }); - let trait_item_method: TraitItemFn = if is_setter { - parse_quote! { - #[lua(kind="FieldSetterMethod", raw)] - #(#attrs)* - fn #field_name (&mut self, lua: &Lua, #setter_arg_attrs other: #field_type); - } - } else { - parse_quote! { - #[lua(kind="FieldGetterMethod", raw)] - #(#attrs)* - fn #field_name (&self, lua: &Lua) -> #field_type; - } - }; - - Ok(trait_item_method) -} - -/// Removes functions from the list and matches them up based on composite ID's into a unified struct -fn extract_composite_functions(functions: &mut Vec) -> Vec { - let indices = functions - .iter() - .enumerate() - .filter_map(|(idx, elem)| { - if elem.attrs.composite.is_some() { - Some(idx) - } else { - None - } - }) - .rev() // reverse order to avoid double shifting things around - .collect::>(); - - let mut composites: HashMap> = HashMap::with_capacity(indices.len()); - for i in indices { - let f = functions.remove(i); - let name = &f.attrs.composite.as_ref().unwrap(); - if composites.contains_key(name.as_str()) { - composites.get_mut(name.as_str()).unwrap().push(f); - } else { - composites.entry((*name).to_owned()).or_insert(vec1![f]); - } - } - - composites - .into_iter() - .map(|(id, functions)| CompositeFunction { id, functions }) - .collect() -} - -fn build_function( - proxied_type_path: &Path, - function_def: TraitItemFn, -) -> darling::Result> { - let attrs = FunctionAttributes::from_attributes(&function_def.attrs)?; - // if skipping return no-op - if attrs.skip.is_present() { - return Ok(None); - }; - - let span = function_def.span(); - - let function_name = function_def.sig.ident.clone(); - let output_attrs = attrs - .output - .clone() - .map(|meta| { - let meta = meta.require_list()?.parse_args::()?; - Ok::<_, syn::Error>(vec![Attribute { - pound_token: Token![#](meta.span()), - style: AttrStyle::Outer, - bracket_token: Default::default(), - meta, - }]) - }) - .transpose()? - .unwrap_or_default(); - - let is_unsafe = function_def.sig.unsafety.is_some(); - - let signature = Signature::new( - proxied_type_path.clone(), - function_def.sig, - attrs.raw.is_present(), - output_attrs, - )?; - Function::new( - function_name.clone(), - attrs, - function_def.default, - signature, - span, - is_unsafe, - ) - .map(Option::Some) -} - -/// generates either the string function name or the MetaMethod type path depending if it's a valid meta method -fn generate_mlua_function_name(function: &Function) -> syn::Result { - let function_name = &function.name; - let tealr = quote!(bevy_mod_scripting_lua::tealr::mlu::mlua); - if function.attrs.kind.is_meta() { - let metamethod = function.attrs.metamethod.as_ref().ok_or_else(|| { - syn::Error::new( - function.span, - "Missing `metamethod` lua proxy attribute, required for meta functions.", - ) - })?; - // check is valid meta method if not use custom name - if VALID_META_METHODS.contains(&metamethod.to_string().as_str()) { - Ok(quote!(#tealr::MetaMethod::#metamethod)) - } else { - let std_string = metamethod.to_string(); - Ok(quote!(#tealr::MetaMethod::Custom(#std_string.to_string()))) - } - } else { - Ok(function_name.to_string().to_token_stream()) - } -} - -/// Given a function with correct meta and the name of the proxied type will generate mlua statement -/// which will register the given function within an appropriate mlua container `UserDataMethods` or `UserDataFields` -/// i.e.: -/// ```rust,ignore -/// /// docs -/// fields.#tealr_function(#signature, #closure) -/// // or -/// -/// /// docs -/// methods.#tealr_function(#signature, #closure) -/// ``` -/// depending on if the function is a field accessor or a method/function -fn generate_mlua_registration_code( - container_ident: Ident, - proxied_type_path: &Path, - function: Function, -) -> darling::Result { - let method_documentation_calls = function - .attrs - .doc - .iter() - .map(|tkns| quote_spanned!(function.span=>#container_ident.document_type(#tkns))); - - let tealr_function = format_ident!( - "{}", - function.attrs.kind.get_tealr_function(), - span = function.span - ); - let signature = generate_mlua_function_name(&function)?; - - let args = function.generate_mlua_args()?; - let body = function.generate_mlua_body(proxied_type_path)?; - - Ok(quote_spanned! {body.span()=> - #(#method_documentation_calls);* - #container_ident.#tealr_function(#signature,|#args| { - #body - }); - }) -} - -/// Same as generate_mlua_registration_code but for composite functions -fn generate_mlua_registration_code_composite( - container_ident: Ident, - proxied_type_path: &Path, - functions: CompositeFunction, -) -> darling::Result { - let tealr = quote!(bevy_mod_scripting_lua::tealr::mlu); - let mut method_documentation_calls = Vec::default(); - let first = functions.functions.first(); - // take the first functions for function signature from the composite - let tealr_function = format_ident!( - "{}", - first.attrs.kind.get_tealr_function(), - span = first.span - ); - let signature = generate_mlua_function_name(first)?; - let (main_arg_names, main_arg_types) = first - .get_other_arguments()? - .map(|a| (a.name.clone(), quote!(#tealr::mlua::Value))) - .unzip::<_, _, Vec<_>, Vec<_>>(); - - let dispatchers = - functions - .functions - .iter() - .map(|function| { - // this is much easier, receivers need special treatment on mlua side - // function args are treated equally, we just need a union for lhs and rhs then to convert those args and - // pass dispatch them to the appropriate function - if function.attrs.kind.expects_receiver() || function.attrs.raw.is_present() { - return Err(syn::Error::new( - function.span, - "Composite functions with receivers are not supported, use a function instead", - )); - } - - method_documentation_calls.extend(function.attrs.doc.iter().map( - |tkns| quote_spanned!(function.span=>#container_ident.document_type(#tkns);), - )); - - let (arg_names, arg_types) = function - .sig - .inputs - .iter() - .map(Arg::arg_signature) - .unzip::<_, _, Vec<_>, Vec<_>>(); - let body = function.generate_mlua_body(proxied_type_path)?; - Ok(quote_spanned!(function.span=> - match (#(<#arg_types as #tealr::mlua::FromLua>::from_lua(#main_arg_names.clone(), ctxt)),*) { - (#(Ok(#arg_names)),*) => { - let out = { - #body - }; - return out.and_then(|out| #tealr::mlua::IntoLua::into_lua(out, ctxt)) - }, - _ => (), - }; - )) - }) - .collect::>>()?; - - // let (variant_idents, variant_types) = unique_types.iter().unzip(); - // let composite_id = Ident::new(&functions.id, first.span); - let composite = quote_spanned! {first.span=> - // bevy_script_api::impl_tealr_any_union!(#composite_id = #(#variant_idents: #variant_types),*) - #(#method_documentation_calls)* - #container_ident.#tealr_function(#signature,|ctxt, (#(#main_arg_names),*) : (#(#main_arg_types),*)| { - #(#dispatchers)* - Err(#tealr::mlua::Error::RuntimeError( - format!("Function `{}` has no overloaded version accepting argument types: `{}`", - #signature, - vec![#(#main_arg_names.type_name()),*].join(", ") - ) - ) - ) - }); - }; - Ok(composite) -} - -#[proc_macro_derive(LuaProxy, attributes(lua, proxy))] -pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { - let derive_input = parse_macro_input!(input as DeriveInput); - - let meta: ProxyInput = match ProxyInput::from_derive_input(&derive_input) { - Ok(v) => v, - Err(e) => return darling::Error::write_errors(e).into(), - }; - if meta.proxy_name.is_some() { - // throw error - return syn::Error::new( - derive_input.span(), - "The `name` attribute is not supported for lua proxies", - ) - .to_compile_error() - .into(); - } - - let proxied_type_path: syn::Path = meta.remote.unwrap_or(meta.ident.clone().into()); - let proxied_type_str = proxied_type_path.segments.last().unwrap().ident.to_string(); - let proxy_type_ident = format_ident!("{PROXY_PREFIX}{}", &meta.ident); - let tealr = quote!(bevy_mod_scripting_lua::tealr::mlu); - - // optional clone extensions - let opt_with_clone = meta - .derive - .clone - .is_present() - .then_some(quote_spanned! {derive_input.span()=>with Clone}) - .unwrap_or_default(); - - let opt_from_lua_proxy = meta.derive.clone.is_present().then_some( - quote_spanned!{derive_input.span()=> - impl bevy_script_api::lua::FromLuaProxy<'_> for #proxied_type_path { - fn from_lua_proxy<'lua>(lua_value: #tealr::mlua::Value<'lua>, _: &'lua #tealr::mlua::Lua) -> #tealr::mlua::Result { - if let #tealr::mlua::Value::UserData(ud) = lua_value{ - let wrapper = ud.borrow::<#proxy_type_ident>()?; - Ok(std::ops::Deref::deref(&wrapper).inner()?) - } else { - Err(#tealr::mlua::Error::FromLuaConversionError{ - from: "Value", - to: #proxied_type_str, - message: None - }) - } - } - } - } - ).unwrap_or_default(); - - // generate type level tealr documentation calls - let type_level_document_calls = meta - .attrs - .iter() - .filter(|&a| a.meta.path().is_ident("doc")) - .map(doc_attribute_to_string_lit) - .map(|tkns| quote_spanned!(derive_input.span()=>methods.document_type(#tkns);)); - - // generate method equivalents for each field, i.e. unify fields and methods as both can be represented as functions - let field_methods: Vec = match meta.data { - darling::ast::Data::::Struct(fields) => { - let mut out: Vec<_> = Default::default(); - let mut errors = darling::Error::accumulator(); - - out.extend( - fields - .iter() - .enumerate() - .filter_map(|(idx, field)| { - errors.handle_in(|| convert_field_to_lua_accessor(idx, field, false)) - }) - .collect::>(), - ); - - out.extend( - fields - .iter() - .enumerate() - .filter_map(|(idx, field)| { - errors.handle_in(|| convert_field_to_lua_accessor(idx, field, true)) - }) - .collect::>(), - ); - - // short circuit if found any errors - if let Err(e) = errors.finish() { - return e.write_errors().into(); - } - - out - } - _ => panic!("Enums or Unions are not supported"), - }; - - let mut errors = darling::Error::accumulator(); - - // generate both tealr documentation and instantiations of functions and field getters/setters - let mut methods = meta - .functions - .0 - .into_iter() - .filter_map(|v| { - errors - .handle_in(|| build_function(&proxied_type_path, v)) - .flatten() - }) - .collect::>(); - - let composites = extract_composite_functions(&mut methods) - .into_iter() - .flat_map(|function| { - errors.handle_in(|| { - generate_mlua_registration_code_composite( - format_ident!("methods", span = function.functions.first().span), - &proxied_type_path, - function, - ) - }) - }) - .collect::>(); - - // for methods, allow composite functions with combined signatures and runtime dispatch based on type - - let fields = field_methods - .into_iter() - .flat_map(|v| { - errors - .handle_in(|| build_function(&proxied_type_path, v)) - .flatten() - }) - .collect::>(); - - let methods = methods - .into_iter() - .map(|function| { - errors.handle_in(|| { - generate_mlua_registration_code( - format_ident!("methods", span = function.span), - &proxied_type_path, - function, - ) - }) - }) - .collect::>(); - - let fields = fields - .into_iter() - .map(|function| { - errors.handle_in(|| { - generate_mlua_registration_code( - format_ident!("fields", span = function.span), - &proxied_type_path, - function, - ) - }) - }) - .collect::>(); - - // stop if any errors so far - if let Err(e) = errors.finish() { - return e.write_errors().into(); - } - - quote_spanned! {derive_input.span()=> - - bevy_script_api::make_script_wrapper!(#proxied_type_path as #proxy_type_ident #opt_with_clone); - bevy_script_api::impl_from_lua_with_clone!(#proxy_type_ident); - bevy_script_api::impl_tealr_type!(#proxy_type_ident); - - #opt_from_lua_proxy - - #[automatically_derived] - #[allow(unused_parens, unused_braces, unused_mut, unused_variables)] - #[allow(clippy::all)] - impl #tealr::TealData for #proxy_type_ident { - fn add_methods<'lua, T: #tealr::TealDataMethods<'lua, Self>>(methods: &mut T) { - #(#type_level_document_calls)* - #(#methods)* - #(#composites)* - } - - fn add_fields<'lua, T: #tealr::TealDataFields<'lua, Self>>(fields: &mut T) { - #(#fields)* - } - } - - #[allow(clippy::all, unused_variables)] - impl bevy_script_api::lua::LuaProxyable for #proxied_type_path { - fn ref_to_lua<'lua>(self_ : bevy_script_api::script_ref::ReflectReference, lua: &'lua #tealr::mlua::Lua) -> #tealr::mlua::Result<#tealr::mlua::Value<'lua>> { - <#proxy_type_ident as #tealr::mlua::IntoLua>::into_lua(#proxy_type_ident::new_ref(self_),lua) - } - - fn apply_lua<'lua>(self_ : &mut bevy_script_api::script_ref::ReflectReference, lua: &'lua #tealr::mlua::Lua, new_val: #tealr::mlua::Value<'lua>) -> #tealr::mlua::Result<()> { - if let #tealr::mlua::Value::UserData(v) = new_val { - let other = v.borrow::<#proxy_type_ident>()?; - let other = &other; - - other.apply_self_to_base(self_)?; - Ok(()) - } else { - Err(#tealr::mlua::Error::RuntimeError( - "Error in assigning to custom user data".to_owned(), - )) - } - } - } - - #[allow(clippy::all, unused_variables)] - impl bevy_script_api::lua::IntoLuaProxy<'_> for #proxied_type_path { - fn to_lua_proxy<'lua>(self, lua: &'lua #tealr::mlua::Lua) -> #tealr::mlua::Result<#tealr::mlua::Value<'lua>>{ - <#proxy_type_ident as #tealr::mlua::IntoLua>::into_lua(#proxy_type_ident::new(self),lua) - } - } - - } - .into() -} - -#[cfg(test)] -mod test { - - use crate::function::FunctionAttributes; - use darling::FromAttributes; - use syn::TraitItemFn; - - #[test] - fn test_parse_function_attributes_parses() { - let function = " - #[lua(output(proxy))] - fn asd(#[proxy] arg: String, #[proxy(Type=\"LuaType\")] arg2: (String, Type)) -> String; - "; - let trait_fn: TraitItemFn = syn::parse_str(function).unwrap(); - - FunctionAttributes::from_attributes(&trait_fn.attrs).unwrap(); - } -} diff --git a/crates/languages/bevy_mod_scripting_lua_derive/src/signature.rs b/crates/languages/bevy_mod_scripting_lua_derive/src/signature.rs deleted file mode 100644 index 26aca7fd..00000000 --- a/crates/languages/bevy_mod_scripting_lua_derive/src/signature.rs +++ /dev/null @@ -1,143 +0,0 @@ -use std::collections::HashMap; - -use bevy_mod_scripting_common::input::SimpleType; -use darling::FromAttributes; -use proc_macro2::{Ident, Span}; -use syn::{ - spanned::Spanned, token::Mut, Attribute, FnArg, Pat, PatIdent, PatType, Path, ReturnType, Type, - TypeTuple, -}; - -use crate::{ - arg::{Arg, ArgAttributes}, - PROXY_PREFIX, RAW_OUT_ALIAS, SELF_ALIAS, -}; - -/// Describes the functional signature of a function from the `functions[..]` list -#[derive(Debug)] -pub struct Signature { - pub inputs: Vec, - pub output: Arg, - pub span: Span, -} - -impl Signature { - /// Creates a new signature struct - /// if in_raw_function will set is_raw on all arguments and outputs to true - /// if is_field_setter, output_attrs will be applied to the third argument of the function if it exists (the first non self or ctxt arg) - pub fn new( - proxied_type_path: Path, - sig: syn::Signature, - in_raw_function: bool, - output_attrs: Vec, - ) -> darling::Result { - // convert output to FnArg - let output_arg_name = Ident::new(RAW_OUT_ALIAS, sig.output.span()); - let span = sig.span(); - // if no return type specified use `()` - let output_type = match sig.output { - ReturnType::Default => Type::Tuple(TypeTuple { - paren_token: Default::default(), - elems: Default::default(), - }), - ReturnType::Type(_, ty) => *ty, - }; - - let inputs = sig - .inputs - .into_iter() - .map(|arg| Self::convert_fn_arg(arg, &proxied_type_path, in_raw_function)) - .collect::>>()?; - - // convert to Arg structs - let output = Self::convert_type( - output_type, - &proxied_type_path, - in_raw_function, - output_attrs, - output_arg_name, - None, - )?; - - Ok(Self { - inputs, - output, - span, - }) - } - - /// Convert a function argument into custom Arg struct by converting the type to SimpleType and parsing attributes - fn convert_fn_arg( - arg: FnArg, - proxied_type_path: &Path, - in_raw_function: bool, - ) -> darling::Result { - let type_map = HashMap::from_iter([( - proxied_type_path.segments.last().unwrap().clone().ident, - None, - )]); - - Ok(match arg { - FnArg::Receiver(ref receiver) => { - let type_ = - SimpleType::new_from_fn_arg(PROXY_PREFIX, &arg, proxied_type_path, &type_map)?; - let attrs = ArgAttributes::from_attributes(&receiver.attrs)?; - Arg::new( - attrs, - Ident::new(SELF_ALIAS, receiver.span()), - receiver.mutability, - type_, - in_raw_function, - ) - } - FnArg::Typed(PatType { attrs, pat, ty, .. }) => { - let (mutability, arg_name) = match pat.as_ref() { - Pat::Ident(PatIdent { - mutability, ident, .. - }) => (mutability, ident), - _ => return Err(darling::Error::custom("Unsupported parameter pattern")), - }; - - Self::convert_type( - *ty, - proxied_type_path, - in_raw_function, - attrs, - arg_name.clone(), - *mutability, - )? - } - }) - } - - /// Convert a type corresponding to an argument into an Arg struct by converting it to a Simple type and parsing the given attributes - fn convert_type( - ty: Type, - proxied_type_path: &Path, - in_raw_function: bool, - attrs: Vec, - arg_name: Ident, - mutability: Option, - ) -> darling::Result { - let mut type_map = HashMap::from_iter([( - proxied_type_path.segments.last().unwrap().clone().ident, - None, - )]); - let is_proxy = attrs.iter().any(|a| a.path().is_ident("proxy")); - let attrs = ArgAttributes::from_attributes(&attrs)?; - let type_ = if is_proxy && attrs.map.is_empty() { - SimpleType::new_from_contextual_type_proxy_all(PROXY_PREFIX, &ty, proxied_type_path)? - } else { - type_map.extend(attrs.map.iter().map(|(a, b)| (a.clone(), Some(b.clone())))); - SimpleType::new_from_contextual_type(PROXY_PREFIX, &ty, proxied_type_path, &type_map)? - }; - - Ok(Arg::new( - attrs, - arg_name, - mutability, - type_, - in_raw_function, - )) - } -} diff --git a/crates/languages/bevy_mod_scripting_lua_derive/src/visitor.rs b/crates/languages/bevy_mod_scripting_lua_derive/src/visitor.rs deleted file mode 100644 index 2dc8ec2b..00000000 --- a/crates/languages/bevy_mod_scripting_lua_derive/src/visitor.rs +++ /dev/null @@ -1,386 +0,0 @@ -/// This module contains both `SimpleType` and `syn::Type` visitors to help us with the code generation. -use bevy_mod_scripting_common::input::*; -use proc_macro2::Span; -use quote::*; -use syn::*; - -/// Generates an unwrapping expression which can be used to assign the unwrapped proxy to a variable. -/// the argument `#[proxy] arg: MyType` will generate the following expression: -/// ```rust,ignore -/// arg.inner()?; -/// ``` -pub(crate) struct LuaSimpleTypeArgumentUnwrapper { - arg_name: Ident, - span: Span, -} - -impl LuaSimpleTypeArgumentUnwrapper { - pub fn new(arg_name: Ident, span: Span) -> Self { - Self { arg_name, span } - } -} - -impl VisitSimpleType> for LuaSimpleTypeArgumentUnwrapper { - fn visit_unit(&mut self, _: bool) -> syn::Result { - Ok(quote_spanned!(self.span=> ())) - } - - fn visit_proxy_type( - &mut self, - _: &ProxyType, - is_child_of_reference: bool, - ) -> syn::Result { - let arg_name: &Ident = &self.arg_name; - - if is_child_of_reference { - Ok(quote_spanned!(self.span=> #arg_name)) - } else { - Ok(quote_spanned!(self.span=> #arg_name.inner()?)) - } - } - - fn visit_type(&mut self, _type: &Type, _: bool) -> syn::Result { - let arg_name: &Ident = &self.arg_name; - Ok(quote_spanned!(self.span=> #arg_name)) - } - - fn visit_unit_path( - &mut self, - unit_path: &UnitPath, - _: bool, - ) -> syn::Result { - match unit_path.std_type_ident { - Some(StdTypeIdent::Option) => { - let inner = self.visit_simple_type(&unit_path.inner, false)?; - let arg_name = &self.arg_name; - Ok(quote_spanned!(self.span=> - #arg_name.map(|#arg_name| Ok::<_,bevy_mod_scripting_lua::tealr::mlu::mlua::Error>(#inner)).transpose()? - )) - } - Some(StdTypeIdent::Vec) => { - let inner = self.visit_simple_type(&unit_path.inner, false)?; - let arg_name = &self.arg_name; - Ok(quote_spanned!(self.span=> - #arg_name.into_iter().map(|#arg_name| Ok(#inner)).collect::,bevy_mod_scripting_lua::tealr::mlu::mlua::Error>>()? - )) - } - Some(unsupported_std_type) => Err(syn::Error::new_spanned( - &unit_path.ident, - format!("`{}` is not yet supported", unsupported_std_type), - )), - _ => Err(syn::Error::new_spanned( - &unit_path.ident, - "Unsupported type", - )), - } - } -} - -/// `maps` a simple type recursively, expanding the type into a series of map/iter/etc calls where the leaf types are operating over -/// unwrapped proxied types (the inner types) and the output expression produces a wrapped proxy type. -/// -/// requires arg_name to be a valid identifier refering to the name of the variable containing a value with the SimpleType being mapped. -/// The returned token stream will be an expression. -pub(crate) struct LuaSimpleTypeWrapper { - arg_name: Ident, - span: Span, -} - -impl LuaSimpleTypeWrapper { - pub fn new(arg_name: Ident, span: Span) -> Self { - Self { arg_name, span } - } -} - -impl VisitSimpleType> for LuaSimpleTypeWrapper { - fn visit_unit_path( - &mut self, - unit_path: &UnitPath, - _: bool, - ) -> syn::Result { - match unit_path.std_type_ident { - Some(StdTypeIdent::Option) => { - let inner = self.visit_simple_type(&unit_path.inner, false)?; - let arg_name = &self.arg_name; - Ok(quote_spanned!(self.span=> - #arg_name.map(|mut #arg_name| #inner) - )) - } - Some(StdTypeIdent::Vec) => { - let inner = self.visit_simple_type(&unit_path.inner, false)?; - let arg_name = &self.arg_name; - - Ok(quote_spanned!(self.span=> - #arg_name.into_iter().map(|mut #arg_name| #inner).collect::>() - )) - } - Some(unsupported_std_type) => Err(syn::Error::new_spanned( - &unit_path.ident, - format!("`{}` is not yet supported", unsupported_std_type), - )), - _ => Err(syn::Error::new_spanned( - &unit_path.ident, - "Unsupported type", - )), - } - } - - fn visit_duo_path( - &mut self, - duo_path: &DuoPath, - _: bool, - ) -> syn::Result { - let tealr = quote!(bevy_mod_scripting_lua::tealr); - - match duo_path.std_type_ident { - Some(StdTypeIdent::Result) => { - let left = self.visit_simple_type(&duo_path.left, false)?; - let right = self.visit_simple_type(&duo_path.right, false)?; - let arg_name = &self.arg_name; - Ok(quote_spanned!(self.span=> - #arg_name.map(|mut #arg_name| #left).map_err(|#arg_name| #tealr::mlu::mlua::Error::external(#right)) - )) - } - Some(unsupported_std_type) => Err(syn::Error::new_spanned( - &duo_path.ident, - format!("`{}` is not yet supported", unsupported_std_type), - )), - _ => Err(syn::Error::new_spanned(&duo_path.ident, "Unsupported type")), - } - } - - fn visit_unit(&mut self, _: bool) -> syn::Result { - Ok(quote_spanned!(self.span=> - () - )) - } - - fn visit_proxy_type( - &mut self, - proxy_type: &ProxyType, - _: bool, - ) -> syn::Result { - let proxy_ident = &proxy_type.proxy_ident; - let arg_name = &self.arg_name; - Ok(quote_spanned! {self.span=> - #proxy_ident::new(#arg_name) - }) - } - - fn visit_type(&mut self, _type: &Type, _: bool) -> syn::Result { - Ok(self.arg_name.to_token_stream()) - } -} - -/// Wrapper around the `TypeConstructorVisitor` which generates a syn::Type from a `SimpleType`. -/// This is used to handle special cases such as when encountering an outer `Result` where E needs to specifically be converted to an `mlua::Error` on the proxy side -pub(crate) struct LuaTypeConstructorVisitor { - pub general_visitor: TypeConstructorVisitor, -} - -impl LuaTypeConstructorVisitor { - pub fn new(generate_proxy_type: bool, strip_outer_ref: bool) -> Self { - Self { - general_visitor: TypeConstructorVisitor::new(generate_proxy_type, strip_outer_ref), - } - } -} - -impl VisitSimpleType for LuaTypeConstructorVisitor { - fn visit_unit(&mut self, is_child_of_reference: bool) -> Type { - self.general_visitor.visit_unit(is_child_of_reference) - } - - fn visit_proxy_type(&mut self, proxy_type: &ProxyType, is_child_of_reference: bool) -> Type { - self.general_visitor - .visit_proxy_type(proxy_type, is_child_of_reference) - } - - fn visit_type(&mut self, _type: &Type, is_child_of_reference: bool) -> Type { - self.general_visitor - .visit_type(_type, is_child_of_reference) - } - - fn visit_unit_path(&mut self, unit_path: &UnitPath, is_child_of_reference: bool) -> Type { - self.general_visitor - .visit_unit_path(unit_path, is_child_of_reference) - } - - fn visit_duo_path(&mut self, duo_path: &DuoPath, is_child_of_reference: bool) -> Type { - // this will only trigger for top level types, the deeper nesting is handled by the general visitor - // outer Result needs to be converted to Result when converting to a proxy_type - let tealr = quote!(bevy_mod_scripting_lua::tealr); - - if duo_path - .std_type_ident - .is_some_and(|i| i == StdTypeIdent::Result) - && self.general_visitor.generate_proxy_type - { - let ident = &duo_path.ident; - let lt_token = duo_path.lt_token; - let gt_token = duo_path.gt_token; - let left = self.visit_simple_type(&duo_path.left, false); - parse_quote!(#ident #lt_token #left, #tealr::mlu::mlua::Error #gt_token) - } else { - self.general_visitor - .visit_duo_path(duo_path, is_child_of_reference) - } - } - - fn visit_reference( - &mut self, - reference: &bevy_mod_scripting_common::input::Reference, - is_child_of_reference: bool, - ) -> Type { - self.general_visitor - .visit_reference(reference, is_child_of_reference) - } -} - -#[cfg(test)] -mod test { - use std::collections::HashMap; - - use crate::visitor::LuaSimpleTypeArgumentUnwrapper; - - use super::LuaSimpleTypeWrapper; - use bevy_mod_scripting_common::input::{SimpleType, VisitSimpleType}; - use proc_macro2::Span; - use quote::*; - use syn::parse_quote; - - #[test] - pub fn test_lua_argument_wrapper_simple_proxy() { - let expected = quote_spanned!(Span::call_site()=> - LuaMyType::new(arg) - ); - - let mut visitor = LuaSimpleTypeWrapper::new(format_ident!("arg"), Span::call_site()); - - let output = visitor - .visit( - &SimpleType::new_from_fully_specified_type( - "Lua", - &parse_quote!(MyType), - &HashMap::from_iter([(format_ident!("MyType"), None)]), - ) - .unwrap(), - ) - .unwrap(); - - assert_eq!(output.to_string(), expected.to_string()) - } - - #[test] - pub fn test_lua_argument_wrapper_non_proxy() { - let expected = quote_spanned!(Span::call_site()=> - arg - ); - - let mut visitor = LuaSimpleTypeWrapper::new(format_ident!("arg"), Span::call_site()); - - let output = visitor - .visit( - &SimpleType::new_from_fully_specified_type( - "Lua", - &parse_quote!(MyType), - &HashMap::from_iter([]), - ) - .unwrap(), - ) - .unwrap(); - - assert_eq!(output.to_string(), expected.to_string()) - } - - #[test] - pub fn test_lua_argument_wrapper_vec() { - let expected = quote_spanned!(Span::call_site()=> - arg.into_iter().map(|mut arg| LuaMyType::new(arg)).collect::>() - ); - - let mut visitor = LuaSimpleTypeWrapper::new(format_ident!("arg"), Span::call_site()); - - let output = visitor - .visit( - &SimpleType::new_from_fully_specified_type( - "Lua", - &parse_quote!(Vec), - &HashMap::from_iter([(format_ident!("MyType"), None)]), - ) - .unwrap(), - ) - .unwrap(); - - assert_eq!(output.to_string(), expected.to_string()) - } - - #[test] - pub fn test_lua_argument_unwrapper_simple_proxy() { - let expected = quote_spanned!(Span::call_site()=> - arg.inner()? - ); - - let mut visitor = - LuaSimpleTypeArgumentUnwrapper::new(format_ident!("arg"), Span::call_site()); - - let output = visitor - .visit( - &SimpleType::new_from_fully_specified_type( - "Lua", - &parse_quote!(MyType), - &HashMap::from_iter([(format_ident!("MyType"), None)]), - ) - .unwrap(), - ) - .unwrap(); - - assert_eq!(output.to_string(), expected.to_string()) - } - - #[test] - pub fn test_lua_argument_unwrapper_non_proxy() { - let expected = quote_spanned!(Span::call_site()=> - arg - ); - - let mut visitor = - LuaSimpleTypeArgumentUnwrapper::new(format_ident!("arg"), Span::call_site()); - - let output = visitor - .visit( - &SimpleType::new_from_fully_specified_type( - "Lua", - &parse_quote!(MyType), - &HashMap::from_iter([]), - ) - .unwrap(), - ) - .unwrap(); - - assert_eq!(output.to_string(), expected.to_string()) - } - - #[test] - pub fn test_lua_argument_unwrapper_vec() { - let expected = quote_spanned!(Span::call_site()=> - arg.into_iter().map(|arg| Ok(arg.inner()?)).collect::, bevy_mod_scripting_lua::tealr::mlu::mlua::Error>>()? - ); - - let mut visitor = - LuaSimpleTypeArgumentUnwrapper::new(format_ident!("arg"), Span::call_site()); - - let output = visitor - .visit( - &SimpleType::new_from_fully_specified_type( - "Lua", - &parse_quote!(Vec), - &HashMap::from_iter([(format_ident!("MyType"), None)]), - ) - .unwrap(), - ) - .unwrap(); - - assert_eq!(output.to_string(), expected.to_string()) - } -} diff --git a/crates/languages/bevy_mod_scripting_rhai/src/assets.rs b/crates/languages/bevy_mod_scripting_rhai/src/assets.rs deleted file mode 100644 index 4470cf59..00000000 --- a/crates/languages/bevy_mod_scripting_rhai/src/assets.rs +++ /dev/null @@ -1,44 +0,0 @@ -use bevy::{ - asset::{io::Reader, Asset, AssetLoader, AsyncReadExt, LoadContext}, - reflect::TypePath, -}; - -use bevy_mod_scripting_core::prelude::*; - -#[derive(Asset, Debug, TypePath)] -/// A rhai code file in bytes -pub struct RhaiFile { - pub bytes: Vec, -} - -impl CodeAsset for RhaiFile { - fn bytes(&self) -> &[u8] { - self.bytes.as_slice() - } -} - -#[derive(Default)] -/// Asset loader for lua scripts -pub struct RhaiLoader; - -impl AssetLoader for RhaiLoader { - type Asset = RhaiFile; - type Settings = (); - type Error = anyhow::Error; - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _: &'a Self::Settings, - _: &'a mut LoadContext, - ) -> bevy::asset::BoxedFuture<'a, Result> { - Box::pin(async move { - let mut bytes = Vec::new(); - reader.read_to_end(&mut bytes).await?; - Ok(RhaiFile { bytes }) - }) - } - - fn extensions(&self) -> &[&str] { - &["rhai"] - } -} diff --git a/crates/languages/bevy_mod_scripting_rhai/src/docs.rs b/crates/languages/bevy_mod_scripting_rhai/src/docs.rs deleted file mode 100644 index 6fd312fe..00000000 --- a/crates/languages/bevy_mod_scripting_rhai/src/docs.rs +++ /dev/null @@ -1,17 +0,0 @@ -use bevy_mod_scripting_core::prelude::*; - -pub struct RhaiDocFragment; - -impl DocFragment for RhaiDocFragment { - fn merge(self, _o: Self) -> Self { - todo!() - } - - fn gen_docs(self) -> Result<(), ScriptError> { - todo!() - } - - fn name(&self) -> &'static str { - todo!() - } -} diff --git a/crates/languages/bevy_mod_scripting_rhai/src/lib.rs b/crates/languages/bevy_mod_scripting_rhai/src/lib.rs index cbb0eb16..fef8ede4 100644 --- a/crates/languages/bevy_mod_scripting_rhai/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_rhai/src/lib.rs @@ -1,202 +1,350 @@ -use crate::{ - assets::{RhaiFile, RhaiLoader}, - docs::RhaiDocFragment, +use bevy::{ + app::Plugin, + ecs::{entity::Entity, world::World}, }; -use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; -use bevy_mod_scripting_core::{prelude::*, systems::*, world::WorldPointerGuard}; -use rhai::*; -use std::marker::PhantomData; +use bevy_mod_scripting_core::{ + bindings::WorldCallbackAccess, + context::{ContextAssigner, ContextBuilder, ContextInitializer, ContextPreHandlingInitializer}, + error::ScriptError, + event::CallbackLabel, + handler::Args, + script::ScriptId, + ScriptingPlugin, +}; +use rhai::{CallFnOptions, Engine, FnPtr, FuncArgs, Scope, AST}; -pub mod assets; -pub mod docs; pub use rhai; pub mod prelude { - pub use crate::{ - assets::{RhaiFile, RhaiLoader}, - docs::RhaiDocFragment, - RhaiContext, RhaiEvent, RhaiScriptHost, - }; pub use rhai; - pub use rhai::{Engine, FuncArgs}; + pub use rhai::FuncArgs; } -#[derive(Resource)] -pub struct RhaiScriptHost { - pub engine: Engine, - _ph: PhantomData, +pub trait RhaiEventArg: Args + FuncArgs {} +impl RhaiEventArg for T {} + +pub type RhaiRuntime = Engine; + +pub struct RhaiScriptContext { + pub ast: AST, + pub scope: Scope<'static>, } -#[allow(deprecated)] -impl Default for RhaiScriptHost { +pub struct RhaiScriptingPlugin { + pub scripting_plugin: ScriptingPlugin, +} + +impl Default for RhaiScriptingPlugin { fn default() -> Self { - let mut e = Engine::new(); - // prevent shadowing of `state`,`world` and `entity` in variable in scripts - e.on_def_var(|_, info, _| { - Ok(info.name() != "state" && info.name() != "world" && info.name() != "entity") - }); - - Self { - engine: e, - _ph: Default::default(), + RhaiScriptingPlugin { + scripting_plugin: ScriptingPlugin { + runtime_builder: Some(RhaiRuntime::new), + callback_handler: Some(rhai_callback_handler::), + context_assigner: None, + context_builder: Some(ContextBuilder { + load: rhai_context_load, + reload: rhai_context_reload, + }), + }, } } } -pub struct RhaiContext { - pub ast: AST, - pub scope: Scope<'static>, +impl Plugin for RhaiScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + self.scripting_plugin.build(app); + } } -#[derive(Clone, Event)] -/// A Rhai Hook. The result of creating this event will be -/// a call to the lua script with the hook_name and the given arguments -pub struct RhaiEvent { - pub hook_name: String, - pub args: A, - pub recipients: Recipients, +pub fn rhai_context_load( + script: &ScriptId, + content: &[u8], + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + runtime: &mut RhaiRuntime, +) -> Result { + let mut ast = runtime.compile(std::str::from_utf8(content)?)?; + ast.set_source(script.to_string()); + + let mut context = RhaiScriptContext { + ast, + scope: Scope::new(), + }; + with_world(world, &mut context, |mut context| { + initializers + .iter() + .try_for_each(|init| init(script, &mut context))?; + + pre_handling_initializers + .iter() + .try_for_each(|init| init(script, Entity::from_raw(0), &mut context))?; + + runtime.eval_ast_with_scope(&mut context.scope, &context.ast)?; + // do not invoke top level statements after the first time we run the script + context.ast.clear_statements(); + + Ok(()) + })?; + Ok(context) } -impl ScriptEvent for RhaiEvent { - fn recipients(&self) -> &crate::Recipients { - &self.recipients - } +pub fn rhai_context_reload( + script: &ScriptId, + content: &[u8], + context: &mut RhaiScriptContext, + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + runtime: &mut RhaiRuntime, +) -> Result<(), ScriptError> { + *context = rhai_context_load( + script, + content, + initializers, + pre_handling_initializers, + world, + runtime, + )?; + Ok(()) } -impl ScriptHost for RhaiScriptHost { - type ScriptContext = RhaiContext; - type ScriptEvent = RhaiEvent; - type ScriptAsset = RhaiFile; - type APITarget = Engine; - type DocTarget = RhaiDocFragment; - - fn register_with_app_in_set( - app: &mut bevy::prelude::App, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) { - app.add_priority_event::() - .init_asset::() - .init_asset_loader::() - .init_resource::>() - .init_resource::>() - .init_resource::>() - .register_type::>() - .register_type::>() - .register_type::>() - .add_systems( - schedule, - ( - script_add_synchronizer::, - script_remove_synchronizer::, - script_hot_reload_handler::, - ) - .chain() - .in_set(set), - ) - // setup engine - .add_systems( - Startup, - |mut providers: ResMut>, mut host: ResMut| { - providers - .attach_all(&mut host.engine) - .expect("Error in adding api's for rhai"); - }, - ); - } +#[allow(clippy::too_many_arguments)] +pub fn rhai_callback_handler( + args: A, + entity: Entity, + script_id: &ScriptId, + callback: &CallbackLabel, + context: &mut RhaiScriptContext, + pre_handling_initializers: &[ContextPreHandlingInitializer], + runtime: &mut RhaiRuntime, + world: &mut World, +) -> Result<(), ScriptError> { + with_world(world, context, |context| { + pre_handling_initializers + .iter() + .try_for_each(|init| init(script_id, entity, context))?; - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError> { - providers.setup_all(script_data, ctx) - } + if context + .scope + .get_value::(callback.as_ref()) + .is_none() + { + // not subscribed to this handler + return Ok(()); + }; - fn load_script( - &mut self, - script: &[u8], - script_data: &ScriptData, - _: &mut APIProviders, - ) -> Result { - let mut scope = Scope::new(); - let mut ast = self - .engine - .compile( - std::str::from_utf8(script).map_err(|e| ScriptError::FailedToLoad { - script: script_data.name.to_owned(), - msg: e.to_string(), - })?, - ) - .map_err(|e| ScriptError::SyntaxError { - script: script_data.name.to_owned(), - msg: e.to_string(), - })?; - - ast.set_source(script_data.name); - - // persistent state for scripts - scope.push("state", Map::new()); - - Ok(RhaiContext { ast, scope }) - } + // we want the call to be able to impact the scope + let options = CallFnOptions::new().rewind_scope(false); + runtime.call_fn_with_options( + options, + &mut context.scope, + &context.ast, + callback.as_ref(), + args, + )?; + Ok(()) + }) +} - fn handle_events<'a>( - &mut self, - world: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ) { - // safety: - // - we have &mut World access - // - we do not use the original reference again anywhere in this function - let world = unsafe { WorldPointerGuard::new(world) }; - - ctxs.for_each(|(fd, ctx)| { - providers - .setup_runtime_all(world.clone(), &fd, ctx) - .expect("Failed to setup script runtime"); - - for event in events.iter() { - // check if this script should handle this event - if !event.recipients().is_recipient(&fd) { - continue; - }; - - match self.engine.call_fn( - &mut ctx.scope, - &ctx.ast, - &event.hook_name, - event.args.clone(), - ) { - Ok(v) => v, - Err(e) => { - let mut world = world.write(); - let mut state: CachedScriptState = world.remove_resource().unwrap(); - - match *e { - EvalAltResult::ErrorFunctionNotFound(..) => {} - _ => { - let (_, mut error_wrt, _) = state.event_state.get_mut(&mut world); - - let error = ScriptError::RuntimeError { - script: fd.name.to_string(), - msg: e.to_string(), - }; - error!("{}", error); - error_wrt.send(ScriptErrorEvent { error }); - } - } - - world.insert_resource(state); - } - }; - } - - // executing this at the end here means we execute global statements exactly once - // all this method call does is set a variable on the AST to NONE so should not affect performance - ctx.ast.clear_statements(); - }); - } +pub fn with_world Result<(), ScriptError>>( + world: &mut World, + context: &mut RhaiScriptContext, + f: F, +) -> Result<(), ScriptError> { + WorldCallbackAccess::with_callback_access(world, |guard| { + context.scope.push("world", guard.clone()); + f(context) + }) } +// use crate::{ +// assets::{RhaiFile, RhaiLoader}, +// docs::RhaiDocFragment, +// }; +// use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; +// use bevy_mod_scripting_core::{prelude::*, systems::*}; +// use rhai::*; +// use std::marker::PhantomData; + +// pub mod assets; +// pub mod docs; +// pub use rhai; +// pub mod prelude { +// pub use crate::{ +// assets::{RhaiFile, RhaiLoader}, +// docs::RhaiDocFragment, +// RhaiContext, RhaiEvent, RhaiScriptHost, +// }; +// pub use rhai; +// pub use rhai::{RhaiRuntime, FuncArgs}; +// } + +// #[derive(Resource)] +// pub struct RhaiScriptHost { +// pub RhaiRuntime: RhaiRuntime, +// _ph: PhantomData, +// } + +// #[allow(deprecated)] +// impl Default for RhaiScriptHost { +// fn default() -> Self { +// let mut e = RhaiRuntime::new(); +// // prevent shadowing of `state`,`world` and `entity` in variable in scripts +// e.on_def_var(|_, info, _| { +// Ok(info.name() != "state" && info.name() != "world" && info.name() != "entity") +// }); + +// Self { +// RhaiRuntime: e, +// _ph: Default::default(), +// } +// } +// } + +// pub struct RhaiContext { +// pub ast: AST, +// pub scope: Scope<'static>, +// } + +// #[derive(Clone, Event)] +// /// A Rhai Hook. The result of creating this event will be +// /// a call to the lua script with the hook_name and the given arguments +// pub struct RhaiEvent { +// pub hook_name: String, +// pub args: A, +// pub recipients: Recipients, +// } + +// impl ScriptEvent for RhaiEvent { +// fn recipients(&self) -> &crate::Recipients { +// &self.recipients +// } +// } + +// impl ScriptHost for RhaiScriptHost { +// type ScriptContext = RhaiContext; +// type ScriptEvent = RhaiEvent; +// type ScriptAsset = RhaiFile; +// type APITarget = RhaiRuntime; +// type DocTarget = RhaiDocFragment; + +// fn register_with_app_in_set( +// app: &mut bevy::prelude::App, +// schedule: impl ScheduleLabel, +// set: impl SystemSet, +// ) { +// app.add_priority_event::() +// .init_asset::() +// .init_asset_loader::() +// .init_resource::>() +// .init_resource::>() +// .init_resource::>() +// .register_type::>() +// .register_type::>() +// .register_type::>() +// .add_systems( +// schedule, +// ( +// script_add_synchronizer::, +// script_remove_synchronizer::, +// script_hot_reload_handler::, +// ) +// .chain() +// .in_set(set), +// ) +// // setup RhaiRuntime +// .add_systems( +// Startup, +// |mut providers: ResMut>, mut host: ResMut| { +// providers +// .attach_all(&mut host.RhaiRuntime) +// .expect("Error in adding api's for rhai"); +// }, +// ); +// } + +// fn setup_script( +// &mut self, +// script_data: &ScriptData, +// ctx: &mut Self::ScriptContext, +// providers: &mut APIProviders, +// ) -> Result<(), ScriptError> { +// providers.setup_all(script_data, ctx) +// } + +// fn load_script( +// &mut self, +// script: &[u8], +// script_data: &ScriptData, +// _: &mut APIProviders, +// ) -> Result { +// let mut scope = Scope::new(); +// let mut ast = self +// .RhaiRuntime +// .compile( +// std::str::from_utf8(script).map_err(|e| ScriptError::FailedToLoad { +// script: script_data.name.to_owned(), +// msg: e.to_string(), +// })?, +// ) +// .map_err(|e| ScriptError::SyntaxError { +// script: script_data.name.to_owned(), +// msg: e.to_string(), +// })?; + +// ast.set_source(script_data.name); + +// // persistent state for scripts +// scope.push("state", Map::new()); + +// Ok(RhaiContext { ast, scope }) +// } + +// fn handle_events<'a>( +// &mut self, +// world: &mut World, +// events: &[Self::ScriptEvent], +// ctxs: impl Iterator, &'a mut Self::ScriptContext)>, +// _providers: &mut APIProviders, +// ) { +// ctxs.for_each(|(fd, ctx)| { +// for event in events.iter() { +// // check if this script should handle this event +// if !event.recipients().is_recipient(&fd) { +// continue; +// }; + +// match self.RhaiRuntime.call_fn( +// &mut ctx.scope, +// &ctx.ast, +// &event.hook_name, +// event.args.clone(), +// ) { +// Ok(v) => v, +// Err(e) => { +// let mut state: CachedScriptState = world.remove_resource().unwrap(); + +// match *e { +// EvalAltResult::ErrorFunctionNotFound(..) => {} +// _ => { +// let (_, mut error_wrt, _) = state.event_state.get_mut(world); + +// let error = ScriptError::RuntimeError { +// script: fd.name.to_string(), +// msg: e.to_string(), +// }; +// error!("{}", error); +// error_wrt.send(ScriptErrorEvent { error }); +// } +// } + +// world.insert_resource(state); +// } +// }; +// } + +// // executing this at the end here means we execute global statements exactly once +// // all this method call does is set a variable on the AST to NONE so should not affect performance +// ctx.ast.clear_statements(); +// }); +// } +// } diff --git a/crates/languages/bevy_mod_scripting_rhai_derive/readme.md b/crates/languages/bevy_mod_scripting_rhai_derive/readme.md deleted file mode 100644 index e058ed4f..00000000 --- a/crates/languages/bevy_mod_scripting_rhai_derive/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# bevy_mod_scripting_lua_derive - -This crate is a part of the ["bevy_mod_scripting" workspace](https://github.com/makspll/bevy_mod_scripting). \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_rhai_derive/src/lib.rs b/crates/languages/bevy_mod_scripting_rhai_derive/src/lib.rs deleted file mode 100644 index 4feb6fce..00000000 --- a/crates/languages/bevy_mod_scripting_rhai_derive/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -use proc_macro::TokenStream; - -#[proc_macro] -pub fn impl_lua_newtype(tokens: TokenStream) -> TokenStream { - // let newtype = parse_macro_input!(tokens as Newtype); - - // implementor - // .generate(newtype) - // .map_err(|e| e.to_compile_error()) - // .unwrap_or_else(core::convert::identity) - // .into() - tokens -} diff --git a/crates/languages/bevy_mod_scripting_rune/src/assets.rs b/crates/languages/bevy_mod_scripting_rune/src/assets.rs deleted file mode 100644 index 23be9f0f..00000000 --- a/crates/languages/bevy_mod_scripting_rune/src/assets.rs +++ /dev/null @@ -1,46 +0,0 @@ -use anyhow::Error; -use bevy::{ - asset::{io::Reader, Asset, AssetLoader, AsyncReadExt}, - reflect::TypePath, -}; -use bevy_mod_scripting_core::prelude::*; - -#[derive(Asset, TypePath, Debug)] -/// A loaded rune file in bytes. -pub struct RuneFile { - /// File content in bytes. - pub bytes: Vec, -} - -impl CodeAsset for RuneFile { - fn bytes(&self) -> &[u8] { - self.bytes.as_slice() - } -} - -#[derive(Default)] -/// Enables loading Rune scripts from `.rune` and `.rn` files. -pub struct RuneLoader; - -impl AssetLoader for RuneLoader { - type Asset = RuneFile; - type Settings = (); - type Error = Error; - - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _settings: &'a (), - _load_context: &'a mut bevy::asset::LoadContext, - ) -> bevy::utils::BoxedFuture<'a, Result> { - Box::pin(async move { - let mut bytes = Vec::new(); - reader.read_to_end(&mut bytes).await?; - Ok(RuneFile { bytes }) - }) - } - - fn extensions(&self) -> &[&str] { - &["rune", "rn"] - } -} diff --git a/crates/languages/bevy_mod_scripting_rune/src/docs.rs b/crates/languages/bevy_mod_scripting_rune/src/docs.rs deleted file mode 100644 index bcd7a02e..00000000 --- a/crates/languages/bevy_mod_scripting_rune/src/docs.rs +++ /dev/null @@ -1,17 +0,0 @@ -use bevy_mod_scripting_core::prelude::*; - -pub struct RuneDocFragment; - -impl DocFragment for RuneDocFragment { - fn merge(self, _o: Self) -> Self { - todo!() - } - - fn gen_docs(self) -> Result<(), ScriptError> { - todo!() - } - - fn name(&self) -> &'static str { - todo!() - } -} diff --git a/crates/languages/bevy_mod_scripting_rune/src/lib.rs b/crates/languages/bevy_mod_scripting_rune/src/lib.rs index 4c7dc065..93e799be 100644 --- a/crates/languages/bevy_mod_scripting_rune/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_rune/src/lib.rs @@ -1,271 +1,291 @@ -use std::{marker::PhantomData, sync::Arc}; +use std::sync::Arc; -use bevy::prelude::*; -use bevy_mod_scripting_core::{ - prelude::*, - systems::{self, CachedScriptState}, - world::{WorldPointer, WorldPointerGuard}, -}; -use prelude::{RuneDocFragment, RuneFile, RuneLoader}; +use bevy_mod_scripting_core::ScriptingPlugin; use rune::{ - runtime::{Args, RuntimeContext, VmError, VmResult}, - Context, Diagnostics, Source, Sources, Unit, Vm, + runtime::{Args, RuntimeContext}, + Unit, Vm, }; -mod assets; -mod docs; - -pub mod prelude { - pub use crate::{ - assets::{RuneFile, RuneLoader}, - docs::RuneDocFragment, - RuneArgs, RuneEvent, RuneScriptContext, RuneScriptHost, - }; - pub use rune::{self, runtime::Args, Context}; -} - -/// Super trait adding additional bounds to Rune's `Args` trait. -/// It's gets automatically implemented for any type that implments `Args`, -/// so you should never have to manually implement it. -pub trait RuneArgs: Args + Clone + Send + Sync + 'static {} - -impl RuneArgs for T {} - -/// A Rune script hook. -#[derive(Debug, Clone, Event)] -pub struct RuneEvent { - /// The name of the Rune function to call. - pub hook_name: String, - /// The arguments to supply the function being invoked. If you - /// don't need any arguments, `()` is a good default value. - pub args: A, - /// The target set of scripts that should handle this event. - pub recipients: Recipients, -} - -impl ScriptEvent for RuneEvent { - fn recipients(&self) -> &Recipients { - &self.recipients - } -} - -/// A cached Rune Vm used to execute units. -struct RuneVm(Vm); +pub trait RuneEventArg: Args + Clone + Send + Sync + 'static {} +impl RuneEventArg for T {} -impl Default for RuneVm { - fn default() -> Self { - Self(Vm::new( - Arc::new(RuntimeContext::default()), - Arc::new(Unit::default()), - )) - } -} - -/// Script context for a rune script. pub struct RuneScriptContext { pub unit: Arc, pub runtime_context: Arc, } -#[derive(Resource)] -/// Rune script host. Enables Rune scripting. -pub struct RuneScriptHost { - _ph: PhantomData, +pub type RuneRuntime = Vm; + +pub struct RuneScriptingPlugin { + pub scripting_plugin: ScriptingPlugin, } -impl Default for RuneScriptHost { +impl Default for RuneScriptingPlugin { fn default() -> Self { Self { - _ph: Default::default(), + scripting_plugin: ScriptingPlugin { + runtime_builder: todo!(), + callback_handler: todo!(), + context_builder: todo!(), + context_assigner: todo!(), + }, } } } -impl RuneScriptHost { - /// Helper function to handle errors from a Rune virtual machine. - /// - #[cold] - fn handle_rune_error(world: WorldPointer, error: VmError, script_data: &ScriptData<'_>) { - let mut world = world.write(); - let mut state: CachedScriptState = world.remove_resource().unwrap(); - - let (_, mut error_wrt, _) = state.event_state.get_mut(&mut world); - - let error = ScriptError::RuntimeError { - script: script_data.name.to_owned(), - msg: error.to_string(), - }; - - error!("{}", error); - - error_wrt.send(ScriptErrorEvent { error }); - world.insert_resource(state); - } -} - -impl ScriptHost for RuneScriptHost { - type ScriptContext = RuneScriptContext; - - type ScriptEvent = RuneEvent; - - type ScriptAsset = RuneFile; - - type APITarget = Context; - - type DocTarget = RuneDocFragment; - - fn register_with_app_in_set( - app: &mut App, - schedule: impl bevy::ecs::schedule::ScheduleLabel, - set: impl SystemSet, - ) { - app.add_priority_event::() - .init_asset::() - .init_asset_loader::() - .init_resource::>() - .init_resource::>() - .init_resource::>() - .register_type::>() - .register_type::>() - .register_type::>() - // Add a cached Vm as a non-send resource. - .insert_non_send_resource(RuneVm::default()) - // handle script insertions removal first - // then update their contexts later on script asset changes - .add_systems( - schedule, - ( - systems::script_add_synchronizer::, - systems::script_remove_synchronizer::, - systems::script_hot_reload_handler::, - ) - .chain() - .in_set(set), - ); - } - - fn load_script( - &mut self, - script: &[u8], - script_data: &ScriptData, - providers: &mut APIProviders, - ) -> Result { - let mut context = rune_modules::default_context().map_err(ScriptError::new_other)?; - - // Rune requires that we tell it what modules and types we'll be using before - // it compiles a file. - providers.attach_all(&mut context).unwrap(); - - let mut diagnostics = Diagnostics::new(); - - let mut sources = Sources::new(); - sources - .insert( - Source::new( - script_data.name, - std::str::from_utf8(script).expect("Slice is not UTF-8"), - ) - .map_err(|msg| ScriptError::FailedToLoad { - script: script_data.name.into(), - msg: msg.to_string(), - })?, - ) - .map_err(|msg| ScriptError::FailedToLoad { - script: script_data.name.into(), - msg: msg.to_string(), - })?; - - let result = rune::prepare(&mut sources) - .with_context(&context) - .with_diagnostics(&mut diagnostics) - .build(); - - if !diagnostics.is_empty() { - let mut writer = rune::termcolor::Buffer::no_color(); - - diagnostics - .emit(&mut writer, &sources) - .expect("Failed to write diagnostics to buffer"); - - return Err(ScriptError::SyntaxError { - script: script_data.name.into(), - msg: std::str::from_utf8(writer.as_slice()) - .expect("Slice was not UTF-8") - .to_owned(), - }); - } - - let unit = result.expect("Failed to build Rune unit."); - - let runtime_ctx = context - .runtime() - .expect("Failed to create Rune runtime context."); - - Ok(RuneScriptContext { - unit: Arc::new(unit), - runtime_context: Arc::new(runtime_ctx), - }) - } - - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError> { - providers.setup_all(script_data, ctx) - } - - fn handle_events<'a>( - &mut self, - world: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ) { - // Grab the cached Vm. - let RuneVm(mut vm) = world.remove_non_send_resource::().unwrap(/* invariant */); - - { - // Safety: - // - we have &mut World access - // - we do not use the original reference again anywhere in this block. - // - the guard is dropped at the end of this block. - let world = unsafe { WorldPointerGuard::new(world) }; - - ctxs.for_each(|(script_data, ctx)| { - providers - .setup_runtime_all(world.clone(), &script_data, ctx) - .expect("Could not setup script runtime"); - - for event in events { - if !event.recipients().is_recipient(&script_data) { - continue; - } - - // Swap out the old context and old unit with the new ones. - *vm.context_mut() = Arc::clone(&ctx.runtime_context); - *vm.unit_mut() = Arc::clone(&ctx.unit); - - let mut exec = match vm.execute([event.hook_name.as_str()], event.args.clone()) - { - Ok(exec) => exec, - Err(error) => { - Self::handle_rune_error(world.clone(), error, &script_data); - continue; - } - }; - - if let VmResult::Err(error) = exec.complete() { - Self::handle_rune_error(world.clone(), error, &script_data); - } - } - }); - - // explictly release the pointer to world. - drop(world); - } - - world.insert_non_send_resource(RuneVm(vm)); - } -} +// use std::{marker::PhantomData, sync::Arc}; + +// use bevy::prelude::*; +// use bevy_mod_scripting_core::{ +// prelude::*, +// systems::{self, CachedScriptState}, +// }; +// use prelude::{RuneDocFragment, RuneFile, RuneLoader}; +// use rune::{ +// runtime::{Args, RuntimeContext, VmError, VmResult}, +// Context, Diagnostics, Source, Sources, Unit, Vm, +// }; + +// mod assets; +// mod docs; + +// pub mod prelude { +// pub use crate::{ +// assets::{RuneFile, RuneLoader}, +// docs::RuneDocFragment, +// RuneArgs, RuneEvent, RuneScriptContext, RuneScriptHost, +// }; +// pub use rune::{self, runtime::Args, Context}; +// } + +// /// Super trait adding additional bounds to Rune's `Args` trait. +// /// It's gets automatically implemented for any type that implments `Args`, +// /// so you should never have to manually implement it. +// pub trait RuneArgs: Args + Clone + Send + Sync + 'static {} + +// impl RuneArgs for T {} + +// /// A Rune script hook. +// #[derive(Debug, Clone, Event)] +// pub struct RuneEvent { +// /// The name of the Rune function to call. +// pub hook_name: String, +// /// The arguments to supply the function being invoked. If you +// /// don't need any arguments, `()` is a good default value. +// pub args: A, +// /// The target set of scripts that should handle this event. +// pub recipients: Recipients, +// } + +// impl ScriptEvent for RuneEvent { +// fn recipients(&self) -> &Recipients { +// &self.recipients +// } +// } + +// /// A cached Rune Vm used to execute units. +// struct RuneVm(Vm); + +// impl Default for RuneVm { +// fn default() -> Self { +// Self(Vm::new( +// Arc::new(RuntimeContext::default()), +// Arc::new(Unit::default()), +// )) +// } +// } + +// /// Script context for a rune script. +// pub struct RuneScriptContext { +// pub unit: Arc, +// pub runtime_context: Arc, +// } + +// #[derive(Resource)] +// /// Rune script host. Enables Rune scripting. +// pub struct RuneScriptHost { +// _ph: PhantomData, +// } + +// impl Default for RuneScriptHost { +// fn default() -> Self { +// Self { +// _ph: Default::default(), +// } +// } +// } + +// impl RuneScriptHost { +// /// Helper function to handle errors from a Rune virtual machine. +// /// +// #[cold] +// fn handle_rune_error(world: &mut World, error: VmError, script_data: &ScriptData<'_>) { +// let mut state: CachedScriptState = world.remove_resource().unwrap(); + +// let (_, mut error_wrt, _) = state.event_state.get_mut(world); + +// let error = ScriptError::RuntimeError { +// script: script_data.name.to_owned(), +// msg: error.to_string(), +// }; + +// error!("{}", error); + +// error_wrt.send(ScriptErrorEvent { error }); +// world.insert_resource(state); +// } +// } + +// impl ScriptHost for RuneScriptHost { +// type ScriptContext = RuneScriptContext; + +// type ScriptEvent = RuneEvent; + +// type ScriptAsset = RuneFile; + +// type APITarget = Context; + +// type DocTarget = RuneDocFragment; + +// fn register_with_app_in_set( +// app: &mut App, +// schedule: impl bevy::ecs::schedule::ScheduleLabel, +// set: impl SystemSet, +// ) { +// app.add_priority_event::() +// .init_asset::() +// .init_asset_loader::() +// .init_resource::>() +// .init_resource::>() +// .init_resource::>() +// .register_type::>() +// .register_type::>() +// .register_type::>() +// // Add a cached Vm as a non-send resource. +// .insert_non_send_resource(RuneVm::default()) +// // handle script insertions removal first +// // then update their contexts later on script asset changes +// .add_systems( +// schedule, +// ( +// systems::script_add_synchronizer::, +// systems::script_remove_synchronizer::, +// systems::script_hot_reload_handler::, +// ) +// .chain() +// .in_set(set), +// ); +// } + +// fn load_script( +// &mut self, +// script: &[u8], +// script_data: &ScriptData, +// providers: &mut APIProviders, +// ) -> Result { +// let mut context = rune_modules::default_context().map_err(ScriptError::new_other)?; + +// // Rune requires that we tell it what modules and types we'll be using before +// // it compiles a file. +// providers.attach_all(&mut context).unwrap(); + +// let mut diagnostics = Diagnostics::new(); + +// let mut sources = Sources::new(); +// sources +// .insert( +// Source::new( +// script_data.name, +// std::str::from_utf8(script).expect("Slice is not UTF-8"), +// ) +// .map_err(|msg| ScriptError::FailedToLoad { +// script: script_data.name.into(), +// msg: msg.to_string(), +// })?, +// ) +// .map_err(|msg| ScriptError::FailedToLoad { +// script: script_data.name.into(), +// msg: msg.to_string(), +// })?; + +// let result = rune::prepare(&mut sources) +// .with_context(&context) +// .with_diagnostics(&mut diagnostics) +// .build(); + +// if !diagnostics.is_empty() { +// let mut writer = rune::termcolor::Buffer::no_color(); + +// diagnostics +// .emit(&mut writer, &sources) +// .expect("Failed to write diagnostics to buffer"); + +// return Err(ScriptError::SyntaxError { +// script: script_data.name.into(), +// msg: std::str::from_utf8(writer.as_slice()) +// .expect("Slice was not UTF-8") +// .to_owned(), +// }); +// } + +// let unit = result.expect("Failed to build Rune unit."); + +// let runtime_ctx = context +// .runtime() +// .expect("Failed to create Rune runtime context."); + +// Ok(RuneScriptContext { +// unit: Arc::new(unit), +// runtime_context: Arc::new(runtime_ctx), +// }) +// } + +// fn setup_script( +// &mut self, +// script_data: &ScriptData, +// ctx: &mut Self::ScriptContext, +// providers: &mut APIProviders, +// ) -> Result<(), ScriptError> { +// providers.setup_all(script_data, ctx) +// } + +// fn handle_events<'a>( +// &mut self, +// world: &mut World, +// events: &[Self::ScriptEvent], +// ctxs: impl Iterator, &'a mut Self::ScriptContext)>, +// _providers: &mut APIProviders, +// ) { +// // Grab the cached Vm. +// let RuneVm(mut vm) = world.remove_non_send_resource::().unwrap(/* invariant */); + +// { +// ctxs.for_each(|(script_data, ctx)| { +// for event in events { +// if !event.recipients().is_recipient(&script_data) { +// continue; +// } + +// // Swap out the old context and old unit with the new ones. +// *vm.context_mut() = Arc::clone(&ctx.runtime_context); +// *vm.unit_mut() = Arc::clone(&ctx.unit); + +// let mut exec = match vm.execute([event.hook_name.as_str()], event.args.clone()) +// { +// Ok(exec) => exec, +// Err(error) => { +// Self::handle_rune_error(world, error, &script_data); +// continue; +// } +// }; + +// if let VmResult::Err(error) = exec.complete() { +// Self::handle_rune_error(world, error, &script_data); +// } +// } +// }); +// } + +// world.insert_non_send_resource(RuneVm(vm)); +// } +// } diff --git a/examples/lua/event_recipients.rs b/examples/lua/event_recipients.rs index 3a8a75e1..2d4272f5 100644 --- a/examples/lua/event_recipients.rs +++ b/examples/lua/event_recipients.rs @@ -1,134 +1,71 @@ -use bevy::prelude::*; +use bevy::{app::AppExit, core::FrameCount, prelude::*}; use bevy_mod_scripting::prelude::*; -use rand::prelude::SliceRandom; -use std::sync::atomic::Ordering::Relaxed; -use std::sync::{atomic::AtomicU32, Mutex}; - -#[derive(Clone)] -pub struct MyLuaArg(usize); - -impl<'lua> IntoLua<'lua> for MyLuaArg { - fn into_lua(self, lua: &'lua Lua) -> mlua::Result> { - self.0.into_lua(lua) - } -} - -#[derive(Default)] -pub struct LuaAPIProvider; - -/// the custom Lua api, world is provided via a global pointer, -/// and callbacks are defined only once at script creation -impl APIProvider for LuaAPIProvider { - type APITarget = Mutex; - type DocTarget = LuaDocFragment; - type ScriptContext = Mutex; - - fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), ScriptError> { - // callbacks can receive any `ToLuaMulti` arguments, here '()' and - // return any `FromLuaMulti` arguments, here a `usize` - // check the Rlua documentation for more details - - let ctx = ctx.get_mut().unwrap(); - - ctx.globals() - .set( - "print", - ctx.create_function(|_ctx, msg: String| { - info!("{}", msg); - Ok(()) - }) - .map_err(ScriptError::new_other)?, - ) - .map_err(ScriptError::new_other)?; - - Ok(()) - } - - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - let ctx = ctx.get_mut().unwrap(); - let globals = ctx.globals(); - globals - .set("script_id", script_data.sid) - .map_err(ScriptError::new_other)?; - Ok(()) - } +use bevy_mod_scripting_core::{ + asset::ScriptAsset, script::ScriptComponent, AddContextPreHandlingInitializer, +}; + +fn load_script( + server: Res, + mut commands: Commands, + mut handle: Local>, +) { + let path = "scripts/event_recipients.lua"; + let handle_ = server.load::(path); + *handle = handle_; + + commands.spawn(ScriptComponent::new(vec![ + "scripts/event_recipients.lua".into() + ])); + commands.spawn(ScriptComponent::new(vec![ + "scripts/event_recipients.lua".into() + ])); } -static COUNTER: AtomicU32 = AtomicU32::new(0); - -/// utility for generating random events from a list -fn fire_random_event(w: &mut PriorityEventWriter>, events: &[ScriptEventData]) { - let mut rng = rand::thread_rng(); - let id = COUNTER.fetch_add(1, Relaxed); - let arg = MyLuaArg(id as usize); - let event = events - .choose(&mut rng) - .map(|v| LuaEvent { - hook_name: v.0.to_string(), - args: arg, - recipients: v.1.clone(), - }) - .unwrap(); - - info!( - "\t - event: {},\t recipients: {:?},\t id: {}", - event.hook_name, event.recipients, id - ); - w.send(event, 0); +fn trigger_script_callback(mut writer: EventWriter>) { + writer.send(ScriptCallbackEvent::new_for_all( + OnEventCallback::into_callback_label(), + 1, + )); + + writer.send(ScriptCallbackEvent::new( + OnEventCallback::into_callback_label(), + 2, + Recipients::Entity(Entity::from_raw(1)), + )); } -fn do_update(mut w: PriorityEventWriter>) { - info!("Update, firing:"); - - let all_events = [ - ScriptEventData("on_event", Recipients::All), - ScriptEventData("on_event", Recipients::ScriptID(0)), - ScriptEventData("on_event", Recipients::ScriptID(1)), - ScriptEventData( - "on_event", - Recipients::ScriptName("scripts/event_recipients.lua".to_owned()), - ), - ]; - - // fire random event, for any of the system sets - fire_random_event(&mut w, &all_events); +fn quit_after_few_frames(mut exit: EventWriter, count: Res) { + if count.0 > 5 { + exit.send(AppExit); + } } -#[derive(Clone)] -pub struct ScriptEventData(&'static str, Recipients); - -fn load_our_scripts(server: Res, mut commands: Commands) { - // spawn two identical scripts - // id's will be 0 and 1 - let path = "scripts/event_recipients.lua"; - let handle = server.load::(path); - let scripts = (0..2) - .map(|_| Script::::new(path.to_string(), handle.clone())) - .collect(); - - commands - .spawn(()) - .insert(ScriptCollection:: { scripts }); +pub struct OnEventCallback; +impl IntoCallbackLabel for OnEventCallback { + fn into_callback_label() -> CallbackLabel { + "on_event".into() + } } fn main() -> std::io::Result<()> { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .add_plugins(ScriptingPlugin) - .add_systems(Startup, load_our_scripts) - // randomly fire events for either all scripts, - // the script with id 0 - // or the script with id 1 - .add_systems(Update, do_update) - .add_script_handler::, 0, 0>(PostUpdate) - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(LuaAPIProvider)); - app.run(); + .add_plugins(LuaScriptingPlugin::::default()) + .add_context_pre_handling_initializer(|_, e, ctx: &mut Lua| { + ctx.globals().set("entity", format!("{e:?}")).unwrap(); + Ok(()) + }) + .add_systems(Startup, load_script) + .add_systems( + Update, + ( + trigger_script_callback, + event_handler::.after(trigger_script_callback), + quit_after_few_frames, + ), + ) + .run(); Ok(()) } diff --git a/makefile b/makefile index 2a39b284..c6f8a493 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,7 @@ CODEGEN_PATH=${PWD}/target/codegen BEVY_PATH=${CODEGEN_PATH}/bevy GLAM_PATH=${CODEGEN_PATH}/glam OUTPUT_PATH=${CODEGEN_PATH}/output -GENERATED_SRC_PATH=./crates/bevy_script_api/src/providers +GENERATED_SRC_PATH=./crates/languages/bevy_mod_scripting_lua/src/bindings/providers GEN_BEVY_FEATURES=bevy_asset,bevy_gltf,bevy_animation,bevy_core_pipeline,bevy_ui,bevy_pbr,bevy_render,bevy_text,bevy_sprite,file_watcher,multi-threaded build_test_in_package: @@ -46,8 +46,10 @@ valgrind: --simulate-cache=yes \ ${EXEC} --bench ${T_ID} -install_bevy_api_gen: +install_nightly: rustup install ${NIGHTLY_VERSION} + +install_bevy_api_gen: cargo +${NIGHTLY_VERSION} install --path ./crates/bevy_api_gen prepare_api_gen: @@ -60,10 +62,10 @@ clean_bevy: cd ${BEVY_PATH} && cargo clean generate_bevy: - cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen generate --output ${OUTPUT_PATH} --template-args '{ "self_is_bevy_script_api": true}' --features ${GEN_BEVY_FEATURES} + cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen generate --output ${OUTPUT_PATH} --template-args '{ "self_is_bms_lua": true}' --features ${GEN_BEVY_FEATURES} collect_bevy: - cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen collect --output ${OUTPUT_PATH} --template-args '{ "self_is_bevy_script_api": true}' + cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen collect --output ${OUTPUT_PATH} --template-args '{ "self_is_bms_lua": true}' deletion_confirmation: @echo -n "This action will delete ALL files in directories: '${GENERATED_SRC_PATH}' amd ${OUTPUT_PATH} (y/N) " diff --git a/src/documentation/main.rs b/src/documentation/main.rs index d7802bea..f210b0bc 100644 --- a/src/documentation/main.rs +++ b/src/documentation/main.rs @@ -6,7 +6,7 @@ fn main() { let args: Vec = env::args().collect(); let mut app = App::new(); app.add_plugins(MinimalPlugins) - .add_plugins(ScriptingPlugin) + // .add_plugins(ScriptingPlugin) .add_plugins(AssetPlugin::default()); static INVALID_ARGUMENT_WARNING: &str = "Expected one of: 'lua','rhai' as arguments"; diff --git a/src/lib.rs b/src/lib.rs index 82d53079..a4f7c1bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ pub mod rhai { #[cfg(feature = "rhai_script_api")] pub mod api { - pub use bevy_script_api::rhai::*; + // pub use bevy_script_api::rhai::*; } } @@ -40,11 +40,11 @@ pub mod prelude { #[cfg(feature = "lua")] pub use bevy_mod_scripting_lua::prelude::*; - #[cfg(feature = "rhai")] - pub use bevy_mod_scripting_rhai::prelude::*; + // #[cfg(feature = "rhai")] + // pub use bevy_mod_scripting_rhai::prelude::*; - #[cfg(feature = "rune")] - pub use bevy_mod_scripting_rune::prelude::*; + // #[cfg(feature = "rune")] + // pub use bevy_mod_scripting_rune::prelude::*; #[cfg(any(feature = "lua_script_api", feature = "rhai_script_api"))] pub use bevy_script_api::prelude::*;