diff options
Diffstat (limited to 'src/lua')
| -rw-r--r-- | src/lua/mod.rs | 6 | ||||
| -rw-r--r-- | src/lua/ownedfunction.rs | 17 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/lua/mod.rs b/src/lua/mod.rs index 0ddcd7f..7388890 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -1,4 +1,5 @@ use std::{ + borrow::Borrow, path::Path, sync::{Mutex, MutexGuard}, }; @@ -6,9 +7,10 @@ use std::{ use lazy_static::lazy_static; use mlua::prelude::*; -use crate::sheet::cell::CellRef; +use crate::{config::GlobalConfig, sheet::cell::CellRef}; pub mod iobuffer; +pub mod ownedfunction; pub mod runtime; lazy_static! { @@ -37,6 +39,8 @@ fn print(_: &Lua, args: LuaMultiValue) -> LuaResult<()> { if let Some(ud) = arg.as_userdata() { if ud.is::<CellRef>() { writer.write(ud.borrow::<CellRef>().unwrap().value().to_string()); + } else if ud.is::<GlobalConfig>() { + writer.write(format!("{:#?}", GlobalConfig::instance().borrow())) } else { writer.write(format!("{:#?}", ud)); } diff --git a/src/lua/ownedfunction.rs b/src/lua/ownedfunction.rs new file mode 100644 index 0000000..a8d81cf --- /dev/null +++ b/src/lua/ownedfunction.rs @@ -0,0 +1,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() + } +} |