use anyhow::Result;
use whynot::{new_runtime, PhpRuntime, PhpValue, RuntimeConfig, RuntimeKind};
fn main() -> Result<()> {
let cfg = RuntimeConfig { debug: true, ..Default::default() };
let mut rt = new_runtime(RuntimeKind::Process(cfg))?;
let hello = rt.call("hello", &[])?;
println!("hello.output = {:?}", hello.output);
println!("hello.result = {:?}", hello.result);
let greet = rt.call("greet", &[PhpValue::from("Milton")])?;
println!("greet.output = {:?}", greet.output);
println!("greet.result = {:?}", greet.result);
let add = rt.call("add", &[7.into(), 5.into()])?;
println!("add.output = {:?}", add.output);
println!("add.result = {:?}", add.result);
let user = rt.call("make_user", &[PhpValue::from("Alice"), PhpValue::from(30)])?;
println!("user.output = {:?}", user.output);
println!("user.info = {:?}", user.info);
println!("user.result = {:?}", user.result);
let boom = rt.call("risky", &[])?;
if let Some(ex) = boom.exception.as_ref() {
println!("exception.class = {}", ex.class);
println!("exception.message = {}", ex.message);
println!("exception.code = {}", ex.code);
println!("exception.trace = {}", ex.trace);
println!("exception.output = {}", boom.output);
}
Ok(())
}