Home Explore Blog CI



neovim

46th chunk of `runtime/doc/luaref.txt`
08dfaee42e9a29b8c009c82ab3b11ae124533312ed54fffa0000000100000fa4
 an extra element on the stack, which is the value to be
        added to the buffer.

luaL_argcheck                                                  *luaL_argcheck()*
>c
    void luaL_argcheck (lua_State *L,
                        int cond,
                        int narg,
                        const char *extramsg);
<
        Checks whether `cond` is true. If not, raises an error with the
        following message, where `func` is retrieved from the call stack:
>
               bad argument #<narg> to <func> (<extramsg>)
<

luaL_argerror                                                  *luaL_argerror()*
>c
    int luaL_argerror (lua_State *L, int narg, const char *extramsg);
<
        Raises an error with the following message, where `func` is retrieved
        from the call stack:
>
               bad argument #<narg> to <func> (<extramsg>)
<
        This function never returns, but it is an idiom to use it in C
        functions as `return luaL_argerror(` `args` `)`.

luaL_Buffer                                                        *luaL_Buffer*
>c
    typedef struct luaL_Buffer luaL_Buffer;
<
        Type for a `string buffer`.

        A string buffer allows C code to build Lua strings piecemeal. Its
        pattern of use is as follows:

         - First you declare a variable `b` of type `luaL_Buffer`.
         - Then you initialize it with a call `luaL_buffinit(L, &b)` (see
           |luaL_buffinit()|).
         - Then you add string pieces to the buffer calling any of the
           `luaL_add*` functions.
         - You finish by calling `luaL_pushresult(&b)` (see
           |luaL_pushresult()|). This call leaves the final string on the
           top of the stack.

        During its normal operation, a string buffer uses a variable number of
        stack slots. So, while using a buffer, you cannot assume that you know
        where the top of the stack is. You can use the stack between
        successive calls to buffer operations as long as that use is balanced;
        that is, when you call a buffer operation, the stack is at the same
        level it was immediately after the previous buffer operation. (The
        only exception to this rule is `luaL_addvalue`
        |luaL_addvalue()|.) After calling `luaL_pushresult` the stack is
        back to its level when the buffer was initialized, plus the final
        string on its top.

luaL_buffinit                                                  *luaL_buffinit()*
>c
    void luaL_buffinit (lua_State *L, luaL_Buffer *B);
<
        Initializes a buffer `B`. This function does not allocate any space;
        the buffer must be declared as a variable (see |luaL_Buffer|).

luaL_callmeta                                                  *luaL_callmeta()*
>c
    int luaL_callmeta (lua_State *L, int obj, const char *e);
<
        Calls a metamethod.

        If the object at index `obj` has a metatable and this metatable has a
        field `e`, this function calls this field and passes the object as its
        only argument. In this case this function returns 1 and pushes onto
        the stack the value returned by the call. If there is no metatable or
        no metamethod, this function returns
        0 (without pushing any value on the stack).

luaL_checkany                                                  *luaL_checkany()*
>c
    void luaL_checkany (lua_State *L, int narg);
<
        Checks whether the function has an argument of any type (including
        `nil`) at position `narg`.

luaL_checkint                                                  *luaL_checkint()*
>c
    int luaL_checkint (lua_State *L, int narg);
<
        Checks whether the function argument `narg` is a number and returns
        this number cast to an `int`.

luaL_checkinteger                                          *luaL_checkinteger()*
>c
    lua_Integer luaL_checkinteger (lua_State *L, int narg);
<
        Checks whether the function argument `narg` is a number and returns
        this

Title: Lua Auxiliary Library: Argument Checks, Buffers and Metamethod Calls
Summary
This section describes functions related to argument checks (`luaL_argcheck`, `luaL_argerror`), introduces the `luaL_Buffer` type for building Lua strings piecemeal, and provides functions for buffer initialization (`luaL_buffinit`). It also covers the function `luaL_callmeta` for calling metamethods, and functions for checking argument types, such as `luaL_checkany`, `luaL_checkint`, and `luaL_checkinteger`.