Home Explore Blog CI



neovim

38th chunk of `runtime/doc/luaref.txt`
73b30d63861118dfdcc65f95a5c4564cf99d4b05fb21299f0000000100000fa3
 every
        function in the library, except to `lua_newstate` (see
        |lua_newstate()|), which creates a Lua state from scratch.

lua_status                                                        *lua_status()*
>c
    int lua_status (lua_State *L);
<
        Returns the status of the thread `L`.

        The status can be 0 for a normal thread, an error code if the thread
        finished its execution with an error, or `LUA_YIELD` if the thread is
        suspended.

lua_toboolean                                                  *lua_toboolean()*
>c
    int lua_toboolean (lua_State *L, int index);
<
        Converts the Lua value at the given acceptable index to a C boolean
        value (0 or 1). Like all tests in Lua, `lua_toboolean` returns 1 for
        any Lua value different from `false` and `nil`; otherwise it returns
        0. It also returns 0 when called with a non-valid index. (If you want
           to accept only actual boolean values, use `lua_isboolean`
           |lua_isboolean()| to test the value's type.)

lua_tocfunction                                              *lua_tocfunction()*
>c
    lua_CFunction lua_tocfunction (lua_State *L, int index);
<
        Converts a value at the given acceptable index to a C function. That
        value must be a C function; otherwise it returns `NULL`.

lua_tointeger                                                  *lua_tointeger()*
>c
    lua_Integer lua_tointeger (lua_State *L, int idx);
<
        Converts the Lua value at the given acceptable index to the signed
        integral type `lua_Integer` (see |lua_Integer|). The Lua value
        must be a number or a string convertible to a number (see
        |lua-coercion|); otherwise, `lua_tointeger` returns 0.

        If the number is not an integer, it is truncated in some non-specified
        way.

lua_tolstring                                                  *lua_tolstring()*
>c
    const char *lua_tolstring (lua_State *L, int index, size_t *len);
<
        Converts the Lua value at the given acceptable index to a C string. If
        `len` is not `NULL`, it also sets `*len` with the string length. The
        Lua value must be a string or a number; otherwise, the function
        returns `NULL`. If the value is a number, then `lua_tolstring`  also
        `changes the actual value in the stack to a` `string`. (This change
        confuses `lua_next` |lua_next()| when `lua_tolstring` is applied
        to keys during a table traversal.)

        `lua_tolstring` returns a fully aligned pointer to a string inside the
        Lua state. This string always has a zero (`\0`) after its last
        character (as in C), but may contain other zeros in its body. Because
        Lua has garbage collection, there is no guarantee that the pointer
        returned by `lua_tolstring` will be valid after the corresponding
        value is removed from the stack.

lua_tonumber                                                    *lua_tonumber()*
>c
    lua_Number lua_tonumber (lua_State *L, int index);
<
        Converts the Lua value at the given acceptable index to the C type
        `lua_Number` (see |lua_Number|). The Lua value must be a number
        or a string convertible to a number (see |lua-coercion|);
        otherwise, `lua_tonumber` returns 0.

lua_topointer                                                  *lua_topointer()*
>c
    const void *lua_topointer (lua_State *L, int index);
<
        Converts the value at the given acceptable index to a generic C
        pointer (`void*`). The value may be a userdata, a table, a thread, or
        a function; otherwise, `lua_topointer` returns `NULL`. Different
        objects will give different pointers. There is no way to convert the
        pointer back to its original value.

        Typically this function is used only for debug information.

lua_tostring                                                    *lua_tostring()*
>c
    const char *lua_tostring (lua_State

Title: Lua C API: Conversion Functions (Boolean, C Function, Integer, String, Number, Pointer)
Summary
This section details functions in the Lua C API for converting Lua values to C types. It covers `lua_toboolean` for converting to a C boolean, `lua_tocfunction` for converting to a C function, `lua_tointeger` for converting to a Lua integer, `lua_tolstring` for converting to a C string with length, `lua_tonumber` for converting to a Lua number, and `lua_topointer` for converting to a generic C pointer.