summaryrefslogtreecommitdiff
path: root/src/lua/ownedfunction.rs
blob: a8d81cf93a564975b71ea74028435b4657978e8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use mlua::{Function, Lua, RegistryKey, Value};

#[derive(Debug)]
pub struct OwnedFunction {
    key: RegistryKey,
}

impl OwnedFunction {
    pub fn new<'lua>(value: Value<'lua>, lua: &'lua Lua) -> Self {
        let key = lua.create_registry_value(value).unwrap();
        Self { key }
    }

    pub fn get<'lua>(&self, lua: &'lua Lua) -> Function<'lua> {
        lua.registry_value(&self.key).unwrap()
    }
}