-
-
Notifications
You must be signed in to change notification settings - Fork 188
Open
Description
I use tracebacks when displaying warnings. However, to the best of my knowledge, luaL_traceback
is not exposed in the "safe" API. In order to get backtraces, I had to wrap the unsafe luaL_traceback
with create_c_function
to be able to get the backtraces. Providing some sort of lua.traceback()
or the likes that would do this could be useful instead of needing a custom implementation.
For reference, my unsafe implementation is below:
#[allow(non_snake_case)]
unsafe extern "C-unwind" fn traceback_wrap(L: *mut mlua::lua_State) -> i32 {
unsafe {
let msg = if mlua::ffi::lua_isstring(L, 1) != 0 {
mlua::ffi::lua_tostring(L, 1)
} else {
std::ptr::null()
};
let level = if mlua::ffi::lua_isinteger(L, 2) != 0 {
mlua::ffi::lua_tointeger(L, 2)
} else {
1
};
mlua::ffi::luaL_traceback(L, L, msg, level as i32);
}
1
}
let traceback = unsafe { lua.create_c_function(traceback_wrap)? };
Metadata
Metadata
Assignees
Labels
No labels