Home Explore Blog CI



neovim

47th chunk of `runtime/doc/luaref.txt`
963da473ca48f3bf84d7b495b92494f24367c533213db2470000000100000fa2
 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 number cast to a `lua_Integer` (see |lua_Integer|).

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

luaL_checklstring                                          *luaL_checklstring()*
>c
    const char *luaL_checklstring (lua_State *L, int narg, size_t *l);
<
        Checks whether the function argument `narg` is a string and returns
        this string; if `l` is not `NULL` fills `*l` with the string's length.

luaL_checknumber                                            *luaL_checknumber()*
>c
    lua_Number luaL_checknumber (lua_State *L, int narg);
<
        Checks whether the function argument `narg` is a number and returns
        this number (see |lua_Number|).

luaL_checkoption                                            *luaL_checkoption()*
>c
    int luaL_checkoption (lua_State *L,
                          int narg,
                          const char *def,
                          const char *const lst[]);
<
        Checks whether the function argument `narg` is a string and searches
        for this string in the array `lst` (which must be NULL-terminated).
        Returns the index in the array where the string was found. Raises an
        error if the argument is not a string or if the string cannot be
        found.

        If `def` is not `NULL`, the function uses `def` as a default value
        when there is no argument `narg` or if this argument is `nil`.

        This is a useful function for mapping strings to C enums. (The usual
        convention in Lua libraries is to use strings instead of numbers to
        select options.)

luaL_checkstack                                              *luaL_checkstack()*
>c
    void luaL_checkstack (lua_State *L, int sz, const char *msg);
<
        Grows the stack size to `top + sz` elements, raising an error if the
        stack cannot grow to that size. `msg` is an additional text to go into
        the error message.

luaL_checkstring                                            *luaL_checkstring()*
>c
    const char *luaL_checkstring (lua_State *L, int narg);
<
        Checks whether the function argument `narg` is a string and returns
        this string.

luaL_checktype                                                *luaL_checktype()*
>c
    void luaL_checktype (lua_State *L, int narg, int t);
<
        Checks whether the function argument `narg` has type `t` (see
        |lua_type()|).

luaL_checkudata                                              *luaL_checkudata()*
>c
    void *luaL_checkudata (lua_State *L, int narg, const char *tname);
<
        Checks whether the function argument `narg` is a userdata of the type
        `tname` (see |luaL_newmetatable()|).

luaL_dofile                                                      *luaL_dofile()*
>c
    int luaL_dofile (lua_State *L, const

Title: Lua Auxiliary Library: Argument Checking Functions
Summary
This section details several functions from the Lua Auxiliary Library designed for argument checking within C functions. It covers `luaL_checkany`, `luaL_checkint`, `luaL_checkinteger`, `luaL_checklong`, `luaL_checklstring`, `luaL_checknumber`, `luaL_checkoption`, `luaL_checkstack`, `luaL_checkstring`, `luaL_checktype`, and `luaL_checkudata`, all of which ensure arguments passed to Lua functions from C code are of the expected type and format. Additionally, `luaL_dofile` is introduced.