diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2024-01-10 10:08:33 +0000 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2024-01-10 10:08:33 +0000 |
commit | b5896173fd1fc4ddd3fc47d0e67b2070c84b7210 (patch) | |
tree | 529222168c1dd33a2c110930dc8c7b5b777527f0 | |
parent | 205989f569f5d1ae3aa196545fc313180ed891c1 (diff) | |
download | mlua-b5896173fd1fc4ddd3fc47d0e67b2070c84b7210.zip |
Include skip_memory_check code only when the corresponding attribute set for module
-rw-r--r-- | mlua_derive/src/lib.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/mlua_derive/src/lib.rs b/mlua_derive/src/lib.rs index 8f2b6da..7b6fb30 100644 --- a/mlua_derive/src/lib.rs +++ b/mlua_derive/src/lib.rs @@ -51,7 +51,11 @@ pub fn lua_module(attr: TokenStream, item: TokenStream) -> TokenStream { let func_name = &func.sig.ident; let module_name = args.name.unwrap_or_else(|| func_name.clone()); let ext_entrypoint_name = Ident::new(&format!("luaopen_{module_name}"), Span::call_site()); - let skip_memory_check = args.skip_memory_check; + let skip_memory_check = if args.skip_memory_check { + quote! { lua.skip_memory_check(true); } + } else { + quote! {} + }; let wrapped = quote! { ::mlua::require_module_feature!(); @@ -61,7 +65,7 @@ pub fn lua_module(attr: TokenStream, item: TokenStream) -> TokenStream { #[no_mangle] unsafe extern "C-unwind" fn #ext_entrypoint_name(state: *mut ::mlua::lua_State) -> ::std::os::raw::c_int { let lua = ::mlua::Lua::init_from_ptr(state); - lua.skip_memory_check(#skip_memory_check); + #skip_memory_check lua.entrypoint1(state, #func_name) } }; |