pub struct Call { /* private fields */ }
Expand description
Used to call specific functions with arguments.
Implementations§
source§impl Call
impl Call
sourcepub fn new(name: &str) -> Call
pub fn new(name: &str) -> Call
Creates a new call.
Examples found in repository?
examples/call.rs (line 59)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn main() {
let mut module = Module::new();
// Add functions to read `a` and `b` from `RustArgs`.
module.add(
Arc::new("a_of".into()),
a_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
module.add(
Arc::new("b_of".into()),
b_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
error(load_str(
"main.dyon",
Arc::new(
r#"
fn add_args(a: f64, b: f64) {
println("add_args:")
println(link {a" + "b" = "a + b})
}
fn add_obj(obj: {}) {
println("add_obj:")
println(link {obj.a" + "obj.b" = "obj.a + obj.b})
}
fn add_rust(obj: any) {
println("add_rust")
a := a_of(obj)
b := b_of(obj)
println(link {a" + "b" = "a + b})
}
add(a, b) = a + b
create_vec(a, b) = (a, b)
id(obj) = clone(obj)
"#
.into(),
),
&mut module,
));
let ref module = Arc::new(module);
let a = 20.0;
let b = 30.0;
// Call with multiple arguments.
let call = Call::new("add_args").arg(a).arg(b);
error(call.run(&mut Runtime::new(), module));
// Call with object.
let call = Call::new("add_obj").arg(Args { a, b });
error(call.run(&mut Runtime::new(), module));
// Call with rust object.
let call = Call::new("add_rust").rust(RustArgs { a, b });
error(call.run(&mut Runtime::new(), module));
// Call function with return value.
let call = Call::new("add").arg(a).arg(b);
match call.run_ret::<f64>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns vec4.
let call = Call::new("create_vec").arg(a).arg(b);
match call.run_vec4::<[f64; 2]>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns Rust object.
let call = Call::new("id").rust(RustArgs { a, b });
match call.run_ret::<RustObject>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer.lock().unwrap().downcast_ref::<RustArgs>());
}
Err(err) => {
error(Err(err));
}
}
}
sourcepub fn arg<T: PushVariable>(self, val: T) -> Self
pub fn arg<T: PushVariable>(self, val: T) -> Self
Push value to argument list.
Examples found in repository?
examples/call.rs (line 59)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn main() {
let mut module = Module::new();
// Add functions to read `a` and `b` from `RustArgs`.
module.add(
Arc::new("a_of".into()),
a_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
module.add(
Arc::new("b_of".into()),
b_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
error(load_str(
"main.dyon",
Arc::new(
r#"
fn add_args(a: f64, b: f64) {
println("add_args:")
println(link {a" + "b" = "a + b})
}
fn add_obj(obj: {}) {
println("add_obj:")
println(link {obj.a" + "obj.b" = "obj.a + obj.b})
}
fn add_rust(obj: any) {
println("add_rust")
a := a_of(obj)
b := b_of(obj)
println(link {a" + "b" = "a + b})
}
add(a, b) = a + b
create_vec(a, b) = (a, b)
id(obj) = clone(obj)
"#
.into(),
),
&mut module,
));
let ref module = Arc::new(module);
let a = 20.0;
let b = 30.0;
// Call with multiple arguments.
let call = Call::new("add_args").arg(a).arg(b);
error(call.run(&mut Runtime::new(), module));
// Call with object.
let call = Call::new("add_obj").arg(Args { a, b });
error(call.run(&mut Runtime::new(), module));
// Call with rust object.
let call = Call::new("add_rust").rust(RustArgs { a, b });
error(call.run(&mut Runtime::new(), module));
// Call function with return value.
let call = Call::new("add").arg(a).arg(b);
match call.run_ret::<f64>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns vec4.
let call = Call::new("create_vec").arg(a).arg(b);
match call.run_vec4::<[f64; 2]>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns Rust object.
let call = Call::new("id").rust(RustArgs { a, b });
match call.run_ret::<RustObject>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer.lock().unwrap().downcast_ref::<RustArgs>());
}
Err(err) => {
error(Err(err));
}
}
}
sourcepub fn vec4<T: ConvertVec4>(self, val: T) -> Self
pub fn vec4<T: ConvertVec4>(self, val: T) -> Self
Push Vec4 to argument list.
sourcepub fn rust<T: 'static>(self, val: T) -> Self
pub fn rust<T: 'static>(self, val: T) -> Self
Push Rust object to argument list.
Examples found in repository?
examples/call.rs (line 67)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn main() {
let mut module = Module::new();
// Add functions to read `a` and `b` from `RustArgs`.
module.add(
Arc::new("a_of".into()),
a_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
module.add(
Arc::new("b_of".into()),
b_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
error(load_str(
"main.dyon",
Arc::new(
r#"
fn add_args(a: f64, b: f64) {
println("add_args:")
println(link {a" + "b" = "a + b})
}
fn add_obj(obj: {}) {
println("add_obj:")
println(link {obj.a" + "obj.b" = "obj.a + obj.b})
}
fn add_rust(obj: any) {
println("add_rust")
a := a_of(obj)
b := b_of(obj)
println(link {a" + "b" = "a + b})
}
add(a, b) = a + b
create_vec(a, b) = (a, b)
id(obj) = clone(obj)
"#
.into(),
),
&mut module,
));
let ref module = Arc::new(module);
let a = 20.0;
let b = 30.0;
// Call with multiple arguments.
let call = Call::new("add_args").arg(a).arg(b);
error(call.run(&mut Runtime::new(), module));
// Call with object.
let call = Call::new("add_obj").arg(Args { a, b });
error(call.run(&mut Runtime::new(), module));
// Call with rust object.
let call = Call::new("add_rust").rust(RustArgs { a, b });
error(call.run(&mut Runtime::new(), module));
// Call function with return value.
let call = Call::new("add").arg(a).arg(b);
match call.run_ret::<f64>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns vec4.
let call = Call::new("create_vec").arg(a).arg(b);
match call.run_vec4::<[f64; 2]>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns Rust object.
let call = Call::new("id").rust(RustArgs { a, b });
match call.run_ret::<RustObject>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer.lock().unwrap().downcast_ref::<RustArgs>());
}
Err(err) => {
error(Err(err));
}
}
}
sourcepub fn run(
&self,
runtime: &mut Runtime,
module: &Arc<Module>
) -> Result<(), String>
pub fn run( &self, runtime: &mut Runtime, module: &Arc<Module> ) -> Result<(), String>
Run call without any return value.
Examples found in repository?
examples/call.rs (line 60)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn main() {
let mut module = Module::new();
// Add functions to read `a` and `b` from `RustArgs`.
module.add(
Arc::new("a_of".into()),
a_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
module.add(
Arc::new("b_of".into()),
b_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
error(load_str(
"main.dyon",
Arc::new(
r#"
fn add_args(a: f64, b: f64) {
println("add_args:")
println(link {a" + "b" = "a + b})
}
fn add_obj(obj: {}) {
println("add_obj:")
println(link {obj.a" + "obj.b" = "obj.a + obj.b})
}
fn add_rust(obj: any) {
println("add_rust")
a := a_of(obj)
b := b_of(obj)
println(link {a" + "b" = "a + b})
}
add(a, b) = a + b
create_vec(a, b) = (a, b)
id(obj) = clone(obj)
"#
.into(),
),
&mut module,
));
let ref module = Arc::new(module);
let a = 20.0;
let b = 30.0;
// Call with multiple arguments.
let call = Call::new("add_args").arg(a).arg(b);
error(call.run(&mut Runtime::new(), module));
// Call with object.
let call = Call::new("add_obj").arg(Args { a, b });
error(call.run(&mut Runtime::new(), module));
// Call with rust object.
let call = Call::new("add_rust").rust(RustArgs { a, b });
error(call.run(&mut Runtime::new(), module));
// Call function with return value.
let call = Call::new("add").arg(a).arg(b);
match call.run_ret::<f64>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns vec4.
let call = Call::new("create_vec").arg(a).arg(b);
match call.run_vec4::<[f64; 2]>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns Rust object.
let call = Call::new("id").rust(RustArgs { a, b });
match call.run_ret::<RustObject>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer.lock().unwrap().downcast_ref::<RustArgs>());
}
Err(err) => {
error(Err(err));
}
}
}
sourcepub fn run_ret<T: PopVariable>(
&self,
runtime: &mut Runtime,
module: &Arc<Module>
) -> Result<T, String>
pub fn run_ret<T: PopVariable>( &self, runtime: &mut Runtime, module: &Arc<Module> ) -> Result<T, String>
Run call with return value.
Examples found in repository?
examples/call.rs (line 72)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn main() {
let mut module = Module::new();
// Add functions to read `a` and `b` from `RustArgs`.
module.add(
Arc::new("a_of".into()),
a_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
module.add(
Arc::new("b_of".into()),
b_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
error(load_str(
"main.dyon",
Arc::new(
r#"
fn add_args(a: f64, b: f64) {
println("add_args:")
println(link {a" + "b" = "a + b})
}
fn add_obj(obj: {}) {
println("add_obj:")
println(link {obj.a" + "obj.b" = "obj.a + obj.b})
}
fn add_rust(obj: any) {
println("add_rust")
a := a_of(obj)
b := b_of(obj)
println(link {a" + "b" = "a + b})
}
add(a, b) = a + b
create_vec(a, b) = (a, b)
id(obj) = clone(obj)
"#
.into(),
),
&mut module,
));
let ref module = Arc::new(module);
let a = 20.0;
let b = 30.0;
// Call with multiple arguments.
let call = Call::new("add_args").arg(a).arg(b);
error(call.run(&mut Runtime::new(), module));
// Call with object.
let call = Call::new("add_obj").arg(Args { a, b });
error(call.run(&mut Runtime::new(), module));
// Call with rust object.
let call = Call::new("add_rust").rust(RustArgs { a, b });
error(call.run(&mut Runtime::new(), module));
// Call function with return value.
let call = Call::new("add").arg(a).arg(b);
match call.run_ret::<f64>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns vec4.
let call = Call::new("create_vec").arg(a).arg(b);
match call.run_vec4::<[f64; 2]>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns Rust object.
let call = Call::new("id").rust(RustArgs { a, b });
match call.run_ret::<RustObject>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer.lock().unwrap().downcast_ref::<RustArgs>());
}
Err(err) => {
error(Err(err));
}
}
}
sourcepub fn run_vec4<T: ConvertVec4>(
&self,
runtime: &mut Runtime,
module: &Arc<Module>
) -> Result<T, String>
pub fn run_vec4<T: ConvertVec4>( &self, runtime: &mut Runtime, module: &Arc<Module> ) -> Result<T, String>
Convert return value to a Vec4 convertible type.
Examples found in repository?
examples/call.rs (line 83)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn main() {
let mut module = Module::new();
// Add functions to read `a` and `b` from `RustArgs`.
module.add(
Arc::new("a_of".into()),
a_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
module.add(
Arc::new("b_of".into()),
b_of,
Dfn::nl(vec![Type::Any], Type::F64),
);
error(load_str(
"main.dyon",
Arc::new(
r#"
fn add_args(a: f64, b: f64) {
println("add_args:")
println(link {a" + "b" = "a + b})
}
fn add_obj(obj: {}) {
println("add_obj:")
println(link {obj.a" + "obj.b" = "obj.a + obj.b})
}
fn add_rust(obj: any) {
println("add_rust")
a := a_of(obj)
b := b_of(obj)
println(link {a" + "b" = "a + b})
}
add(a, b) = a + b
create_vec(a, b) = (a, b)
id(obj) = clone(obj)
"#
.into(),
),
&mut module,
));
let ref module = Arc::new(module);
let a = 20.0;
let b = 30.0;
// Call with multiple arguments.
let call = Call::new("add_args").arg(a).arg(b);
error(call.run(&mut Runtime::new(), module));
// Call with object.
let call = Call::new("add_obj").arg(Args { a, b });
error(call.run(&mut Runtime::new(), module));
// Call with rust object.
let call = Call::new("add_rust").rust(RustArgs { a, b });
error(call.run(&mut Runtime::new(), module));
// Call function with return value.
let call = Call::new("add").arg(a).arg(b);
match call.run_ret::<f64>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns vec4.
let call = Call::new("create_vec").arg(a).arg(b);
match call.run_vec4::<[f64; 2]>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer);
}
Err(err) => {
error(Err(err));
}
}
// Call function that returns Rust object.
let call = Call::new("id").rust(RustArgs { a, b });
match call.run_ret::<RustObject>(&mut Runtime::new(), module) {
Ok(answer) => {
println!("{:?}", answer.lock().unwrap().downcast_ref::<RustArgs>());
}
Err(err) => {
error(Err(err));
}
}
}
Auto Trait Implementations§
impl !RefUnwindSafe for Call
impl Send for Call
impl !Sync for Call
impl Unpin for Call
impl !UnwindSafe for Call
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more