mirror of https://github.com/sayanarijit/xplr
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
469 B
Rust
18 lines
469 B
Rust
use anyhow::bail;
|
|
use anyhow::Result;
|
|
|
|
pub fn resolve_fn<'lua, 'a>(
|
|
table: &mlua::Table<'lua>,
|
|
mut path: impl Iterator<Item = &'a str>,
|
|
) -> Result<mlua::Function<'lua>> {
|
|
if let Some(nxt) = path.next() {
|
|
match table.get(nxt)? {
|
|
mlua::Value::Table(t) => resolve_fn(&t, path),
|
|
mlua::Value::Function(f) => Ok(f),
|
|
t => bail!("{:?} is not a function", t),
|
|
}
|
|
} else {
|
|
bail!("Invalid path")
|
|
}
|
|
}
|