Home Explore Blog CI



neovim

53th chunk of `runtime/doc/luaref.txt`
835032047410b8ff1f1386b9f66af0ba8f49776fc272a7e70000000100000fa6
 functions are
declared in `lualib.h` and should not be called directly: you must call them
like any other Lua C function, e.g., by using `lua_call` (see |lua_call()|).

==============================================================================
5.1  Basic Functions                                           *lua-lib-core*

The basic library provides some core functions to Lua. If you do not include
this library in your application, you should check carefully whether you need
to provide implementations for some of its facilities.

assert({v} [, {message}])                               *assert()*
    Issues an error when the value of its argument `v` is false (i.e., `nil` or
    `false`); otherwise, returns all its arguments. `message` is an error message;
    when absent, it defaults to "assertion failed!"

collectgarbage({opt} [, {arg}])                         *collectgarbage()*
        This function is a generic interface to the garbage collector. It
        performs different functions according to its first argument, {opt}:

        `"stop"`       stops the garbage collector.
        `"restart"`    restarts the garbage collector.
        `"collect"`    performs a full garbage-collection cycle.
        `"count"`      returns the total memory in use by Lua (in Kbytes).
        `"step"`       performs a garbage-collection step. The step "size" is
                     controlled by {arg} (larger values mean more steps) in a
                     non-specified way. If you want to control the step size
                     you must experimentally tune the value of {arg}. Returns
                     `true` if the step finished a collection cycle.
        `"setpause"`   sets {arg} /100 as the new value for the `pause` of
                     the collector (see |lua-gc|).
        `"setstepmul"` sets {arg} /100 as the new value for the
                     `step multiplier` of the collector (see |lua-gc|).

dofile({filename})                                      *dofile()*
        Opens the named file and executes its contents as a Lua chunk. When
        called without arguments, `dofile` executes the contents of the
        standard input (`stdin`). Returns all values returned by the chunk. In
        case of errors, `dofile` propagates the error to its caller (that is,
        `dofile` does not run in protected mode).

error({message} [, {level}])                            *error()*
        Terminates the last protected function called and returns `message` as
        the error message. Function {error} never returns.

        Usually, {error} adds some information about the error position at the
        beginning of the message. The {level} argument specifies how to get
        the error position. With level 1 (the default), the error position is
        where the {error} function was called. Level 2 points the error to
        where the function that called {error} was called; and so on. Passing
        a level 0 avoids the addition of error position information to the
        message.

_G                                                      *_G*
        A global variable (not a function) that holds the global environment
        (that is, `_G._G = _G`). Lua itself does not use this variable;
        changing its value does not affect any environment, nor vice-versa.
        (Use `setfenv` to change environments.)

getfenv({f})                                            *getfenv()*
        Returns the current environment in use by the function. {f} can be a
        Lua function or a number that specifies the function at that stack
        level: Level 1 is the function calling `getfenv`. If the given
        function is not a Lua function, or if {f} is 0, `getfenv` returns the
        global environment. The default for {f} is 1.

getmetatable({object})                                  *getmetatable()*
        If {object} does not have a metatable, returns `nil`. Otherwise, if
        the object's metatable has a `"__metatable"`

Title: Lua Basic Functions (Continued)
Summary
Continuation of the basic functions in Lua, detailing 'collectgarbage' and its various options for garbage collection control. It then describes the 'dofile' function, which executes Lua chunks from files or standard input. Following this is 'error', which terminates the last protected function call and provides an error message, along with options for specifying the error position. The section continues with '_G', a global variable holding the global environment, 'getfenv', which returns the current environment of a function, and 'getmetatable', which retrieves the metatable of an object.