From 98e0042214523b045c2ffe348dac595162670ddd Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 26 Apr 2022 18:32:43 +0800 Subject: [PATCH] Fix build. --- src/api/eval.rs | 24 +++++++++++++----------- src/api/run.rs | 5 ++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/api/eval.rs b/src/api/eval.rs index 7fc83dab..0abb366c 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -4,7 +4,7 @@ use crate::eval::{Caches, GlobalRuntimeState}; use crate::parser::ParseState; use crate::types::dynamic::Variant; use crate::{ - Dynamic, Engine, Module, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR, + Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -194,7 +194,10 @@ impl Engine { #[cfg(feature = "debugging")] if self.debugger.is_some() { global.debugger.status = crate::eval::DebuggerStatus::Terminate; - let lib = &[ast.as_ref()]; + let lib = &[ + #[cfg(not(feature = "no_function"))] + ast.as_ref(), + ]; let node = &crate::ast::Stmt::Noop(Position::NONE); self.run_debugger(scope, global, lib, &mut None, node, 0)?; } @@ -230,18 +233,17 @@ impl Engine { return Ok(Dynamic::UNIT); } - let lib = [ + let mut _lib = &[ #[cfg(not(feature = "no_function"))] ast.as_ref(), - ]; - let lib = if lib.first().map(|m: &&Module| m.is_empty()).unwrap_or(true) { - &[] - } else { - &lib[..] - }; + ][..]; + #[cfg(not(feature = "no_function"))] + if !ast.has_functions() { + _lib = &[]; + } let result = - self.eval_global_statements(scope, global, &mut caches, statements, lib, level); + self.eval_global_statements(scope, global, &mut caches, statements, _lib, level); #[cfg(not(feature = "no_module"))] { @@ -266,7 +268,7 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, statements: &[crate::ast::Stmt], - lib: &[&Module], + lib: &[&crate::Module], level: usize, ) -> RhaiResult { self.eval_global_statements(scope, global, caches, statements, lib, level) diff --git a/src/api/run.rs b/src/api/run.rs index 3b53e30a..b79a168d 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -68,7 +68,10 @@ impl Engine { #[cfg(feature = "debugging")] if self.debugger.is_some() { global.debugger.status = crate::eval::DebuggerStatus::Terminate; - let lib = &[ast.as_ref()]; + let lib = &[ + #[cfg(not(feature = "no_function"))] + ast.as_ref(), + ]; let node = &crate::ast::Stmt::Noop(crate::Position::NONE); self.run_debugger(scope, global, lib, &mut None, node, 0)?; }