Skip to content

Commit 7ee53aa

Browse files
committed
allow optionally disabling bindings
1 parent 4872759 commit 7ee53aa

File tree

5 files changed

+45
-23
lines changed

5 files changed

+45
-23
lines changed

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ path = "src/lib.rs"
2424
features = ["lua", "lua54", "rhai", "rune"]
2525

2626
[features]
27+
default = ["core_functions", "bevy_bindings", "unsafe_lua_modules"]
28+
2729
## core
2830
doc_always = ["bevy_mod_scripting_core/doc_always"]
2931

@@ -38,6 +40,10 @@ luajit = ["bevy_mod_scripting_lua/luajit", "lua"]
3840
luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"]
3941
luau = ["bevy_mod_scripting_lua/luau", "lua"]
4042

43+
# bindings
44+
core_functions = ["bevy_mod_scripting_functions/core_functions"]
45+
bevy_bindings = ["bevy_mod_scripting_functions/bevy_bindings"]
46+
4147
# optional
4248
unsafe_lua_modules = ["bevy_mod_scripting_lua/unsafe_lua_modules"]
4349
mlua_serialize = ["bevy_mod_scripting_lua/mlua_serialize"]
@@ -62,7 +68,7 @@ bevy_mod_scripting_functions = { workspace = true }
6268
bevy = { version = "0.15.0", default-features = false }
6369
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.0-alpha.1" }
6470
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.9.0-alpha.1" }
65-
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.0-alpha.1" }
71+
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.0-alpha.1"}
6672
test_utils = { path = "crates/test_utils" }
6773
mlua = { version = "0.10" }
6874

crates/bevy_mod_scripting_functions/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ categories = ["game-development"]
1212
readme = "readme.md"
1313

1414
[features]
15-
15+
core_functions = []
16+
bevy_bindings = []
1617

1718

1819
[dependencies]

crates/bevy_mod_scripting_functions/src/core.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ use bindings::{
2323
use error::{InteropError, InteropErrorInner};
2424
use reflection_extensions::{PartialReflectExt, TypeIdExtensions};
2525

26-
use crate::{bevy_bindings::LuaBevyScriptingPlugin, namespaced_register::NamespaceBuilder};
26+
use crate::{namespaced_register::NamespaceBuilder};
2727

2828

2929
pub fn register_bevy_bindings(app: &mut App) {
30-
app.add_plugins(LuaBevyScriptingPlugin);
30+
#[cfg(feature = "bevy_bindings")]
31+
app.add_plugins(crate::bevy_bindings::LuaBevyScriptingPlugin);
3132
}
3233

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

327328

328-
trait Test: GetTypeRegistration {}
329-
330-
// impl Test for smol_str::SmolStr {}
331-
332329
pub fn register_script_type_registration_functions(
333330
registry: &mut World,
334331
) -> Result<(), FunctionRegistrationError> {
@@ -389,3 +386,29 @@ pub fn register_script_query_result_functions(
389386
});
390387
Ok(())
391388
}
389+
390+
pub fn register_core_functions(app: &mut App) {
391+
let world = app.world_mut();
392+
// we don't exclude from compilation here,
393+
// since these are much smaller and still useful if not included initially
394+
// perhaps people might want to include some but not all of these
395+
396+
#[cfg(feature="core_functions")]
397+
register_world_functions(world).expect("Failed to register world functions");
398+
399+
#[cfg(feature="core_functions")]
400+
register_reflect_reference_functions(world)
401+
.expect("Failed to register reflect reference functions");
402+
403+
#[cfg(feature="core_functions")]
404+
register_script_type_registration_functions(world)
405+
.expect("Failed to register script type registration functions");
406+
407+
#[cfg(feature="core_functions")]
408+
register_script_query_builder_functions(world)
409+
.expect("Failed to register script query builder functions");
410+
411+
#[cfg(feature="core_functions")]
412+
register_script_query_result_functions(world)
413+
.expect("Failed to register script query result functions");
414+
}
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use ::bevy::prelude::*;
2+
#[cfg(feature = "bevy_bindings")]
23
pub mod bevy_bindings;
34
pub mod core;
45

@@ -12,20 +13,6 @@ pub struct ScriptFunctionsPlugin;
1213
impl Plugin for ScriptFunctionsPlugin {
1314
fn build(&self, app: &mut App) {
1415
register_bevy_bindings(app);
15-
let world = app.world_mut();
16-
17-
register_world_functions(world).expect("Failed to register world functions");
18-
19-
register_reflect_reference_functions(world)
20-
.expect("Failed to register reflect reference functions");
21-
22-
register_script_type_registration_functions(world)
23-
.expect("Failed to register script type registration functions");
24-
25-
register_script_query_builder_functions(world)
26-
.expect("Failed to register script query builder functions");
27-
28-
register_script_query_result_functions(world)
29-
.expect("Failed to register script query result functions");
16+
register_core_functions(app);
3017
}
3118
}

docs/src/installation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ By default all of the useful features are enabled, but you may disable them if y
4848
| ---- | ---- |
4949
| core_functions | If enabled, will enable all core functions, i.e. bevy integrations which let you interact with Bevy via reflection |
5050
| 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. |
51+
| mlua_async | Enables `mlua/async`|
52+
| mlua_serialize | Enables `mlua/serialize` |
53+
| mlua_macros | Enables `mlua/macros` |
54+
| unsafe_lua_modules | Allows loading unsafe modules via `require` in lua |
55+
5156

0 commit comments

Comments
 (0)