pub struct DebugInfo(/* private fields */);Expand description
Activation record related to a specified active function.
All internal fields of this record may be unset if not requested, the methods describe how to request the field they return.
DebugInfos can be directly created and used (see DebugInfo::new) or are passed as arguments to hooks (see Hook).
Requesting information related to different functions using the same DebugInfo
will result in the activation record containing information related to both functions simultaneously…which could be confusing.
(Unless the requested information is the same both times, in which case all the info is just overwritten.)
Implementations§
Source§impl DebugInfo
impl DebugInfo
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new DebugInfo.
All the internal fields of the returned activation record will be unset, see LuaState::get_info to request information.
Sourcepub const unsafe fn from_raw(raw: lua_Debug) -> Self
pub const unsafe fn from_raw(raw: lua_Debug) -> Self
Wraps a pre-existing raw lua_Debug.
§Safety
If all MaybeUninit fields are initialized:
name,namewhat,what, andsourcemust either be null or point to valid nul-terminated strings.eventmust either be-1or the numerical value of anyHookEventvalue bit or’d with1 << 31.
If all MaybeUninit fields are uninitialized:
eventmust be just the numerical value of anyHookEventvalue.
A non-modified lua_Debug obtained from DebugInfo::into_raw should always be safe to use.
If the private field is somehow accessed, it should preferably be kept at 0 or otherwise any value Lua might set it to.
Sourcepub const fn into_raw(self) -> lua_Debug
pub const fn into_raw(self) -> lua_Debug
Returns the wrapped lua_Debug.
There are no guarantees on the raw fields of the returned lua_Debug:
some fields may have unexpected values and the MaybeUninit fields may not be initialized.
The raw lua_Debug can be safely converted back into a DebugInfo using DebugInfo::from_raw, as long as it is not modified.
Sourcepub const fn as_mut_ptr(&mut self) -> *mut lua_Debug
pub const fn as_mut_ptr(&mut self) -> *mut lua_Debug
Sourcepub const fn source(&self) -> Option<&CStr>
pub const fn source(&self) -> Option<&CStr>
Returns the literal source of the specified function if said function was loaded via a string.
Otherwise, it returns the chunk name, which is usually '@' followed by the file path or "=[C]" (but could be anything).
This field will only be set if the 'S' selector is used (see LuaState::get_info), and will always be None otherwise.
Sourcepub const fn short_source(&self) -> Option<&CStr>
pub const fn short_source(&self) -> Option<&CStr>
Returns a “printable” version of DebugInfo::source, intended to be used in error messages (which Lua does).
The returned string is never longer than 60 characters.
This field will only be set if the 'S' selector is used (see LuaState::get_info), and will always be None otherwise.
Sourcepub const fn line_defined(&self) -> Option<i32>
pub const fn line_defined(&self) -> Option<i32>
Returns the line number where the definition of the specified Lua function starts.
CFunctions return None instead.
This field will only be set if the 'S' selector is used (see LuaState::get_info), and will always be None otherwise.
Sourcepub const fn last_line_defined(&self) -> Option<i32>
pub const fn last_line_defined(&self) -> Option<i32>
Returns the line number where the definition of the specified Lua function ends.
CFunctions return None instead.
This field will only be set if the 'S' selector is used (see LuaState::get_info), and will always be None otherwise.
Sourcepub const fn what(&self) -> Option<&CStr>
pub const fn what(&self) -> Option<&CStr>
Returns what the specified function is:
"Lua"for Lua functions."C"forCFunctions."main"if it’s the main part of a chunk.
This field will only be set if the 'S' selector is used (see LuaState::get_info), and will always be None otherwise.
Sourcepub const fn current_line(&self) -> Option<i32>
pub const fn current_line(&self) -> Option<i32>
Returns, if known, the current line where the specified function is executing.
None is returned if the current line is not known.
This field will only be set if the 'l' selector is used (see LuaState::get_info) or within Hooks called by HookEvent::Line
(see Hook), and will always be None otherwise.
Sourcepub const fn name(&self) -> Option<&CStr>
pub const fn name(&self) -> Option<&CStr>
Returns a reasonable name for the specified function based on how it was called, or None if no suitable name could be found.
This field will only be set if the 'n' selector is used (see LuaState::get_info), and will always be None otherwise.
Sourcepub const fn name_what(&self) -> Option<&CStr>
pub const fn name_what(&self) -> Option<&CStr>
Returns an explenation of how DebugInfo::name is found.
Possible returned values are:
"global"."local"."method"."field"."upvalue"."metamethod"."". (Returned when no other option applies or no suitable name was found.)
This field will only be set if the 'n' selector is used (see LuaState::get_info), and will always be None otherwise.
Sourcepub const fn n_upvalues(&self) -> Option<u8>
pub const fn n_upvalues(&self) -> Option<u8>
Returns the number of upvalues of the specified function.
This field will only be set if the 'u' selector is used (see LuaState::get_info), and will always be None otherwise.