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