Use modules to implement packages.
This commit is contained in:
@@ -4,7 +4,8 @@ use crate::engine::{
|
||||
Engine, FunctionsLib, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_PRINT, KEYWORD_TYPE_OF,
|
||||
};
|
||||
use crate::fn_native::FnCallArgs;
|
||||
use crate::packages::{PackageStore, PackagesCollection};
|
||||
use crate::module::Module;
|
||||
use crate::packages::PackagesCollection;
|
||||
use crate::parser::{map_dynamic_to_expr, Expr, FnDef, ReturnType, Stmt, AST};
|
||||
use crate::result::EvalAltResult;
|
||||
use crate::scope::{Entry as ScopeEntry, EntryType as ScopeEntryType, Scope};
|
||||
@@ -112,7 +113,7 @@ impl<'a> State<'a> {
|
||||
/// Call a registered function
|
||||
fn call_fn(
|
||||
packages: &PackagesCollection,
|
||||
base_package: &PackageStore,
|
||||
global_module: &Module,
|
||||
fn_name: &str,
|
||||
args: &mut FnCallArgs,
|
||||
pos: Position,
|
||||
@@ -120,8 +121,8 @@ fn call_fn(
|
||||
// Search built-in's and external functions
|
||||
let hash = calc_fn_hash(empty(), fn_name, args.iter().map(|a| a.type_id()));
|
||||
|
||||
base_package
|
||||
.get_function(hash)
|
||||
global_module
|
||||
.get_fn(hash)
|
||||
.or_else(|| packages.get_function(hash))
|
||||
.map(|func| func.call(args, pos))
|
||||
.transpose()
|
||||
@@ -556,7 +557,7 @@ fn optimize_expr<'a>(expr: Expr, state: &mut State<'a>) -> Expr {
|
||||
""
|
||||
};
|
||||
|
||||
call_fn(&state.engine.packages, &state.engine.base_package, name, &mut call_args, *pos).ok()
|
||||
call_fn(&state.engine.packages, &state.engine.global_module, name, &mut call_args, *pos).ok()
|
||||
.and_then(|result|
|
||||
result.or_else(|| {
|
||||
if !arg_for_type_of.is_empty() {
|
||||
|
Reference in New Issue
Block a user