Returns a table with information about a function
Returns a table with information about a function. The optional field "what" is a string indicating which values to return (can be more than one). If omitted, all is returned.
f - returns "func" field
l - returns "currentline" field
L - returns a table whose indices are the numbers of the lines that are valid on the function. (A valid line is a line with some associated code, that is, a line where you can put a break point. Non-valid lines include empty lines and comments.)
n - returns "name" and "namewhat" fields
S - returns "source", "short_src", "linedefined" and "what" fields
u - returns "nups" field
The function name can be an integer representing the stack level, where 0 is debug.getinfo itself, 1 is the function that called debug.getinfo, 2 is the function that called that, and so on. Returns nil if the function number is larger than the number of functions on the stack.
Field meanings of the returned table are:
source - where the function was defined. If in a file, it is the file name prefixed by "@".
If the function was defined in a string (through loadstring) then "source" is this string.
If the function was defined interactively (through the lua.exe program) then source will be "stdin".
If the function was defined in a C program, then source will be "[C]".
short_src - a shorter version of "source" (up to 60 characters), useful for error messages
linedefined - the first line number, in the source, where this function was defined (for Lua functions).
lastlinedefined - the last line number, in the source, where this function was defined (for Lua functions).
what - what this function is. Can be "Lua" for a regular Lua function, "C" if it is a C function, or "main" if it is part of the main Lua chunk (ie. outside any function).
name - an attempt to find the name of the function - may be nil.
Since functions can have many names (by assigning a function to many variables) or no name, the name cannot always be determined.
Lua tries to find the name of the function by inspecting the call stack to find how the function was called. This can only work if debug.getinfo was called with a stack level number, not a function itself.
namewhat - what the "name" field means. It can be "global", "local", "method", "field", or the empty string (""). The empty string means Lua did not find the name, and thus the name field will not be present.
nups - the number of upvalues that this function has.
activelines - a table of the active lines of the function, that is ones which have code on them, as opposed to blank lines or comments. Each entry in table contains the line number as a key, and true as the value.
currentline - the line that is currently active (only applies to active functions, that is if the call to debug.getinfo is for a stack level).
func - the function that is active at that stack level (if called with a stack level).
See Also ...
debug.debug - Enters interactive debugging
Lua base functions
(Help topic: lua=debug.getinfo)
Enter a search string to find matching documentation.
Gammon Software support
Forum RSS feed ( https://gammon.com.au/rss/forum.xml )