Remove Position parameter from plugin call function.

This commit is contained in:
Stephen Chung 2020-09-18 13:59:38 +08:00
parent 7c3498a4e1
commit cfe28c9282
5 changed files with 157 additions and 116 deletions

View File

@ -84,71 +84,91 @@ impl ExportedParams for ExportedFnParams {
let mut skip = false; let mut skip = false;
let mut special = FnSpecialAccess::None; let mut special = FnSpecialAccess::None;
for attr in attrs { for attr in attrs {
let crate::attrs::AttrItem { key, value, span: item_span } = attr; let crate::attrs::AttrItem {
key,
value,
span: item_span,
} = attr;
match (key.to_string().as_ref(), value) { match (key.to_string().as_ref(), value) {
("get", None) | ("set", None) | ("name", None) => { ("get", None) | ("set", None) | ("name", None) => {
return Err(syn::Error::new(key.span(), "requires value")) return Err(syn::Error::new(key.span(), "requires value"))
}, }
("name", Some(s)) if &s.value() == FN_IDX_GET => { ("name", Some(s)) if &s.value() == FN_IDX_GET => {
return Err(syn::Error::new(item_span, return Err(syn::Error::new(
"use attribute 'index_get' instead")) item_span,
}, "use attribute 'index_get' instead",
))
}
("name", Some(s)) if &s.value() == FN_IDX_SET => { ("name", Some(s)) if &s.value() == FN_IDX_SET => {
return Err(syn::Error::new(item_span, return Err(syn::Error::new(
"use attribute 'index_set' instead")) item_span,
}, "use attribute 'index_set' instead",
))
}
("name", Some(s)) if s.value().starts_with("get$") => { ("name", Some(s)) if s.value().starts_with("get$") => {
return Err(syn::Error::new(item_span, return Err(syn::Error::new(
format!("use attribute 'getter = \"{}\"' instead", item_span,
&s.value()["get$".len()..]))) format!(
}, "use attribute 'getter = \"{}\"' instead",
&s.value()["get$".len()..]
),
))
}
("name", Some(s)) if s.value().starts_with("set$") => { ("name", Some(s)) if s.value().starts_with("set$") => {
return Err(syn::Error::new(item_span, return Err(syn::Error::new(
format!("use attribute 'setter = \"{}\"' instead", item_span,
&s.value()["set$".len()..]))) format!(
}, "use attribute 'setter = \"{}\"' instead",
&s.value()["set$".len()..]
),
))
}
("name", Some(s)) if s.value().contains('$') => { ("name", Some(s)) if s.value().contains('$') => {
return Err(syn::Error::new(s.span(), return Err(syn::Error::new(
"Rhai function names may not contain dollar sign")) s.span(),
}, "Rhai function names may not contain dollar sign",
))
}
("name", Some(s)) if s.value().contains('.') => { ("name", Some(s)) if s.value().contains('.') => {
return Err(syn::Error::new(s.span(), return Err(syn::Error::new(
"Rhai function names may not contain dot")) s.span(),
}, "Rhai function names may not contain dot",
("name", Some(s)) => { ))
name.push(s.value())
},
("set", Some(s)) => special = match special {
FnSpecialAccess::None =>
FnSpecialAccess::Property(Property::Set(syn::Ident::new(&s.value(),
s.span()))),
_ => {
return Err(syn::Error::new(item_span.span(), "conflicting setter"))
} }
}, ("name", Some(s)) => name.push(s.value()),
("get", Some(s)) => special = match special { ("set", Some(s)) => {
FnSpecialAccess::None => special = match special {
FnSpecialAccess::Property(Property::Get(syn::Ident::new(&s.value(), FnSpecialAccess::None => FnSpecialAccess::Property(Property::Set(
s.span()))), syn::Ident::new(&s.value(), s.span()),
_ => { )),
return Err(syn::Error::new(item_span.span(), "conflicting getter")) _ => return Err(syn::Error::new(item_span.span(), "conflicting setter")),
} }
}, }
("index_get", None) => special = match special { ("get", Some(s)) => {
FnSpecialAccess::None => special = match special {
FnSpecialAccess::Index(Index::Get), FnSpecialAccess::None => FnSpecialAccess::Property(Property::Get(
syn::Ident::new(&s.value(), s.span()),
)),
_ => return Err(syn::Error::new(item_span.span(), "conflicting getter")),
}
}
("index_get", None) => {
special = match special {
FnSpecialAccess::None => FnSpecialAccess::Index(Index::Get),
_ => { _ => {
return Err(syn::Error::new(item_span.span(), "conflicting index_get")) return Err(syn::Error::new(item_span.span(), "conflicting index_get"))
} }
}, }
}
("index_set", None) => special = match special { ("index_set", None) => {
FnSpecialAccess::None => special = match special {
FnSpecialAccess::Index(Index::Set), FnSpecialAccess::None => FnSpecialAccess::Index(Index::Set),
_ => { _ => {
return Err(syn::Error::new(item_span.span(), "conflicting index_set")) return Err(syn::Error::new(item_span.span(), "conflicting index_set"))
} }
}, }
}
("return_raw", None) => return_raw = true, ("return_raw", None) => return_raw = true,
("index_get", Some(s)) | ("index_set", Some(s)) | ("return_raw", Some(s)) => { ("index_get", Some(s)) | ("index_set", Some(s)) | ("return_raw", Some(s)) => {
return Err(syn::Error::new(s.span(), "extraneous value")) return Err(syn::Error::new(s.span(), "extraneous value"))
@ -327,26 +347,40 @@ impl ExportedFn {
} }
pub(crate) fn exported_names(&self) -> Vec<syn::LitStr> { pub(crate) fn exported_names(&self) -> Vec<syn::LitStr> {
let mut literals = self.params.name.as_ref() let mut literals = self
.map(|v| v.iter() .params
.map(|s| syn::LitStr::new(s, proc_macro2::Span::call_site())).collect()) .name
.as_ref()
.map(|v| {
v.iter()
.map(|s| syn::LitStr::new(s, proc_macro2::Span::call_site()))
.collect()
})
.unwrap_or_else(|| Vec::new()); .unwrap_or_else(|| Vec::new());
match self.params.special { match self.params.special {
FnSpecialAccess::None => {}, FnSpecialAccess::None => {}
FnSpecialAccess::Property(Property::Get(ref g)) => FnSpecialAccess::Property(Property::Get(ref g)) => literals.push(syn::LitStr::new(
literals.push(syn::LitStr::new(&format!("get${}", g.to_string()), g.span())), &format!("get${}", g.to_string()),
FnSpecialAccess::Property(Property::Set(ref s)) => g.span(),
literals.push(syn::LitStr::new(&format!("set${}", s.to_string()), s.span())), )),
FnSpecialAccess::Index(Index::Get) => FnSpecialAccess::Property(Property::Set(ref s)) => literals.push(syn::LitStr::new(
literals.push(syn::LitStr::new(FN_IDX_GET, proc_macro2::Span::call_site())), &format!("set${}", s.to_string()),
FnSpecialAccess::Index(Index::Set) => s.span(),
literals.push(syn::LitStr::new(FN_IDX_SET, proc_macro2::Span::call_site())), )),
FnSpecialAccess::Index(Index::Get) => {
literals.push(syn::LitStr::new(FN_IDX_GET, proc_macro2::Span::call_site()))
}
FnSpecialAccess::Index(Index::Set) => {
literals.push(syn::LitStr::new(FN_IDX_SET, proc_macro2::Span::call_site()))
}
} }
if literals.is_empty() { if literals.is_empty() {
literals.push(syn::LitStr::new(&self.signature.ident.to_string(), literals.push(syn::LitStr::new(
self.signature.ident.span())); &self.signature.ident.to_string(),
self.signature.ident.span(),
));
} }
literals literals
@ -394,53 +428,61 @@ impl ExportedFn {
match params.special { match params.special {
// 2a. Property getters must take only the subject as an argument. // 2a. Property getters must take only the subject as an argument.
FnSpecialAccess::Property(Property::Get(_)) if self.arg_count() != 1 => FnSpecialAccess::Property(Property::Get(_)) if self.arg_count() != 1 => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"property getter requires exactly 1 argument", "property getter requires exactly 1 argument",
)), ))
}
// 2b. Property getters must return a value. // 2b. Property getters must return a value.
FnSpecialAccess::Property(Property::Get(_)) if self.return_type().is_none() => FnSpecialAccess::Property(Property::Get(_)) if self.return_type().is_none() => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"property getter must return a value" "property getter must return a value",
)), ))
}
// 3a. Property setters must take the subject and a new value as arguments. // 3a. Property setters must take the subject and a new value as arguments.
FnSpecialAccess::Property(Property::Set(_)) if self.arg_count() != 2 => FnSpecialAccess::Property(Property::Set(_)) if self.arg_count() != 2 => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"property setter requires exactly 2 arguments", "property setter requires exactly 2 arguments",
)), ))
}
// 3b. Property setters must return nothing. // 3b. Property setters must return nothing.
FnSpecialAccess::Property(Property::Set(_)) if self.return_type().is_some() => FnSpecialAccess::Property(Property::Set(_)) if self.return_type().is_some() => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"property setter must return no value" "property setter must return no value",
)), ))
}
// 4a. Index getters must take the subject and the accessed "index" as arguments. // 4a. Index getters must take the subject and the accessed "index" as arguments.
FnSpecialAccess::Index(Index::Get) if self.arg_count() != 2 => FnSpecialAccess::Index(Index::Get) if self.arg_count() != 2 => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"index getter requires exactly 2 arguments", "index getter requires exactly 2 arguments",
)), ))
}
// 4b. Index getters must return a value. // 4b. Index getters must return a value.
FnSpecialAccess::Index(Index::Get) if self.return_type().is_none() => FnSpecialAccess::Index(Index::Get) if self.return_type().is_none() => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"index getter must return a value" "index getter must return a value",
)), ))
}
// 5a. Index setters must take the subject, "index", and new value as arguments. // 5a. Index setters must take the subject, "index", and new value as arguments.
FnSpecialAccess::Index(Index::Set) if self.arg_count() != 3 => FnSpecialAccess::Index(Index::Set) if self.arg_count() != 3 => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"index setter requires exactly 3 arguments", "index setter requires exactly 3 arguments",
)), ))
}
// 5b. Index setters must return nothing. // 5b. Index setters must return nothing.
FnSpecialAccess::Index(Index::Set) if self.return_type().is_some() => FnSpecialAccess::Index(Index::Set) if self.return_type().is_some() => {
return Err(syn::Error::new( return Err(syn::Error::new(
self.signature.span(), self.signature.span(),
"index setter must return no value" "index setter must return no value",
)), ))
}
_ => {} _ => {}
} }
@ -685,7 +727,7 @@ impl ExportedFn {
quote! { quote! {
impl PluginFunction for #type_name { impl PluginFunction for #type_name {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), #arg_count, debug_assert_eq!(args.len(), #arg_count,
"wrong arg count: {} != {}", "wrong arg count: {} != {}",

View File

@ -279,7 +279,7 @@ mod generate_tests {
struct Token(); struct Token();
impl PluginFunction for Token { impl PluginFunction for Token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 0usize, debug_assert_eq!(args.len(), 0usize,
"wrong arg count: {} != {}", args.len(), 0usize); "wrong arg count: {} != {}", args.len(), 0usize);
@ -323,7 +323,7 @@ mod generate_tests {
struct Token(); struct Token();
impl PluginFunction for Token { impl PluginFunction for Token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -364,7 +364,7 @@ mod generate_tests {
let expected_tokens = quote! { let expected_tokens = quote! {
impl PluginFunction for MyType { impl PluginFunction for MyType {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -398,7 +398,7 @@ mod generate_tests {
struct Token(); struct Token();
impl PluginFunction for Token { impl PluginFunction for Token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -445,7 +445,7 @@ mod generate_tests {
struct Token(); struct Token();
impl PluginFunction for Token { impl PluginFunction for Token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -493,7 +493,7 @@ mod generate_tests {
struct Token(); struct Token();
impl PluginFunction for Token { impl PluginFunction for Token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);

View File

@ -307,7 +307,7 @@ mod generate_tests {
struct get_mystic_number_token(); struct get_mystic_number_token();
impl PluginFunction for get_mystic_number_token { impl PluginFunction for get_mystic_number_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 0usize, debug_assert_eq!(args.len(), 0usize,
"wrong arg count: {} != {}", args.len(), 0usize); "wrong arg count: {} != {}", args.len(), 0usize);
@ -369,7 +369,7 @@ mod generate_tests {
struct add_one_to_token(); struct add_one_to_token();
impl PluginFunction for add_one_to_token { impl PluginFunction for add_one_to_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -446,7 +446,7 @@ mod generate_tests {
struct add_one_to_token(); struct add_one_to_token();
impl PluginFunction for add_one_to_token { impl PluginFunction for add_one_to_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -474,7 +474,7 @@ mod generate_tests {
struct add_n_to_token(); struct add_n_to_token();
impl PluginFunction for add_n_to_token { impl PluginFunction for add_n_to_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -540,7 +540,7 @@ mod generate_tests {
struct add_together_token(); struct add_together_token();
impl PluginFunction for add_together_token { impl PluginFunction for add_together_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -613,7 +613,7 @@ mod generate_tests {
struct add_together_token(); struct add_together_token();
impl PluginFunction for add_together_token { impl PluginFunction for add_together_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -855,7 +855,7 @@ mod generate_tests {
struct get_mystic_number_token(); struct get_mystic_number_token();
impl PluginFunction for get_mystic_number_token { impl PluginFunction for get_mystic_number_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 0usize, debug_assert_eq!(args.len(), 0usize,
"wrong arg count: {} != {}", args.len(), 0usize); "wrong arg count: {} != {}", args.len(), 0usize);
@ -948,7 +948,7 @@ mod generate_tests {
struct print_out_to_token(); struct print_out_to_token();
impl PluginFunction for print_out_to_token { impl PluginFunction for print_out_to_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -1012,7 +1012,7 @@ mod generate_tests {
struct increment_token(); struct increment_token();
impl PluginFunction for increment_token { impl PluginFunction for increment_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -1079,7 +1079,7 @@ mod generate_tests {
struct increment_token(); struct increment_token();
impl PluginFunction for increment_token { impl PluginFunction for increment_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -1166,7 +1166,7 @@ mod generate_tests {
struct increment_token(); struct increment_token();
impl PluginFunction for increment_token { impl PluginFunction for increment_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -1251,7 +1251,7 @@ mod generate_tests {
struct int_foo_token(); struct int_foo_token();
impl PluginFunction for int_foo_token { impl PluginFunction for int_foo_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -1317,7 +1317,7 @@ mod generate_tests {
struct int_foo_token(); struct int_foo_token();
impl PluginFunction for int_foo_token { impl PluginFunction for int_foo_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 1usize, debug_assert_eq!(args.len(), 1usize,
"wrong arg count: {} != {}", args.len(), 1usize); "wrong arg count: {} != {}", args.len(), 1usize);
@ -1383,7 +1383,7 @@ mod generate_tests {
struct int_foo_token(); struct int_foo_token();
impl PluginFunction for int_foo_token { impl PluginFunction for int_foo_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -1454,7 +1454,7 @@ mod generate_tests {
struct int_foo_token(); struct int_foo_token();
impl PluginFunction for int_foo_token { impl PluginFunction for int_foo_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -1521,7 +1521,7 @@ mod generate_tests {
struct get_by_index_token(); struct get_by_index_token();
impl PluginFunction for get_by_index_token { impl PluginFunction for get_by_index_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -1593,7 +1593,7 @@ mod generate_tests {
struct get_by_index_token(); struct get_by_index_token();
impl PluginFunction for get_by_index_token { impl PluginFunction for get_by_index_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 2usize, debug_assert_eq!(args.len(), 2usize,
"wrong arg count: {} != {}", args.len(), 2usize); "wrong arg count: {} != {}", args.len(), 2usize);
@ -1662,7 +1662,7 @@ mod generate_tests {
struct set_by_index_token(); struct set_by_index_token();
impl PluginFunction for set_by_index_token { impl PluginFunction for set_by_index_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 3usize, debug_assert_eq!(args.len(), 3usize,
"wrong arg count: {} != {}", args.len(), 3usize); "wrong arg count: {} != {}", args.len(), 3usize);
@ -1738,7 +1738,7 @@ mod generate_tests {
struct set_by_index_token(); struct set_by_index_token();
impl PluginFunction for set_by_index_token { impl PluginFunction for set_by_index_token {
fn call(&self, fn call(&self,
args: &mut [&mut Dynamic], pos: Position args: &mut [&mut Dynamic]
) -> Result<Dynamic, Box<EvalAltResult>> { ) -> Result<Dynamic, Box<EvalAltResult>> {
debug_assert_eq!(args.len(), 3usize, debug_assert_eq!(args.len(), 3usize,
"wrong arg count: {} != {}", args.len(), 3usize); "wrong arg count: {} != {}", args.len(), 3usize);

View File

@ -232,7 +232,7 @@ impl Engine {
// Run external function // Run external function
let result = if func.is_plugin_fn() { let result = if func.is_plugin_fn() {
func.get_plugin_fn().call(args, Position::none()) func.get_plugin_fn().call(args)
} else { } else {
func.get_native_fn()(self, lib, args) func.get_native_fn()(self, lib, args)
}; };
@ -1099,7 +1099,7 @@ impl Engine {
self.call_script_fn(scope, mods, state, lib, &mut None, name, func, args, level) self.call_script_fn(scope, mods, state, lib, &mut None, name, func, args, level)
} }
Some(f) if f.is_plugin_fn() => f.get_plugin_fn().call(args.as_mut(), Position::none()), Some(f) if f.is_plugin_fn() => f.get_plugin_fn().call(args.as_mut()),
Some(f) if f.is_native() => { Some(f) if f.is_native() => {
if !f.is_method() { if !f.is_method() {
// Clone first argument // Clone first argument

View File

@ -3,7 +3,7 @@
pub use crate::{ pub use crate::{
fn_native::CallableFunction, stdlib::any::TypeId, stdlib::boxed::Box, stdlib::format, fn_native::CallableFunction, stdlib::any::TypeId, stdlib::boxed::Box, stdlib::format,
stdlib::mem, stdlib::string::ToString, stdlib::vec as new_vec, stdlib::vec::Vec, Dynamic, stdlib::mem, stdlib::string::ToString, stdlib::vec as new_vec, stdlib::vec::Vec, Dynamic,
Engine, EvalAltResult, FnAccess, ImmutableString, Module, Position, RegisterResultFn, Engine, EvalAltResult, FnAccess, ImmutableString, Module, RegisterResultFn,
}; };
#[cfg(not(features = "no_module"))] #[cfg(not(features = "no_module"))]
@ -34,8 +34,7 @@ pub trait PluginFunction {
fn is_method_call(&self) -> bool; fn is_method_call(&self) -> bool;
fn is_varadic(&self) -> bool; fn is_varadic(&self) -> bool;
fn call(&self, args: &mut [&mut Dynamic], pos: Position) fn call(&self, args: &mut [&mut Dynamic]) -> Result<Dynamic, Box<EvalAltResult>>;
-> Result<Dynamic, Box<EvalAltResult>>;
fn clone_boxed(&self) -> Box<dyn PluginFunction>; fn clone_boxed(&self) -> Box<dyn PluginFunction>;