luaur_vm/functions/
db_traceback.rs1use crate::functions::getthread::getthread;
2use crate::functions::lua_l_optinteger::lua_l_optinteger;
3use crate::functions::lua_l_traceback::lua_l_traceback;
4use crate::macros::lua_l_argcheck::luaL_argcheck;
5use crate::macros::lua_l_optstring::LUA_L_OPTSTRING;
6use crate::type_aliases::lua_state::lua_State;
7use core::ffi::{c_char, c_int};
8
9pub fn db_traceback(l: *mut lua_State) -> c_int {
10 unsafe {
11 let mut arg: c_int = 0;
12 let l1 = getthread(l, &mut arg);
13
14 let msg_ptr = crate::functions::lua_l_optlstring::lua_l_optlstring(
19 l,
20 arg + 1,
21 core::ptr::null(),
22 core::ptr::null_mut(),
23 );
24 let msg = if msg_ptr.is_null() {
25 None
26 } else {
27 Some(core::ffi::CStr::from_ptr(msg_ptr).to_str().unwrap_or(""))
28 };
29
30 let default_level = if l == l1 { 1 } else { 0 };
31 let level = lua_l_optinteger(l, arg + 2, default_level);
32
33 luaL_argcheck!(l, level >= 0, arg + 2, "level can't be negative");
34
35 lua_l_traceback(l, l1, msg, level);
36
37 1
38 }
39}