macro_rules! error { ($l:expr, $($args:tt)+) => { ... }; }
Expand description
Throws the lua error with the given message. The first argument is the lua context in which the error should be thrown. When throwing an error from a rust callback use the lua state which was passed to the callback.
This macro will exit the current function so no code after it will be executed.
§Example
let lua = tlua::Lua::new();
lua.set("rust_callback_which_may_throw",
tlua::Function::new(|arg1: i32, arg2: String, lua: tlua::LuaState| {
// - `arg1` & `arg2` are passed by caller from lua
// - `lua` is a special argument inserted by tlua.
// Only it should be used with `tlua::error!()`!
tlua::error!(lua, "invalid arguments: {arg1}, {arg2}");
}));