mlua_derive: Fix #[lua(meta, field)] case

This commit is contained in:
Alex Orlenko
2026-05-31 12:28:06 +01:00
parent 208a70f407
commit fcab60bac4
2 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -356,7 +356,7 @@ pub fn userdata_impl(attr: TokenStream, item: TokenStream) -> TokenStream {
let lua_name = lua_attr.name(fn_name);
if lua_attr.meta {
let tokens = quote! {
registry.add_meta_field(#lua_name, #type_path::#fn_name);
registry.add_meta_field(#lua_name, #type_path::#fn_name());
};
registration_calls.push(with_cfg(tokens, &method.attrs));
} else {
+12 -1
View File
@@ -79,6 +79,11 @@ impl Rectangle {
}
}
#[lua(meta, field, name = "__answer")]
fn answer() -> u32 {
42
}
#[lua(skip)]
#[allow(unused)]
fn helper() -> u32 {
@@ -124,7 +129,7 @@ impl Rectangle {
}
fn make_lua() -> Lua {
let lua = Lua::new();
let lua = unsafe { Lua::unsafe_new() };
lua.globals()
.set("Rectangle", lua.create_proxy::<Rectangle>().unwrap())
.unwrap();
@@ -193,6 +198,12 @@ fn test_rectangle() {
assert(other.length == 7, "other length should be 7 after transfer")
assert(other:double_length() == 14, "double_length should be 14")
-- meta field
if _VERSION:match("Lua ") then
local mt = debug.getmetatable(rect)
assert(mt.__answer == 42, "__answer meta field should be 42")
end
assert(rect.lua_version == _VERSION, "lua_version should match Lua's _VERSION")
-- Consuming method