Recompile prior history with `src` so imports and defs persist; only new lines reach `on_line`.
(&mut self, src: &str, mut on_line: F)
| 69 | |
| 70 | /// Recompile prior history with `src` so imports and defs persist; only new lines reach `on_line`. |
| 71 | pub fn eval<F: FnMut(&str)>(&mut self, src: &str, mut on_line: F) -> Result<Outcome> { |
| 72 | let full = if self.history.is_empty() { |
| 73 | src.to_string() |
| 74 | } else { |
| 75 | format!("{}\n{}", self.history, src) |
| 76 | }; |
| 77 | let literal = serde_json::to_string(&full)?; |
| 78 | let expr = format!("__edgeRun({literal})"); |
| 79 | self.tab.evaluate(&expr, false).map_err(|e| anyhow!("starting eval: {e}"))?; |
| 80 | |
| 81 | let mut all: Vec<String> = Vec::new(); |
| 82 | let outcome = drain(&self.tab, &mut |line| all.push(line.to_string()))?; |
| 83 | for line in all.iter().skip(self.history_lines) { |
| 84 | on_line(line); |
| 85 | } |
| 86 | if outcome.err.is_none() { |
| 87 | if !self.history.is_empty() { self.history.push('\n'); } |
| 88 | self.history.push_str(src); |
| 89 | self.history_lines = all.len(); |
| 90 | } |
| 91 | Ok(outcome) |
| 92 | } |
| 93 | |
| 94 | /// Wipe accumulated history and runtime modules; next eval starts in a fresh namespace. |
| 95 | pub fn reset(&mut self) -> Result<()> { |