lua_getinfo
[-(0|1), +(0|1|2), e]
int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
Gets information about a specific function or function invocation.
To get information about a function invocation, the parameter ar
must be a valid activation record that was filled by a previous call to lua_getstack
or given as argument to a hook (see lua_Hook
).
To get information about a function you push it onto the stack and start the what
string with the character '>
'. (In that case, lua_getinfo
pops the function from the top of the stack.) For instance, to know in which line a function f
was defined, you can write the following code:
lua_Debug ar; lua_getglobal(L, "f"); /* get global 'f' */ lua_getinfo(L, ">S", &ar); printf("%d\n", ar.linedefined);
Each character in the string what
selects some fields of the structure ar
to be filled or a value to be pushed on the stack:
-
'
n
': fills in the fieldname
andnamewhat
; -
'
S
': fills in the fieldssource
,short_src
,linedefined
,lastlinedefined
, andwhat
; -
'
l
': fills in the fieldcurrentline
; -
'
t
': fills in the fieldistailcall
; -
'
u
': fills in the fieldsnups
,nparams
, andisvararg
; -
'
f
': pushes onto the stack the function that is running at the given level; -
'
L
': pushes onto the stack 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.)If this option is given together with option '
f
', its table is pushed after the function.
This function returns 0 on error (for instance, an invalid option in what
).
Please login to continue.