Skip to content

Commit

Permalink
allow optionally disabling bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Jan 2, 2025
1 parent 4872759 commit 7ee53aa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ path = "src/lib.rs"
features = ["lua", "lua54", "rhai", "rune"]

[features]
default = ["core_functions", "bevy_bindings", "unsafe_lua_modules"]

## core
doc_always = ["bevy_mod_scripting_core/doc_always"]

Expand All @@ -38,6 +40,10 @@ luajit = ["bevy_mod_scripting_lua/luajit", "lua"]
luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"]
luau = ["bevy_mod_scripting_lua/luau", "lua"]

# bindings
core_functions = ["bevy_mod_scripting_functions/core_functions"]
bevy_bindings = ["bevy_mod_scripting_functions/bevy_bindings"]

# optional
unsafe_lua_modules = ["bevy_mod_scripting_lua/unsafe_lua_modules"]
mlua_serialize = ["bevy_mod_scripting_lua/mlua_serialize"]
Expand All @@ -62,7 +68,7 @@ bevy_mod_scripting_functions = { workspace = true }
bevy = { version = "0.15.0", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.0-alpha.1" }
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.9.0-alpha.1" }
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.0-alpha.1" }
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.0-alpha.1"}
test_utils = { path = "crates/test_utils" }
mlua = { version = "0.10" }

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_mod_scripting_functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ categories = ["game-development"]
readme = "readme.md"

[features]

core_functions = []
bevy_bindings = []


[dependencies]
Expand Down
35 changes: 29 additions & 6 deletions crates/bevy_mod_scripting_functions/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ use bindings::{
use error::{InteropError, InteropErrorInner};
use reflection_extensions::{PartialReflectExt, TypeIdExtensions};

use crate::{bevy_bindings::LuaBevyScriptingPlugin, namespaced_register::NamespaceBuilder};
use crate::{namespaced_register::NamespaceBuilder};


pub fn register_bevy_bindings(app: &mut App) {
app.add_plugins(LuaBevyScriptingPlugin);
#[cfg(feature = "bevy_bindings")]
app.add_plugins(crate::bevy_bindings::LuaBevyScriptingPlugin);
}

pub fn register_world_functions(reg: &mut World) -> Result<(), FunctionRegistrationError> {
Expand Down Expand Up @@ -325,10 +326,6 @@ pub fn register_reflect_reference_functions(
}


trait Test: GetTypeRegistration {}

// impl Test for smol_str::SmolStr {}

pub fn register_script_type_registration_functions(
registry: &mut World,
) -> Result<(), FunctionRegistrationError> {
Expand Down Expand Up @@ -389,3 +386,29 @@ pub fn register_script_query_result_functions(
});
Ok(())
}

pub fn register_core_functions(app: &mut App) {
let world = app.world_mut();
// we don't exclude from compilation here,
// since these are much smaller and still useful if not included initially
// perhaps people might want to include some but not all of these

#[cfg(feature="core_functions")]
register_world_functions(world).expect("Failed to register world functions");

#[cfg(feature="core_functions")]
register_reflect_reference_functions(world)
.expect("Failed to register reflect reference functions");

#[cfg(feature="core_functions")]
register_script_type_registration_functions(world)
.expect("Failed to register script type registration functions");

#[cfg(feature="core_functions")]
register_script_query_builder_functions(world)
.expect("Failed to register script query builder functions");

#[cfg(feature="core_functions")]
register_script_query_result_functions(world)
.expect("Failed to register script query result functions");
}
17 changes: 2 additions & 15 deletions crates/bevy_mod_scripting_functions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ::bevy::prelude::*;
#[cfg(feature = "bevy_bindings")]
pub mod bevy_bindings;
pub mod core;

Expand All @@ -12,20 +13,6 @@ pub struct ScriptFunctionsPlugin;
impl Plugin for ScriptFunctionsPlugin {
fn build(&self, app: &mut App) {
register_bevy_bindings(app);
let world = app.world_mut();

register_world_functions(world).expect("Failed to register world functions");

register_reflect_reference_functions(world)
.expect("Failed to register reflect reference functions");

register_script_type_registration_functions(world)
.expect("Failed to register script type registration functions");

register_script_query_builder_functions(world)
.expect("Failed to register script query builder functions");

register_script_query_result_functions(world)
.expect("Failed to register script query result functions");
register_core_functions(app);
}
}
5 changes: 5 additions & 0 deletions docs/src/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ By default all of the useful features are enabled, but you may disable them if y
| ---- | ---- |
| core_functions | If enabled, will enable all core functions, i.e. bevy integrations which let you interact with Bevy via reflection |
| bevy_bindings | If enabled, populates the function registry with additiona automatically generated bevy bindings. This includes functions on `glam` and `bevy::ecs` types. These are useful but will slow down compilation considerably. |
| mlua_async | Enables `mlua/async`|
| mlua_serialize | Enables `mlua/serialize` |
| mlua_macros | Enables `mlua/macros` |
| unsafe_lua_modules | Allows loading unsafe modules via `require` in lua |


0 comments on commit 7ee53aa

Please sign in to comment.