Home Explore Blog CI



neovim

34th chunk of `runtime/doc/luaref.txt`
de1344135f7eadd3b0b38e108aef7bf82108f71cac0b24fe0000000100000fa1
 invokes the corresponding C function.

        Any function to be registered in Lua must follow the correct protocol
        to receive its parameters and return its results (see
        |lua_CFunction|).

        `lua_pushcfunction` is defined as a macro:
>c
            #define lua_pushcfunction(L,f)  lua_pushcclosure(L,f,0)
<

lua_pushfstring                                              *lua_pushfstring()*
>c
    const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
<
        Pushes onto the stack a formatted string and returns a pointer to this
        string. It is similar to the C function `sprintf`, but has some
        important differences:

         - You do not have to allocate space for the result: the result is a
           Lua string and Lua takes care of memory allocation (and
           deallocation, through garbage collection).
         - The conversion specifiers are quite restricted. There are no flags,
           widths, or precisions. The conversion specifiers can only be `%%`
           (inserts a `%` in the string), `%s` (inserts a zero-terminated
           string, with no size restrictions), `%f` (inserts a
           `lua_Number`), `%p` (inserts a pointer as a hexadecimal numeral),
           `%d` (inserts an `int`), and `%c` (inserts an `int` as a
           character).

lua_pushinteger                                              *lua_pushinteger()*
>c
    void lua_pushinteger (lua_State *L, lua_Integer n);
<
        Pushes a number with value `n` onto the stack.

lua_pushlightuserdata                                  *lua_pushlightuserdata()*
>c
    void lua_pushlightuserdata (lua_State *L, void *p);
<
        Pushes a light userdata onto the stack.
                                                          *lua-lightuserdata*
        Userdata represents C values in Lua. A light userdata represents a
        pointer. It is a value (like a number): you do not create it, it has
        no individual metatable, and it is not collected (as it was never
        created). A light userdata is equal to "any" light userdata with the
        same C address.

lua_pushlstring                                              *lua_pushlstring()*
>c
    void lua_pushlstring (lua_State *L, const char *s, size_t len);
<
        Pushes the string pointed to by `s` with size `len` onto the stack.
        Lua makes (or reuses) an internal copy of the given string, so the
        memory at `s` can be freed or reused immediately after the function
        returns. The string can contain embedded zeros.

lua_pushnil                                                      *lua_pushnil()*
>c
    void lua_pushnil (lua_State *L);
<
        Pushes a nil value onto the stack.

lua_pushnumber                                                *lua_pushnumber()*
>c
    void lua_pushnumber (lua_State *L, lua_Number n);
<
        Pushes a number with value `n` onto the stack.

lua_pushstring                                                *lua_pushstring()*
>c
    void lua_pushstring (lua_State *L, const char *s);
<
        Pushes the zero-terminated string pointed to by `s` onto the stack.
        Lua makes (or reuses) an internal copy of the given string, so the
        memory at `s` can be freed or reused immediately after the function
        returns. The string cannot contain embedded zeros; it is assumed to
        end at the first zero.

lua_pushthread                                                *lua_pushthread()*
>c
    int lua_pushthread (lua_State *L);
<
        Pushes the thread represented by `L` onto the stack. Returns 1 if this
        thread is the main thread of its state.

lua_pushvalue                                                  *lua_pushvalue()*
>c
    void lua_pushvalue (lua_State *L, int index);
<
        Pushes a copy of the element at the given valid index onto the stack.

lua_pushvfstring                                            *lua_pushvfstring()*
>c
    const char *lua_pushvfstring (lua_State *L,

Title: Lua C API: Pushing Various Data Types onto the Stack
Summary
This section documents various functions in the Lua C API for pushing different data types onto the Lua stack. It covers `lua_pushfstring` for pushing formatted strings with specific conversion specifiers, `lua_pushinteger` and `lua_pushnumber` for pushing integer and floating-point numbers, `lua_pushlightuserdata` for pushing light userdata (pointers), `lua_pushlstring` for pushing strings with a specified length (allowing embedded zeros), `lua_pushnil` for pushing nil values, `lua_pushstring` for pushing zero-terminated strings, `lua_pushthread` for pushing the current thread, and `lua_pushvalue` for pushing a copy of a stack element.