Delay creation of global module until actually needed.
This commit is contained in:
parent
1be7e60be2
commit
9a8da93145
@ -2517,7 +2517,15 @@ impl Engine {
|
||||
let (var_name, _alias): (Cow<'_, str>, _) = if state.is_global() {
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
if entry_type == AccessMode::ReadOnly {
|
||||
let global = mods.get_mut(mods.find(KEYWORD_GLOBAL).unwrap()).unwrap();
|
||||
let index = if let Some(index) = mods.find(KEYWORD_GLOBAL) {
|
||||
index
|
||||
} else {
|
||||
// Create automatic global module
|
||||
mods.push(crate::engine::KEYWORD_GLOBAL, Module::new());
|
||||
mods.len() - 1
|
||||
};
|
||||
|
||||
let global = mods.get_mut(index).unwrap();
|
||||
let global = Shared::get_mut(global).unwrap();
|
||||
global.set_var(name.clone(), value.clone());
|
||||
global.build_index();
|
||||
|
@ -826,10 +826,6 @@ impl Engine {
|
||||
lib: &[&Module],
|
||||
level: usize,
|
||||
) -> RhaiResult {
|
||||
// Create the global module
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
mods.push(crate::engine::KEYWORD_GLOBAL, Module::new());
|
||||
|
||||
self.eval_stmt_block(scope, mods, state, lib, &mut None, statements, false, level)
|
||||
.or_else(|err| match *err {
|
||||
EvalAltResult::Return(out, _) => Ok(out),
|
||||
|
Loading…
Reference in New Issue
Block a user