Home Explore Blog CI



neovim

52th chunk of `runtime/doc/luaref.txt`
19e552ec2c7b9915d7e5215a61595cb63cde9e5fbd601c3a0000000100000fa2
 `location`  `: bad argument`  `narg`  `to`  `'func'`  `(`  `tname`
          `expected, got`  `rt`  `)`

        where `location` is produced by `luaL_where`  (see
        |luaL_where()|), `func` is the name of the current function, and
        `rt` is the type name of the actual argument.

luaL_unref                                                        *luaL_unref()*
>c
    void luaL_unref (lua_State *L, int t, int ref);
<
        Releases reference `ref` from the table at index `t` (see
        |luaL_ref()|). The entry is removed from the table, so that the
        referred object can be collected. The reference `ref` is also freed to
        be used again.

        If `ref` is `LUA_NOREF` or `LUA_REFNIL`, `luaL_unref` does nothing.

luaL_where                                                        *luaL_where()*
>c
    void luaL_where (lua_State *L, int lvl);
<
        Pushes onto the stack a string identifying the current position of the
        control at level `lvl` in the call stack. Typically this string has
        the following format:

            `chunkname:currentline:`

        Level 0 is the running function, level 1 is the function that called
        the running function, etc.

        This function is used to build a prefix for error messages.

==============================================================================
5  STANDARD LIBRARIES                                               *lua-lib*

The standard libraries provide useful functions that are implemented directly
through the C API. Some of these functions provide essential services to the
language (e.g., `type` and `getmetatable`); others provide access to "outside"
services (e.g., I/O); and others could be implemented in Lua itself, but are
quite useful or have critical performance requirements that deserve an
implementation in C (e.g., `sort`).

All libraries are implemented through the official C API and are provided as
separate C modules. Currently, Lua has the following standard libraries:

- basic library;
- package library;
- string manipulation;
- table manipulation;
- mathematical functions (sin, log, etc.);
- input and output;
- operating system facilities;
- debug facilities.

Except for the basic and package libraries, each library provides all its
functions as fields of a global table or as methods of its objects.

                                                               *lua-openlibs*
To have access to these libraries, the C host program should call the
`luaL_openlibs` function, which opens all standard libraries (see
|luaL_openlibs()|). Alternatively, the host program can open the libraries
individually by calling `luaopen_base` (for the basic library),
`luaopen_package` (for the package library), `luaopen_string` (for the string
library), `luaopen_table` (for the table library), `luaopen_math` (for the
mathematical library), `luaopen_io` (for the I/O and the Operating System
libraries), and `luaopen_debug` (for the debug library). These 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

Title: Lua Standard Libraries: Overview and Basic Functions
Summary
This section covers the `luaL_unref` function, which releases a reference in a table, and `luaL_where`, which pushes a string identifying the current position in the call stack for error messages. It then transitions into an overview of Lua's standard libraries, including the basic, package, string, table, math, I/O, OS, and debug libraries. It explains how to access these libraries using `luaL_openlibs` or by opening them individually. The section concludes by detailing the basic library, focusing on the `assert` and `collectgarbage` functions.