Create NativeCallable trait.

This commit is contained in:
Stephen Chung
2020-05-11 13:36:50 +08:00
parent 314ec5e4d2
commit 4a8710a4a9
9 changed files with 115 additions and 80 deletions

View File

@@ -2,7 +2,7 @@ use super::PackageStore;
use crate::any::{Dynamic, Variant};
use crate::calc_fn_hash;
use crate::engine::FnCallArgs;
use crate::fn_native::{FnCallArgs, NativeFunction};
use crate::result::EvalAltResult;
use crate::token::Position;
@@ -106,7 +106,7 @@ pub fn reg_none<R>(
map_result(r, pos)
});
lib.functions.insert(hash, f);
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
}
/// Add a function with one parameter to the package.
@@ -157,7 +157,7 @@ pub fn reg_unary<T: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, f);
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
}
/// Add a function with one mutable reference parameter to the package.
@@ -215,7 +215,7 @@ pub fn reg_unary_mut<T: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, f);
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
}
/// Add a function with two parameters to the package.
@@ -271,7 +271,7 @@ pub fn reg_binary<A: Variant + Clone, B: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, f);
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
}
/// Add a function with two parameters (the first one being a mutable reference) to the package.
@@ -334,7 +334,7 @@ pub fn reg_binary_mut<A: Variant + Clone, B: Variant + Clone, R>(
map_result(r, pos)
});
lib.functions.insert(hash, f);
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
}
/// Add a function with three parameters to the package.
@@ -374,7 +374,7 @@ pub fn reg_trinary<A: Variant + Clone, B: Variant + Clone, C: Variant + Clone, R
map_result(r, pos)
});
lib.functions.insert(hash, f);
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
}
/// Add a function with three parameters (the first one is a mutable reference) to the package.
@@ -414,5 +414,5 @@ pub fn reg_trinary_mut<A: Variant + Clone, B: Variant + Clone, C: Variant + Clon
map_result(r, pos)
});
lib.functions.insert(hash, f);
lib.functions.insert(hash, Box::new(NativeFunction::new(f)));
}