mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
mlua_derive: Fix #[lua(meta, field)] case
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user