Fix `Userdata::execute_function/method()`
The two methods weren't using __index to try to find the function on the userdata
This commit is contained in:
parent
8b88612890
commit
2fe5dca6c4
|
@ -140,8 +140,8 @@ impl<'a> AnyUserdata<'a> {
|
|||
|
||||
/// Gets something from the userdata.
|
||||
///
|
||||
/// Will trigger a call to the `__index` metamethod. Use [`AnyUserdata::raw_get`] if you
|
||||
/// don't want to call it.
|
||||
/// Will likely trigger a call to the `__index` metamethod. Use [`AnyUserdata::raw_get`] if
|
||||
/// you don't want to call it, but if its not on the metatable that method one find anything
|
||||
pub fn get<K, V>(&self, key: K) -> crate::Result<V>
|
||||
where
|
||||
K: AsLua<'a>,
|
||||
|
@ -160,7 +160,8 @@ impl<'a> AnyUserdata<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Gets something from the userdata. Will **not** trigger a call to the `__index` metamethod.
|
||||
/// Gets something from the userdata that is on the metatable. Will **not** trigger a call to
|
||||
/// the `__index` metamethod.
|
||||
pub fn raw_get<K, V>(&'a self, key: K) -> crate::Result<V>
|
||||
where
|
||||
K: AsLua<'a>,
|
||||
|
@ -171,15 +172,14 @@ impl<'a> AnyUserdata<'a> {
|
|||
}
|
||||
|
||||
/// Execute a method on this userdata. This finds a function with `name` and executes it
|
||||
/// with the userdata as the first argument.
|
||||
/// with the userdata as the first argument. This may trigger an execution
|
||||
/// of the `__index` meta method.
|
||||
pub fn execute_method<A, R>(&'a self, name: &str, args: A) -> crate::Result<R>
|
||||
where
|
||||
A: IntoLuaVec<'a>,
|
||||
R: FromLuaVec<'a> + FromLua<'a>,
|
||||
{
|
||||
let name = name.to_string();
|
||||
let mt = self.get_metatable()?;
|
||||
let f = mt.get::<_, Function>(name)?;
|
||||
let f: Function = self.get(name.to_string())?;
|
||||
|
||||
let mut args = args.into_lua_value_vec(self.state)?;
|
||||
args.push_front(self.clone().as_lua(self.state)?);
|
||||
|
@ -196,10 +196,7 @@ impl<'a> AnyUserdata<'a> {
|
|||
A: IntoLuaVec<'a>,
|
||||
R: FromLuaVec<'a> + FromLua<'a>,
|
||||
{
|
||||
let name = name.to_string();
|
||||
let mt = self.get_metatable()?;
|
||||
let f = mt.get::<_, Function>(name)?;
|
||||
|
||||
let f: Function = self.get(name.to_string())?;
|
||||
f.exec(args)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue