| 542 | |
| 543 | #[test] |
| 544 | fn call_wrapped_func() -> Result<()> { |
| 545 | let engine = Engine::default(); |
| 546 | let mut linker = Linker::new(&engine); |
| 547 | let mut results = [Val::I32(0)]; |
| 548 | |
| 549 | linker.func_wrap("", "f1", |a: i32, b: i64, c: f32, d: f64| { |
| 550 | assert_eq!(a, 1); |
| 551 | assert_eq!(b, 2); |
| 552 | assert_eq!(c, 3.0); |
| 553 | assert_eq!(d, 4.0); |
| 554 | })?; |
| 555 | |
| 556 | linker.func_wrap("", "f2", || 1i32)?; |
| 557 | |
| 558 | linker.func_wrap("", "f3", || 2i64)?; |
| 559 | |
| 560 | linker.func_wrap("", "f4", || 3.0f32)?; |
| 561 | |
| 562 | linker.func_wrap("", "f5", || 4.0f64)?; |
| 563 | |
| 564 | let mut store = Store::new(&engine, ()); |
| 565 | |
| 566 | let f = linker |
| 567 | .get(&mut store, "", "f1") |
| 568 | .unwrap() |
| 569 | .into_func() |
| 570 | .unwrap(); |
| 571 | f.call( |
| 572 | &mut store, |
| 573 | &[Val::I32(1), Val::I64(2), 3.0f32.into(), 4.0f64.into()], |
| 574 | &mut [], |
| 575 | )?; |
| 576 | f.typed::<(i32, i64, f32, f64), ()>(&store)? |
| 577 | .call(&mut store, (1, 2, 3.0, 4.0))?; |
| 578 | |
| 579 | let f = linker |
| 580 | .get(&mut store, "", "f2") |
| 581 | .unwrap() |
| 582 | .into_func() |
| 583 | .unwrap(); |
| 584 | f.call(&mut store, &[], &mut results)?; |
| 585 | assert_eq!(results[0].unwrap_i32(), 1); |
| 586 | assert_eq!(f.typed::<(), i32>(&store)?.call(&mut store, ())?, 1); |
| 587 | |
| 588 | let f = linker |
| 589 | .get(&mut store, "", "f3") |
| 590 | .unwrap() |
| 591 | .into_func() |
| 592 | .unwrap(); |
| 593 | f.call(&mut store, &[], &mut results)?; |
| 594 | assert_eq!(results[0].unwrap_i64(), 2); |
| 595 | assert_eq!(f.typed::<(), i64>(&store)?.call(&mut store, ())?, 2); |
| 596 | |
| 597 | let f = linker |
| 598 | .get(&mut store, "", "f4") |
| 599 | .unwrap() |
| 600 | .into_func() |
| 601 | .unwrap(); |