mlua-luau-scheduler/examples/callbacks.rs
Filip Tibell 053b85e0c1
YARR (Yet Another Runtime Refactor)
* Minimize dependencies, no longer depending on smol directly, only async-excecutor and its utility crates
* Error callback is no longer thread safe, but faster
* Improved documentation and panic messages for internal workings of runtime
* Depend on mlua exact version needed and serialize feature
* Change crate name
2024-01-27 15:17:09 +01:00

35 lines
743 B
Rust

use mlua::prelude::*;
use mlua_luau_runtime::*;
use async_io::block_on;
const MAIN_SCRIPT: &str = include_str!("./lua/callbacks.luau");
pub fn main() -> LuaResult<()> {
// Set up persistent lua environment
let lua = Lua::new();
// Create a new runtime with custom callbacks
let rt = Runtime::new(&lua)?;
rt.set_error_callback(|e| {
println!(
"Captured error from Lua!\n{}\n{e}\n{}",
"-".repeat(15),
"-".repeat(15)
);
});
// Load the main script into a runtime
let main = lua.load(MAIN_SCRIPT);
rt.spawn_thread(main, ())?;
// Run until completion
block_on(rt.run());
Ok(())
}
#[test]
fn test_callbacks() -> LuaResult<()> {
main()
}