summaryrefslogtreecommitdiff
path: root/src/config
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/config
parent1e1eb95926f556e666bc20355327abd24d264858 (diff)
add state which is shared with the lua environment
Diffstat (limited to 'src/config')
-rw-r--r--src/config/evalsto.rs73
-rw-r--r--src/config/mod.rs5
-rw-r--r--src/config/theme/sheetview.rs5
3 files changed, 3 insertions, 80 deletions
diff --git a/src/config/evalsto.rs b/src/config/evalsto.rs
deleted file mode 100644
index eae9b2d..0000000
--- a/src/config/evalsto.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-use std::{marker::PhantomData, sync::Arc};
-
-use mlua::{FromLua, IntoLua, Lua, Result, Value};
-
-use crate::lua::ownedfunction::OwnedFunction;
-
-#[derive(Clone, Debug)]
-pub enum EvalTo<T, A> {
- Function(Arc<OwnedFunction>, PhantomData<A>),
- Value(T),
-}
-
-impl<T, A> EvalTo<T, A> {
- pub fn get<'lua>(&'lua self, args: A, lua: &'lua Lua) -> Result<T>
- where
- T: FromLua<'lua> + Clone,
- A: IntoLua<'lua>,
- {
- match self {
- EvalTo::Function(value, _) => {
- let func = value.get(lua);
- T::from_lua(func.call(args)?, lua)
- }
- EvalTo::Value(value) => Ok(value.clone()),
- }
- }
-
- pub const fn new(value: T) -> Self {
- Self::Value(value)
- }
-}
-
-impl<'lua, T, A> FromLua<'lua> for EvalTo<T, A>
-where
- T: FromLua<'lua> + Clone,
- A: IntoLua<'lua>,
-{
- fn from_lua(
- value: mlua::prelude::LuaValue<'lua>,
- lua: &'lua mlua::prelude::Lua,
- ) -> Result<Self> {
- if value.is_function() {
- Ok(Self::Function(
- Arc::new(OwnedFunction::new(value, lua)),
- PhantomData,
- ))
- } else {
- Ok(Self::Value(T::from_lua(value, lua)?))
- }
- }
-}
-
-impl<'lua, T, A> IntoLua<'lua> for EvalTo<T, A>
-where
- T: FromLua<'lua> + Clone + IntoLua<'lua>,
- A: IntoLua<'lua>,
-{
- fn into_lua(self, lua: &'lua mlua::prelude::Lua) -> Result<Value<'lua>> {
- match self {
- EvalTo::Function(value, _) => Ok(value.get(lua).into_lua(lua)?),
- EvalTo::Value(value) => value.into_lua(lua),
- }
- }
-}
-
-impl<T, A> Default for EvalTo<T, A>
-where
- T: Default,
-{
- fn default() -> Self {
- Self::Value(T::default())
- }
-}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index c5131a6..b01be62 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -4,9 +4,8 @@ use mlua::{UserData, UserDataFields};
use self::theme::Theme;
-pub mod theme;
pub mod constants;
-pub mod evalsto;
+pub mod theme;
#[derive(Debug, Default)]
pub struct GlobalConfig {
@@ -17,7 +16,7 @@ static GLOBAL_CONFIG: RwLock<GlobalConfig> = RwLock::new(GlobalConfig::new());
const DUMMY_CONFIG: GlobalConfig = GlobalConfig::new();
impl GlobalConfig {
- pub const fn new() -> Self {
+ const fn new() -> Self {
Self {
theme: Theme::new(),
}
diff --git a/src/config/theme/sheetview.rs b/src/config/theme/sheetview.rs
index edc7cc3..bcd53e1 100644
--- a/src/config/theme/sheetview.rs
+++ b/src/config/theme/sheetview.rs
@@ -1,10 +1,7 @@
use mlua::UserData;
use ratatui::style::Color;
-use crate::{
- config::{evalsto::EvalTo, GlobalConfig},
- sheet::cell::CellRef,
-};
+use crate::{config::GlobalConfig, lua::evalsto::EvalTo, sheet::cell::CellRef};
use super::style::Style;