diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 4426f173..3763b47e 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -161,7 +161,7 @@ pub fn combine_with_exported_module(args: proc_macro::TokenStream) -> proc_macro Err(e) => return e.to_compile_error().into(), }; let tokens = quote! { - #module_path::rhai_generate_into_module(#module_expr, true); + #module_path::rhai_generate_into_module(#module_expr); }; proc_macro::TokenStream::from(tokens) } diff --git a/codegen/src/rhai_module.rs b/codegen/src/rhai_module.rs index 66f23390..1661df43 100644 --- a/codegen/src/rhai_module.rs +++ b/codegen/src/rhai_module.rs @@ -17,7 +17,7 @@ pub(crate) fn generate_body( let mut set_fn_stmts: Vec = Vec::new(); let mut set_const_stmts: Vec = Vec::new(); let mut add_mod_blocks: Vec = Vec::new(); - let mut set_flattened_mod_blocks: Vec = Vec::new(); + let mut set_mod_blocks: Vec = Vec::new(); let str_type_path = syn::parse2::(quote! { str }).unwrap(); for (const_name, const_type, const_expr) in consts { @@ -55,10 +55,10 @@ pub(crate) fn generate_body( }) .unwrap(), ); - set_flattened_mod_blocks.push( + set_mod_blocks.push( syn::parse2::(quote! { #(#cfg_attrs)* { - self::#module_name::rhai_generate_into_module(m, flatten); + self::#module_name::rhai_generate_into_module(m); } }) .unwrap(), @@ -155,6 +155,11 @@ pub(crate) fn generate_body( #(#add_mod_blocks)* } } + pub fn rhai_generate_into_module(m: &mut Module) { + #(#set_fn_stmts)* + #(#set_const_stmts)* + #(#set_mod_blocks)* + } } }) .unwrap(); diff --git a/doc/src/rust/packages/create.md b/doc/src/rust/packages/create.md index 53ac17a0..c4ee27e4 100644 --- a/doc/src/rust/packages/create.md +++ b/doc/src/rust/packages/create.md @@ -66,9 +66,6 @@ In fact, this exactly is how Rhai's built-in packages, such as `BasicMathPackage `rhai::plugins::combine_with_exported_module!` adds all functions and constants from the [plugins][plugin module] definition into the package itself. -All sub-modules are _flattened_ (i.e. all functions and constants defined within sub-modules are registered -at the top level) and so there will not be any sub-modules added to the package. - ```rust // Import necessary types and traits. use rhai::{ @@ -107,17 +104,8 @@ def_package!(rhai:MyPackage:"My own personal super package", module, { // Merge all registered functions and constants from the plugin module into the custom package. // - // Functions in the sub-module 'my_sub_module' are flattened and registered at the top level - // instead of in a sub-module. - // // The text string name in the middle parameter can be anything and is reserved for future use; // it is recommended to be an ID string that uniquely identifies the module. - // - // This call ends up registering three functions at the top level of the package: - // 1) greet - // 2) get_num - // 3) get_sub_num (flattened from sub-module 'my_sub_module') - // combine_with_exported_module!(module, "my-functions", my_module)); }); ``` diff --git a/tests/plugins.rs b/tests/plugins.rs index 2bee84e4..928f0381 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -11,7 +11,7 @@ mod test { pub mod special_array_package { use rhai::{Array, INT}; - pub const MYSTIC_NUMBER: INT = 42; + pub const MYSTIC_NUMBER: INT = 42 as INT; #[cfg(not(feature = "no_object"))] pub mod feature { diff --git a/xxx.rs b/xxx.rs new file mode 100644 index 00000000..e69de29b