Improve error message for meta methods on userdata

This commit is contained in:
SeanOMik 2024-01-28 11:27:52 -05:00
parent 716b54797d
commit c6f2d303e2
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
1 changed files with 6 additions and 1 deletions

View File

@ -218,12 +218,17 @@ impl<'a, T: Userdata> UserdataBuilder<'a, T> {
R: AsLua<'a>, R: AsLua<'a>,
T: Userdata + 'static T: Userdata + 'static
{ {
let fn_name = name.as_ref().to_string();
let wrap = move |lua: &'a State, mut val: ValueVec<'a>| { let wrap = move |lua: &'a State, mut val: ValueVec<'a>| {
let this_val = val.pop_front().unwrap(); let this_val = val.pop_front().unwrap();
let this = this_val.as_userdata().unwrap(); // if this panics, its a bug let this = this_val.as_userdata().unwrap(); // if this panics, its a bug
let this = this.as_ref::<T>()?; let this = this.as_ref::<T>()?;
let args = A::from_lua_value_vec(lua, val)?; let this_name = T::name();
let args = Self::result_to_bad_arg(
A::from_lua_value_vec(lua, val),
&this_name, &fn_name
)?;
f(lua, this, args).and_then(|r| r.as_lua(lua)) f(lua, this, args).and_then(|r| r.as_lua(lua))
}; };