Home Explore Blog CI



neovim

51th chunk of `runtime/doc/luaref.txt`
b781cfcb7a625359a09c7627f5ba6816e43e2345af6b46f50000000100000fa1
 with the size of the string to actually
        add it to the buffer.

luaL_pushresult                                              *luaL_pushresult()*
>c
    void luaL_pushresult (luaL_Buffer *B);
<
        Finishes the use of buffer `B` leaving the final string on the top of
        the stack.

luaL_ref                                                            *luaL_ref()*
>c
    int luaL_ref (lua_State *L, int t);
<
        Creates and returns a `reference`, in the table at index `t`, for the
        object at the top of the stack (and pops the object).

        A reference is a unique integer key. As long as you do not manually
        add integer keys into table `t`, `luaL_ref` ensures the uniqueness of
        the key it returns. You can retrieve an object referred by reference
        `r` by calling `lua_rawgeti(L, t, r)` (see |lua_rawgeti()|).
        Function `luaL_unref` (see |luaL_unref()|) frees a reference and
        its associated object.

        If the object at the top of the stack is `nil`, `luaL_ref` returns the
        constant `LUA_REFNIL`. The constant `LUA_NOREF` is guaranteed to be
        different from any reference returned by `luaL_ref`.

luaL_Reg                                                              *luaL_Reg*
>c
    typedef struct luaL_Reg {
        const char *name;
        lua_CFunction func;
    } luaL_Reg;
<
        Type for arrays of functions to be registered by `luaL_register`  (see
        |luaL_register()|). `name` is the function name and `func` is a
        pointer to the function. Any array of `luaL_Reg` must end with a
        sentinel entry in which both `name` and `func` are `NULL`.

luaL_register                                                  *luaL_register()*
>c
    void luaL_register (lua_State *L,
                        const char *libname,
                        const luaL_Reg *l);
<
        Opens a library.

        When called with `libname` equal to `NULL`, it simply registers all
        functions in the list `l` (see |luaL_Reg|) into the table on
        the top of the stack.

        When called with a non-null `libname`, `luaL_register` creates a new
        table `t`, sets it as the value of the global variable `libname`, sets
        it as the value of `package.loaded[libname]`, and registers on it all
        functions in the list `l`. If there is a table in
        `package.loaded[libname]` or in variable `libname`, reuses this table
        instead of creating a new one.

        In any case the function leaves the table on the top of the stack.

luaL_typename                                                  *luaL_typename()*
>c
    const char *luaL_typename (lua_State *L, int idx);
<
        Returns the name of the type of the value at index `idx`.

luaL_typerror                                                  *luaL_typerror()*
>c
    int luaL_typerror (lua_State *L, int narg, const char *tname);
<
        Generates an error with a message like the following:

          `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

Title: Lua Auxiliary Library: References, Library Registration, and Error Handling
Summary
This section covers several Lua auxiliary library functions. It details the reference system for storing and retrieving values, including luaL_ref and luaL_unref. It explains luaL_Reg for defining function arrays for library registration, along with luaL_register for opening and registering libraries. Additionally, it describes luaL_typename for obtaining the type name of a value, luaL_typerror for generating type error messages, and luaL_where for pushing a string identifying the current position of the control at a specific level in the call stack.