Skip to content

Commit

Permalink
Include skip_memory_check code only when the corresponding attribute …
Browse files Browse the repository at this point in the history
…set for module
  • Loading branch information
khvzak committed Jan 10, 2024
1 parent 205989f commit b589617
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mlua_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Expand All @@ -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)
}
};
Expand Down

0 comments on commit b589617

Please sign in to comment.