1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use mlua::{FromLua, Lua, Result, Table, TableExt, ToLuaMulti, Value};
#[derive(Clone)]
pub struct Fetches<'lua>(Table<'lua>);
impl<'lua> Fetches<'lua> {
pub fn get<A, R>(&self, name: &str, args: A) -> Result<R>
where
A: ToLuaMulti<'lua>,
R: FromLua<'lua>,
{
self.0.call_method(name, args)
}
pub fn get_str<A>(&self, name: &str, args: A) -> Result<String>
where
A: ToLuaMulti<'lua>,
{
Ok(match self.0.call_method(name, args)? {
Some(val) => val,
None => String::new(),
})
}
}
impl<'lua> FromLua<'lua> for Fetches<'lua> {
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<Self> {
Ok(Fetches(Table::from_lua(value, lua)?))
}
}