use luajit::Chunk; use owo_colors::OwoColorize; use std::{ fs, panic, 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) .prohibit_globals(true) .build() .unwrap() }; let path = "tests/main.lua"; let main = lua.spawn(async move |s| { if let Err(ref err) = s.load(&Chunk::new(fs::read(path).unwrap()).with_path(path)) { s.report_error(err); } else if let Err(ref err) = s.call_async(0, Some(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; match main.await { Ok(res) => res, Err(err) => panic::resume_unwind(err.into_panic()), } }) } 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); }