Skip to content

debuglib

debug

function debug.debug()

Enters an interactive mode with the user, running each string that the user enters.

View documents

getfenv

function debug.getfenv(o: any)
  -> table

Returns the environment of object o .

View documents

gethook

function debug.gethook(co?: thread)
  -> hook: function
  2. mask: string
  3. count: integer

Returns the current hook settings of the thread.

View documents

getinfo

function debug.getinfo(thread: thread, f: integer|fun(...any):...unknown, what?: string|"L"|"S"|"f"|"l"...(+4))
  -> debuginfo

Returns a table with information about a function.

View documents


what:
   +> "n" -- `name` and `namewhat`
   +> "S" -- `source`, `short_src`, `linedefined`, `lastlinedefined`, and `what`
   +> "l" -- `currentline`
   +> "t" -- `istailcall`
   +> "u" -- `nups`, `nparams`, and `isvararg`
   +> "f" -- `func`
   +> "r" -- `ftransfer` and `ntransfer`
   +> "L" -- `activelines`

getlocal

function debug.getlocal(thread: thread, f: integer|fun(...any):...unknown, index: integer)
  -> name: string
  2. value: any

Returns the name and the value of the local variable with index local of the function at level f of the stack.

View documents

getmetatable

function debug.getmetatable(object: any)
  -> metatable: table

Returns the metatable of the given value.

View documents

getregistry

function debug.getregistry()
  -> table

Returns the registry table.

View documents

getupvalue

function debug.getupvalue(f: fun(...any):...unknown, up: integer)
  -> name: string
  2. value: any

Returns the name and the value of the upvalue with index up of the function.

View documents

getuservalue

function debug.getuservalue(u: userdata, n?: integer)
  -> any
  2. boolean

Returns the n-th user value associated to the userdata u plus a boolean, false if the userdata does not have that value.

View documents

setcstacklimit

function debug.setcstacklimit(limit: integer)
  -> boolean|integer

Deprecated in Lua 5.4.2

Sets a new limit for the C stack. This limit controls how deeply nested calls can go in Lua, with the intent of avoiding a stack overflow.

In case of success, this function returns the old limit. In case of error, it returns false.

View documents

setfenv

function debug.setfenv(object: <T>, env: table)
  -> object: <T>

Sets the environment of the given object to the given table .

View documents

sethook

function debug.sethook(thread: thread, hook: fun(...any):...unknown, mask: string|"c"|"l"|"r", count?: integer)

Sets the given function as a hook.

View documents


mask:
   +> "c" -- Calls hook when Lua calls a function.
   +> "r" -- Calls hook when Lua returns from a function.
   +> "l" -- Calls hook when Lua enters a new line of code.

setlocal

function debug.setlocal(thread: thread, level: integer, index: integer, value: any)
  -> name: string

Assigns the value to the local variable with index local of the function at level of the stack.

View documents

setmetatable

function debug.setmetatable(value: <T>, meta?: table)
  -> value: <T>

Sets the metatable for the given value to the given table (which can be nil).

View documents

setupvalue

function debug.setupvalue(f: fun(...any):...unknown, up: integer, value: any)
  -> name: string

Assigns the value to the upvalue with index up of the function.

View documents

setuservalue

function debug.setuservalue(udata: userdata, value: any, n?: integer)
  -> udata: userdata

Sets the given value as the n-th user value associated to the given udata. udata must be a full userdata.

View documents

traceback

function debug.traceback(thread: thread, message?: any, level?: integer)
  -> message: string

Returns a string with a traceback of the call stack. The optional message string is appended at the beginning of the traceback.

View documents

upvalueid

function debug.upvalueid(f: fun(...any):...unknown, n: integer)
  -> id: lightuserdata

Returns a unique identifier (as a light userdata) for the upvalue numbered n from the given function.

View documents

upvaluejoin

function debug.upvaluejoin(f1: fun(...any):...unknown, n1: integer, f2: fun(...any):...unknown, n2: integer)

Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of the Lua closure f2.

View documents