Home Explore Blog CI



neovim

39th chunk of `runtime/doc/luaref.txt`
3ca9057f07689d242d82af3bc5fc2321be442fe1c13607810000000100000fa2

>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 *L, int index);
<
        Equivalent to `lua_tolstring` (see |lua_tolstring()|) with `len`
        equal to `NULL`.

lua_tothread                                                    *lua_tothread()*
>c
    lua_State *lua_tothread (lua_State *L, int index);
<
        Converts the value at the given acceptable index to a Lua thread
        (represented as `lua_State*` |lua_State|). This value must be a
        thread; otherwise, the function returns `NULL`.

lua_touserdata                                                *lua_touserdata()*
>c
    void *lua_touserdata (lua_State *L, int index);
<
        If the value at the given acceptable index is a full userdata, returns
        its block address. If the value is a light userdata, returns its
        pointer. Otherwise, it returns `NULL`.

lua_type                                                            *lua_type()*
>c
    int lua_type (lua_State *L, int index);
<
        Returns the type of the value in the given acceptable index, or
        `LUA_TNONE` for a non-valid index (that is, an index to an "empty"
        stack position). The types returned by `lua_type` are coded by the
        following constants defined in `lua.h` : `LUA_TNIL`, `LUA_TNUMBER`,
        `LUA_TBOOLEAN`, `LUA_TSTRING`, `LUA_TTABLE`, `LUA_TFUNCTION`,
        `LUA_TUSERDATA`, `LUA_TTHREAD`, and `LUA_TLIGHTUSERDATA`.

lua_typename                                                    *lua_typename()*
>c
    const char *lua_typename  (lua_State *L, int tp);
<
        Returns the name of the type encoded by the value `tp`, which must be
        one the values returned by `lua_type`.

lua_Writer                                                          *lua_Writer*
>c
    typedef int (*lua_Writer) (lua_State *L,
                               const void* p,
                               size_t sz,
                               void* ud);
<
        The writer function used by `lua_dump` (see |lua_dump()|). Every
        time it produces another piece of chunk, `lua_dump` calls the writer,
        passing along the buffer to be written (`p`), its size (`sz`), and the
        `data` parameter supplied to `lua_dump`.

        The writer returns an error code: 0 means no errors; any other value
        means an error and stops `lua_dump` from calling the writer again.

lua_xmove                                                          *lua_xmove()*
>c
    void lua_xmove (lua_State *from, lua_State *to, int n);
<
        Exchange values between different threads of the `same` global state.

        This function pops `n` values from the stack `from`, and pushes them
        onto the stack `to`.

lua_yield                                                          *lua_yield()*
>c
    int lua_yield (lua_State *L, int nresults);
<
        Yields a coroutine.

        This function should only be called as the return expression of a C
        function, as follows:
>c
               return lua_yield (L, nresults);
<
        When a C function

Title: Lua C API: Conversion and Type Functions (Number, Pointer, String, Thread, Userdata, Type, Typename), Writer Function, Thread Exchange, Coroutine Yield
Summary
This section details several functions in the Lua C API. It covers functions for converting Lua values to a C number (`lua_tonumber`), a generic C pointer (`lua_topointer`), a C string (`lua_tostring`), a Lua thread (`lua_tothread`), and userdata (`lua_touserdata`). It also includes functions for determining the type of a Lua value (`lua_type` and `lua_typename`). Furthermore, it describes the `lua_Writer` function type, used for writing chunks, the `lua_xmove` function for exchanging values between threads, and the `lua_yield` function for yielding a coroutine.