summaryrefslogtreecommitdiff
path: root/src/lua
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-01 20:13:55 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-01 20:13:55 +0200
commita807d4e6fb96c4d8b8585b7dbb862e53486562ec (patch)
tree92481d73423fd925f4dd034d68cbfd2e30e216d5 /src/lua
parent417cee4eeeaf7516dfeb59cdbe34fed18f30e0f7 (diff)
add evalsto
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/mod.rs6
-rw-r--r--src/lua/ownedfunction.rs17
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()
+ }
+}