use luajit::Chunk; use owo_colors::OwoColorize; use std::{ fs, process::{self, ExitCode}, }; fn main() -> ExitCode { let tokio = tokio::runtime::Runtime::new().unwrap(); let lua = { let mut rt = lb::runtime::Builder::new(); luby::open(&mut rt); rt.unhandled_error(error_cb).build().unwrap() }; let path = "tests/test.lua"; let main = lua.spawn(async move |s| { if let Err(ref err) = s.load(Chunk::new(fs::read(path).unwrap()).path(path)) { s.report_error(err); } else if let Err(ref err) = s.call_async(0, 1).await { s.report_error(err); } if s.slot(1).integer().unwrap_or(1) == 0 { ExitCode::SUCCESS } else { ExitCode::FAILURE } }); tokio.block_on(async move { lua.await; main.await.unwrap() }) } fn error_cb(err: &luajit::Error) { match err.trace() { Some(trace) => eprintln!("{}\n{trace}", err.red().bold()), None => eprintln!("{}", err.red().bold()), } process::exit(1); }