summaryrefslogtreecommitdiff
path: root/src/sheet/eval.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sheet/eval.rs')
-rw-r--r--src/sheet/eval.rs55
1 files changed, 0 insertions, 55 deletions
diff --git a/src/sheet/eval.rs b/src/sheet/eval.rs
deleted file mode 100644
index 2108e48..0000000
--- a/src/sheet/eval.rs
+++ /dev/null
@@ -1,55 +0,0 @@
-use std::{
- sync::{Arc, RwLock},
- thread::JoinHandle,
-};
-
-use mlua::prelude::*;
-
-use crate::lua;
-
-use super::{cell::Cell, Sheet};
-
-pub trait EvalFunction {
- fn eval_function(
- &self,
- func: String,
- range: Vec<(usize, usize)>,
- ) -> JoinHandle<Result<Sheet, String>>;
-}
-
-impl EvalFunction for Arc<RwLock<Sheet>> {
- fn eval_function(
- &self,
- func_text: String,
- range: Vec<(usize, usize)>,
- ) -> JoinHandle<Result<Sheet, String>> {
- *self.read().unwrap().progress.lock().unwrap() = 0;
- let this = Arc::clone(self);
- std::thread::spawn(move || {
- let lua = lua::get();
- let read_sheet = this.read().unwrap();
- let mut sheet = read_sheet.clone();
- let result = lua.load(func_text).eval::<LuaFunction>();
-
- match result {
- Ok(func) => {
- let read_sheet = this.read().unwrap();
-
- for (i, (row, column)) in range.iter().enumerate() {
- *read_sheet.progress.lock().unwrap() = (i * 100 / range.len()) as u8;
-
- let cellref = read_sheet.get_ref(*row, *column);
-
- match func.call::<_, Cell>(cellref) {
- Ok(cell) => sheet.set_cell(*row, *column, cell),
- Err(error) => return Err(error.to_string()),
- }
- }
- }
- Err(error) => return Err(error.to_string()),
- }
-
- Ok(sheet)
- })
- }
-}