Home Explore Blog CI



neovim

74th chunk of `runtime/doc/luaref.txt`
b8edf57ff12e4e07d2b876c5756f2ebef5c6911ed0a466640000000100000fa4
        `lua_getinfo` (see |lua_getinfo()|), with the string {what}
        describing which fields to fill in. The default for {what} is to get
        all information available, except the table of valid lines. If
        present, the option `f` adds a field named `func` with the function
        itself. If present, the option `L` adds a field named `activelines`
        with the table of valid lines.

        For instance, the expression `debug.getinfo(1,"n").name` returns the
        name of the current function, if a reasonable name can be found, and
        `debug.getinfo(print)` returns a table with all available information
        about the `print` function.

debug.getlocal([{thread},] {level}, {local})                  *debug.getlocal()*
        This function returns the name and the value of the local variable
        with index {local} of the function at level {level} of the stack. (The
        first parameter or local variable has index 1, and so on, until the
        last active local variable.) The function returns `nil` if there is no
        local variable with the given index, and raises an error when called
        with a {level} out of range. (You can call `debug.getinfo`
        |debug.getinfo()| to check whether the level is valid.)

        Variable names starting with `(` (open parentheses) represent
        internal variables (loop control variables, temporaries, and C
        function locals).

debug.getmetatable({object})                              *debug.getmetatable()*
        Returns the metatable of the given {object} or `nil` if it does not
        have a metatable.

debug.getregistry()                                        *debug.getregistry()*
        Returns the registry table (see |lua-registry|).

debug.getupvalue({func}, {up})                              *debug.getupvalue()*
        This function returns the name and the value of the upvalue with index
        {up} of the function {func}. The function returns `nil` if there is no
        upvalue with the given index.

debug.setfenv({object}, {table})                               *debug.setfenv()*
        Sets the environment of the given {object} to the given {table}.
        Returns {object}.

debug.sethook([{thread},] {hook}, {mask} [, {count}])          *debug.sethook()*
        Sets the given function as a hook. The string {mask} and the number
        {count} 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 {count} different from zero, the hook is called after every
        {count} instructions.

        When called without arguments, the `debug.sethook` turns off the hook.

        When the hook is called, its first parameter is a string describing
        the event that triggered its call: `"call"`, `"return"` (or
        `"tail return"`), `"line"`, and `"count"`. For line events, the hook also
        gets the new line number as its second parameter. Inside a hook, you
        can call `getinfo` with level 2 to get more information about the
        running function (level 0 is the `getinfo` function, and level 1 is
        the hook function), unless the event is `"tail return"`. In this case,
        Lua is only simulating the return, and a call to `getinfo` will return
        invalid data.

debug.setlocal([{thread},] {level}, {local}, {value})         *debug.setlocal()*
        This function assigns the value {value} to the local variable with
        index {local} of the function at level {level} of the stack. The
        function returns `nil` if there is no local variable with the given
        index, and raises an error when called with a {level} out of range.
        (You can call `getinfo` to check

Title: Lua Debug Library: Functions for Accessing and Modifying Environment, Metatables, and Hooks
Summary
This section continues describing the Lua `debug` library functions. It covers `debug.getmetatable()` to retrieve the metatable of an object, `debug.getregistry()` to get the registry table, `debug.getupvalue()` to get the name and value of a function's upvalue, `debug.setfenv()` to set the environment of an object, `debug.sethook()` to set a hook function that triggers on specific events like function calls, returns, or line changes, and `debug.setlocal()` to assign a value to a local variable at a given stack level.