export_fn: add "name" parameter

This commit is contained in:
J Henry Waugh
2020-08-07 21:19:17 -05:00
parent 1de13b7a03
commit 7410f40c92
9 changed files with 187 additions and 6 deletions

View File

@@ -0,0 +1,24 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_fn(unknown = true)]
pub fn test_fn(input: Point) -> bool {
input.x > input.y
}
fn main() {
let n = Point {
x: 0.0,
y: 10.0,
};
if test_fn(n) {
println!("yes");
} else {
println!("no");
}
}

View File

@@ -0,0 +1,11 @@
error: unknown attribute 'unknown'
--> $DIR/export_fn_bad_attr.rs:9:13
|
9 | #[export_fn(unknown = true)]
| ^^^^^^^
error[E0425]: cannot find function `test_fn` in this scope
--> $DIR/export_fn_bad_attr.rs:19:8
|
19 | if test_fn(n) {
| ^^^^^^^ not found in this scope

View File

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

View File

@@ -0,0 +1,11 @@
error: expecting string literal value
--> $DIR/export_fn_bad_value.rs:9:20
|
9 | #[export_fn(name = true)]
| ^^^^
error[E0425]: cannot find function `test_fn` in this scope
--> $DIR/export_fn_bad_value.rs:19:8
|
19 | if test_fn(n) {
| ^^^^^^^ not found in this scope

View File

@@ -0,0 +1,24 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_fn("wheeeee")]
pub fn test_fn(input: Point) -> bool {
input.x > input.y
}
fn main() {
let n = Point {
x: 0.0,
y: 10.0,
};
if test_fn(n) {
println!("yes");
} else {
println!("no");
}
}

View File

@@ -0,0 +1,11 @@
error: expected assignment expression
--> $DIR/export_fn_junk_arg.rs:9:13
|
9 | #[export_fn("wheeeee")]
| ^^^^^^^^^
error[E0425]: cannot find function `test_fn` in this scope
--> $DIR/export_fn_junk_arg.rs:19:8
|
19 | if test_fn(n) {
| ^^^^^^^ not found in this scope