summaryrefslogtreecommitdiff
path: root/src/lua/mod.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 00:36:10 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 00:36:10 +0200
commitfe0938b1de0c46fc2afcaa3dcd6a0f4ec870d21a (patch)
tree8db7509894842395cfb309f00c41b7f4d173888c /src/lua/mod.rs
parent1e1eb95926f556e666bc20355327abd24d264858 (diff)
add state which is shared with the lua environment
Diffstat (limited to 'src/lua/mod.rs')
-rw-r--r--src/lua/mod.rs33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/lua/mod.rs b/src/lua/mod.rs
index 7388890..fe3555e 100644
--- a/src/lua/mod.rs
+++ b/src/lua/mod.rs
@@ -1,5 +1,4 @@
use std::{
- borrow::Borrow,
path::Path,
sync::{Mutex, MutexGuard},
};
@@ -7,8 +6,9 @@ use std::{
use lazy_static::lazy_static;
use mlua::prelude::*;
-use crate::{config::GlobalConfig, sheet::cell::CellRef};
+use crate::{config::{theme::{sheetview::SheetViewTheme, Theme}, GlobalConfig}, sheet::cell::CellRef, state::{sheetview::SheetViewState, GlobalState}};
+pub mod evalsto;
pub mod iobuffer;
pub mod ownedfunction;
pub mod runtime;
@@ -32,18 +32,33 @@ lazy_static! {
};
}
+macro_rules! ud_is_type {
+ ($writer:ident, $ud:ident, $f:ty => $fe:expr $(, $($r:ty => $e:expr),+)? $(,)?) => {
+ if $ud.is::<$f>() {
+ $writer.write(format!("{:#?}", $fe))
+ } $($( else if $ud.is::<$r>() {
+ $writer.write(format!("{:#?}", $e))
+ })*)? else {
+ $writer.write(format!("{:#?}", $ud));
+ }
+ };
+}
+
fn print(_: &Lua, args: LuaMultiValue) -> LuaResult<()> {
let mut writer = iobuffer::iobuffer().write().unwrap();
for (i, arg) in args.iter().enumerate() {
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));
- }
+ ud_is_type!(
+ writer,
+ ud,
+ CellRef => ud.borrow::<CellRef>(),
+ GlobalConfig => GlobalConfig::instance(),
+ Theme => GlobalConfig::instance().theme,
+ SheetViewTheme => GlobalConfig::instance().theme.sheetview,
+ GlobalState => GlobalState::instance(),
+ SheetViewState => GlobalState::instance().sheetview,
+ );
} else {
writer.write(format!("{:#?}", arg));
}