use mlua::{FromLua, IntoLuaMulti, Lua, Result, Table, TableExt, Value};
#[derive(Clone)]
pub struct Fetches<'lua>(Table<'lua>);
impl<'lua> Fetches<'lua> {
#[inline]
pub fn get<A, R>(&self, name: &str, args: A) -> Result<R>
where
A: IntoLuaMulti<'lua>,
R: FromLua<'lua>,
{
self.0.call_method(name, args)
}
#[inline]
pub fn get_str<A>(&self, name: &str, args: A) -> Result<String>
where
A: IntoLuaMulti<'lua>,
{
Ok((self.0.call_method::<_, Option<_>>(name, args)?).unwrap_or_default())
}
}
impl<'lua> FromLua<'lua> for Fetches<'lua> {
#[inline]
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<Self> {
Ok(Fetches(Table::from_lua(value, lua)?))
}
}