#[macro_use]
extern crate lazy_static;
use std::sync::{Arc, Mutex};
pub mod oxl;
use oxl::value::{Control, Types};
use oxl::vm::{self, ScopeBase};
use oxl::vm::{Engine, GlobalScope};
use oxl::{basics, json};
#[derive(Debug)]
struct State {
call_count: u32,
}
impl State {
fn new() -> Arc<Mutex<Self>> {
Arc::new(Mutex::new(State { call_count: 0 }))
}
}
impl vm::ScopedCall for State {
fn call(&mut self, _: Vec<Types>) -> Option<Types> {
self.call_count += 1;
Some(Types::Int(self.call_count.into()))
}
}
fn main() {
let mut global = GlobalScope::from_opts(vec![basics::engine_opt, json::engine_opt]);
let mut vm = Engine::new();
let state = State::new();
global.put_func("state::call", vm::Function::from_scoped(state));
let res = vm.eval_file("test/arith.oxl", &mut global);
match res {
Ok(Types::None) => {
println!()
}
Ok(data) => {
println!("{}", data)
}
Err(Control::Error(err)) => {
println!("Error: {err}")
}
_ => {}
}
}