Skip to main content

DebugInfo

Struct DebugInfo 

Source
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

Source

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.

Source

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, and source must either be null or point to valid nul-terminated strings.
  • event must either be -1 or the numerical value of any HookEvent value bit or’d with 1 << 31.

If all MaybeUninit fields are uninitialized:

  • event must be just the numerical value of any HookEvent value.

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.

Source

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.

Source

pub const fn as_ptr(&self) -> *const lua_Debug

Returns a pointer to the wrapped lua_Debug. This can be used to pass this DebugInfo to raw ffi functions.

The caller must ensure that the DebugInfo outlives the pointer this function returns, or else it will end up dangling.

Source

pub const fn as_mut_ptr(&mut self) -> *mut lua_Debug

Returns a mutable pointer to the wrapped lua_Debug. This can be used to pass this DebugInfo to raw ffi functions.

The caller must ensure that the DebugInfo outlives the pointer this function returns, or else it will end up dangling.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn what(&self) -> Option<&CStr>

Returns what the specified function is:

  • "Lua" for Lua functions.
  • "C" for CFunctions.
  • "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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn event(&self) -> Option<HookEvent>

Returns the HookEvent that called the current Hook.

This field will only be set if this DebugInfo comes from the Hook’s arguments (see Hook), and will always be None otherwise.

Trait Implementations§

Source§

impl Clone for DebugInfo

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DebugInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DebugInfo

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.