Remove _result registration methods.

This commit is contained in:
Stephen Chung
2022-08-22 22:16:26 +08:00
parent 4ce8d4609d
commit a9413dc570
9 changed files with 260 additions and 491 deletions

View File

@@ -66,7 +66,7 @@ fn build_type() -> Result<(), Box<EvalAltResult>> {
.with_get_set("z", Self::get_z, Self::set_z);
#[cfg(not(feature = "no_index"))]
builder.with_indexer_get_result(Self::get_component);
builder.with_indexer_get(Self::get_component);
}
}

View File

@@ -97,7 +97,7 @@ fn test_functions_global_module() -> Result<(), Box<EvalAltResult>> {
if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::ANSWER")
));
engine.register_result_fn(
engine.register_fn(
"do_stuff",
|context: NativeCallContext, callback: rhai::FnPtr| -> Result<INT, _> {
callback.call_within_context(&context, ())

View File

@@ -315,11 +315,13 @@ fn test_get_set_indexer() -> Result<(), Box<EvalAltResult>> {
engine
.register_type_with_name::<MyMap>("MyMap")
.register_fn("new_map", || MyMap::new())
.register_indexer_get_result(|map: &mut MyMap, index: &str| {
map.get(index).cloned().ok_or_else(|| {
EvalAltResult::ErrorIndexNotFound(index.into(), rhai::Position::NONE).into()
})
})
.register_indexer_get(
|map: &mut MyMap, index: &str| -> Result<_, Box<EvalAltResult>> {
map.get(index).cloned().ok_or_else(|| {
EvalAltResult::ErrorIndexNotFound(index.into(), rhai::Position::NONE).into()
})
},
)
.register_indexer_set(|map: &mut MyMap, index: &str, value: INT| {
map.insert(index.to_string(), value);
});

View File

@@ -598,7 +598,7 @@ fn test_module_dynamic() -> Result<(), Box<EvalAltResult>> {
let mut static_modules = rhai::module_resolvers::StaticModuleResolver::new();
static_modules.insert("test", module);
engine.set_module_resolver(static_modules);
engine.register_result_fn("test2", test_fn);
engine.register_fn("test2", test_fn);
assert_eq!(engine.eval::<INT>(r#"test2("test", 38);"#)?, 42);