=head1 NAME debug - debugging facilities (standard library) =head1 OVERVIEW This library provides the functionality of the debug interface to Lua programs. You should exert care when using this library. The functions provided here should be used exclusively for debugging and similar tasks, such as profiling. Please resist the temptation to use them as a usual programming tool: they can be very slow. Moreover, several of its functions violate some assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside or that userdata metatables cannot be changed by Lua code) and therefore can compromise otherwise secure code. All functions in this library are provided inside the C table. All functions that operate over a thread have an optional first argument which is the thread to operate over. The default is always the current thread. =head1 REFERENCE =head2 C debug.debug () Enters an interactive mode with the user, running each string that the user enters. Using simple commands and other debug facilities, the user can inspect global and local variables, change their values, evaluate expressions, and so on. A line containing only the word C finishes this function, so that the caller continues its execution. Note that commands for C are not lexically nested within any function, and so have no direct access to local variables. =head2 C debug.getfenv (o) Returns the environment of object C. =head2 C debug.gethook ([thread]) Returns the current hook settings of the thread, as three values: the current hook function, the current hook mask, and the current hook count (as set by the L function). =head2 C debug.getinfo ([thread,] function [, what]) Returns a table with information about a function. You can give the function directly, or you can give a number as the value of C, which means the function running at level C of the call stack of the given thread: level 0 is the current function (C itself); level 1 is the function that called C; and so on. If C is a number larger than the number of active functions, then C returns C. The returned table may contain all the fields returned by C, with the string C describing which fields to fill in. The default for C is to get all information available, except the table of valid lines. If present, the option 'C' adds a field named C with the function itself. If present, the option 'C' adds a field named C with the table of valid lines. For instance, the expression C returns a name of the current function, if a reasonable name can be found, and C returns a table with all available information about the C function. =head2 C debug.getlocal ([thread,] level, local) This function returns the name and the value of the local variable with index C of the function at level C of the stack. (The first parameter or local variable has index 1, and so on, until the last active local variable.) The function returns C if there is no local variable with the given index, and raises an error when called with a C out of range. (You can call L to check whether the level is valid.) Variable names starting with 'C<(>' (open parentheses) represent internal variables (loop control variables, temporaries, and C function locals). =head2 C debug.getmetatable (object) Returns the metatable of the given C or C if it does not have a metatable. =head2 C debug.getregistry () Returns the registry table (see sect 3.5). debug.getupvalue (func, up) This function returns the name and the value of the upvalue with index C of the function C. The function returns C if there is no upvalue with the given index. =head2 C debug.setfenv (object, table) Sets the environment of the given C to the given C. Returns C. =head2 C debug.sethook ([thread,] hook, mask [, count]) Sets the given function as a hook. The string C and the number C describe when the hook will be called. The string mask may have the following characters, with the given meaning: "c": The hook is called every time Lua calls a function; "r": The hook is called every time Lua returns from a function; "l": The hook is called every time Lua enters a new line of code. With a C different from zero, the hook is called after every C instructions. When called without arguments, C turns off the hook. When the hook is called, its first parameter is a string describing the event that has triggered its call: C<"call">, C<"return"> (or C<"tail return">), C<"line">, and C<"count">. For line events, the hook also gets the new line number as its second parameter. Inside a hook, you can call C with level 2 to get more information about the running function (level 0 is the C function, and level 1 is the hook function), unless the event is C<"tail return">. In this case, Lua is only simulating the return, and a call to C will return invalid data. =head2 C debug.setlocal ([thread,] level, local, value) This function assigns the value C to the local variable with index C of the function at level C of the stack. The function returns C if there is no local variable with the given index, and raises an error when called with a C out of range. (You can call C to check whether the level is valid.) Otherwise, it returns the name of the local variable. =head2 C debug.setmetatable (object, table) Sets the metatable for the given C to the given C
(which can be C). =head2 C debug.setupvalue (func, up, value) This function assigns the value C to the upvalue with index C of the function C. The function returns C if there is no upvalue with the given index. Otherwise, it returns the name of the upvalue. =head2 C debug.traceback ([thread,] [message]) Returns a string with a traceback of the call stack. An optional C string is appended at the beginning of the traceback. This function is typically used with C to produce better error messages. =head1 VERSION This is Lua version 5.1.1. =head1 CREDITS Lua is developed at Lua.org, a laboratory of the Department of Computer Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro in Brazil). For more information about the authors, see http://www.lua.org/authors.html . =head1 LICENSE Lua is licensed under the terms of the MIT license reproduced below. This means that Lua is free software and can be used for both academic and commercial purposes at absolutely no cost. For details and rationale, see http://www.lua.org/license.html . ~~~~~ Copyright (C) 1994-2006 Lua.org, PUC-Rio. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ~~~~~