codegen: add rhai_mod and submodule support

This commit is contained in:
J Henry Waugh
2020-08-20 22:20:12 -05:00
parent 38a6c15da1
commit 7962c6dc52
15 changed files with 852 additions and 10 deletions

View File

@@ -0,0 +1,29 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_module]
pub mod test_module {
#[rhai_mod(unknown = "thing")]
pub mod test_mod {
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: unknown attribute 'unknown'
--> $DIR/rhai_mod_bad_attr.rs:11:12
|
11 | #[rhai_mod(unknown = "thing")]
| ^^^^^^^
error[E0433]: failed to resolve: use of undeclared type or module `test_module`
--> $DIR/rhai_mod_bad_attr.rs:24:8
|
24 | if test_module::test_fn(n) {
| ^^^^^^^^^^^ use of undeclared type or module `test_module`

View File

@@ -0,0 +1,29 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_module]
pub mod test_module {
#[rhai_mod(name = true)]
pub mod test_mod {
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: expecting string literal
--> $DIR/rhai_mod_bad_value.rs:11:19
|
11 | #[rhai_mod(name = true)]
| ^^^^
error[E0433]: failed to resolve: use of undeclared type or module `test_module`
--> $DIR/rhai_mod_bad_value.rs:24:8
|
24 | if test_module::test_fn(n) {
| ^^^^^^^^^^^ use of undeclared type or module `test_module`

View File

@@ -0,0 +1,29 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_module]
pub mod test_module {
#[rhai_mod("wheeeee")]
pub mod test_mod {
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: expecting identifier
--> $DIR/rhai_mod_junk_arg.rs:11:12
|
11 | #[rhai_mod("wheeeee")]
| ^^^^^^^^^
error[E0433]: failed to resolve: use of undeclared type or module `test_module`
--> $DIR/rhai_mod_junk_arg.rs:24:8
|
24 | if test_module::test_fn(n) {
| ^^^^^^^^^^^ use of undeclared type or module `test_module`

View File

@@ -0,0 +1,29 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_module]
pub mod test_module {
#[rhai_mod(name)]
pub mod test_mod {
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: requires value
--> $DIR/rhai_mod_missing_value.rs:11:12
|
11 | #[rhai_mod(name)]
| ^^^^
error[E0433]: failed to resolve: use of undeclared type or module `test_module`
--> $DIR/rhai_mod_missing_value.rs:24:8
|
24 | if test_module::test_fn(n) {
| ^^^^^^^^^^^ use of undeclared type or module `test_module`

View File

@@ -0,0 +1,29 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_module]
pub mod test_module {
#[rhai_mod(rhai::name = "thing")]
pub mod test_mod {
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: expecting attribute name
--> $DIR/rhai_mod_path_attr.rs:11:12
|
11 | #[rhai_mod(rhai::name = "thing")]
| ^^^^^^^^^^
error[E0433]: failed to resolve: use of undeclared type or module `test_module`
--> $DIR/rhai_mod_path_attr.rs:24:8
|
24 | if test_module::test_fn(n) {
| ^^^^^^^^^^^ use of undeclared type or module `test_module`

View File

@@ -0,0 +1,29 @@
use rhai::plugin::*;
#[derive(Clone)]
struct Point {
x: f32,
y: f32,
}
#[export_module]
pub mod test_module {
#[rhai_mod(return_raw = "yes")]
pub mod test_mod {
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: unknown attribute 'return_raw'
--> $DIR/rhai_mod_return_raw.rs:11:12
|
11 | #[rhai_mod(return_raw = "yes")]
| ^^^^^^^^^^
error[E0433]: failed to resolve: use of undeclared type or module `test_module`
--> $DIR/rhai_mod_return_raw.rs:24:8
|
24 | if test_module::test_fn(n) {
| ^^^^^^^^^^^ use of undeclared type or module `test_module`