Add combine_with_exported_module.
This commit is contained in:
committed by
J Henry Waugh
parent
aed70db303
commit
848bdf3f01
@@ -152,6 +152,20 @@ pub fn exported_module(module_path: proc_macro::TokenStream) -> proc_macro::Toke
|
||||
proc_macro::TokenStream::from(tokens)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn combine_with_exported_module(args: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
#[allow(unused_variables)]
|
||||
let (module_expr, export_name, module_path) = match crate::register::parse_register_macro(args)
|
||||
{
|
||||
Ok(triple) => triple,
|
||||
Err(e) => return e.to_compile_error().into(),
|
||||
};
|
||||
let tokens = quote! {
|
||||
#module_path::rhai_generate_into_module(#module_expr);
|
||||
};
|
||||
proc_macro::TokenStream::from(tokens)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn register_exported_fn(args: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let (engine_expr, export_name, rust_modpath) = match crate::register::parse_register_macro(args)
|
||||
|
@@ -191,6 +191,7 @@ impl Parse for Module {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Module {
|
||||
pub fn attrs(&self) -> Option<&Vec<syn::Attribute>> {
|
||||
self.mod_all.as_ref().map(|m| &m.attrs)
|
||||
|
@@ -17,6 +17,7 @@ pub(crate) fn generate_body(
|
||||
let mut set_fn_stmts: Vec<syn::Stmt> = Vec::new();
|
||||
let mut set_const_stmts: Vec<syn::Stmt> = Vec::new();
|
||||
let mut add_mod_blocks: Vec<syn::ExprBlock> = Vec::new();
|
||||
let mut set_mod_blocks: Vec<syn::ExprBlock> = Vec::new();
|
||||
let str_type_path = syn::parse2::<syn::Path>(quote! { str }).unwrap();
|
||||
|
||||
for (const_name, const_expr) in consts {
|
||||
@@ -54,6 +55,14 @@ pub(crate) fn generate_body(
|
||||
})
|
||||
.unwrap(),
|
||||
);
|
||||
set_mod_blocks.push(
|
||||
syn::parse2::<syn::ExprBlock>(quote! {
|
||||
#(#cfg_attrs)* {
|
||||
self::#module_name::rhai_generate_into_module(m);
|
||||
}
|
||||
})
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
// NB: these are token streams, because reparsing messes up "> >" vs ">>"
|
||||
@@ -137,6 +146,11 @@ pub(crate) fn generate_body(
|
||||
#(#add_mod_blocks)*
|
||||
m
|
||||
}
|
||||
pub fn rhai_generate_into_module(m: &mut Module) {
|
||||
#(#set_fn_stmts)*
|
||||
#(#set_const_stmts)*
|
||||
#(#set_mod_blocks)*
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
Reference in New Issue
Block a user