This function fills parts of a structure with an identification of the activation record of the function executing at a given level. Level 0 is the current running function, whereas level n+1 is the function that has called level n. When there are no errors, lua_getstack returns 1; when called with a level greater than the stack depth, it returns 0.

    The structure lua_Debug is used to carry different pieces of information about an active function:

    lua_getstack fills only the private part of this structure, for later use. To fill the other fields of lua_Debug with useful information, call

    This function returns 0 on error (for instance, an invalid option in what). Each character in the string what selects some fields of the structure ar to be filled, as indicated by the letter in parentheses in the definition of lua_Debug above: `S´ fills in the fields source, linedefined, and what; `l´ fills in the field currentline, etc. Moreover, `´ pushes onto the stack the function that is running at the given level.

    The fields of lua_Debug have the following meaning:

    • source If the function was defined in a string, then source is that string. If the function was defined in a file, then source starts with a `@´ followed by the file name.

    • short_src A “printable” version of source, to be used in error messages.

    • currentline the current line where the given function is executing. When no line information is available, currentline is set to -1.

    • namewhat Explains the name field. The value of namewhat can be "global", "local", "method", "field", or (the empty string), according to how the function was called. (Lua uses the empty string when no other option seems to apply.)

    • nups The number of upvalues of the function.