codegen: Rhai names cannot contain dot

This commit is contained in:
J Henry Waugh 2020-08-19 22:15:48 -05:00
parent f1dc2cbf18
commit 8efde3c7ce
3 changed files with 47 additions and 0 deletions

View File

@ -113,6 +113,14 @@ impl Parse for ExportedFnParams {
} }
} }
// Check validity of name, if present.
if name.as_ref().filter(|n| n.contains('.')).is_some() {
return Err(syn::Error::new(
span,
"Rhai function names may not contain dot"
))
}
Ok(ExportedFnParams { Ok(ExportedFnParams {
name, name,
return_raw, return_raw,

View File

@ -0,0 +1,28 @@
use rhai::plugin::*;
#[derive(Clone)]
pub struct Point {
x: f32,
y: f32,
}
#[export_module]
pub mod test_module {
pub use super::Point;
#[rhai_fn(name = "foo.bar")]
pub fn test_fn(input: Point) -> bool {
input.x > input.y
}
}
fn main() {
let n = Point {
x: 0.0,
y: 10.0,
};
if test_module::test_fn(n) {
println!("yes");
} else {
println!("no");
}
}

View File

@ -0,0 +1,11 @@
error: Rhai function names may not contain dot
--> $DIR/rhai_fn_rename_dot.rs:12:15
|
12 | #[rhai_fn(name = "foo.bar")]
| ^^^^^^^^^^^^^^^^
error[E0433]: failed to resolve: use of undeclared type or module `test_module`
--> $DIR/rhai_fn_rename_dot.rs:23:8
|
23 | if test_module::test_fn(n) {
| ^^^^^^^^^^^ use of undeclared type or module `test_module`