Format getter/setter function name using constants.

This commit is contained in:
Stephen Chung 2020-03-26 10:55:33 +08:00
parent 2bb2e871ab
commit a5a161ec88

View File

@ -15,6 +15,7 @@ use crate::optimize::optimize_into_ast;
use crate::stdlib::{ use crate::stdlib::{
any::{type_name, TypeId}, any::{type_name, TypeId},
boxed::Box, boxed::Box,
format,
string::{String, ToString}, string::{String, ToString},
sync::Arc, sync::Arc,
vec::Vec, vec::Vec,
@ -177,7 +178,7 @@ impl<'e> Engine<'e> {
name: &str, name: &str,
callback: impl Fn(&mut T) -> U + 'static, callback: impl Fn(&mut T) -> U + 'static,
) { ) {
let get_fn_name = FUNC_GETTER.to_string() + name; let get_fn_name = format!("{}{}", FUNC_GETTER, name);
self.register_fn(&get_fn_name, callback); self.register_fn(&get_fn_name, callback);
} }
@ -219,7 +220,7 @@ impl<'e> Engine<'e> {
name: &str, name: &str,
callback: impl Fn(&mut T, U) -> () + 'static, callback: impl Fn(&mut T, U) -> () + 'static,
) { ) {
let set_fn_name = FUNC_SETTER.to_string() + name; let set_fn_name = format!("{}{}", FUNC_SETTER, name);
self.register_fn(&set_fn_name, callback); self.register_fn(&set_fn_name, callback);
} }
@ -893,8 +894,8 @@ impl<'e> Engine<'e> {
name: &str, name: &str,
mut values: Vec<Dynamic>, mut values: Vec<Dynamic>,
) -> Result<Dynamic, EvalAltResult> { ) -> Result<Dynamic, EvalAltResult> {
let values: Vec<_> = values.iter_mut().map(Dynamic::as_mut).collect(); let mut values: Vec<_> = values.iter_mut().map(Dynamic::as_mut).collect();
engine.call_fn_raw(name, values, None, Position::none()) engine.call_fn_raw(name, &mut values, None, Position::none())
} }
call_fn_internal(self, name, args.into_vec()).and_then(|b| { call_fn_internal(self, name, args.into_vec()).and_then(|b| {