Home Explore Blog CI



neovim

49th chunk of `runtime/doc/luaref.txt`
12b4ef58ebfccb72a7cae81c56f44e60c0c147b87c68325b0000000100000fa2
 (lua_State *L,
                           const char *s,
                           const char *p,
                           const char *r);
<
        Creates a copy of string `s` by replacing any occurrence of the string
        `p` with the string `r`. Pushes the resulting string on the stack and
        returns it.

luaL_loadbuffer                                              *luaL_loadbuffer()*
>c
    int luaL_loadbuffer (lua_State *L,
                         const char *buff,
                         size_t sz,
                         const char *name);
<
        Loads a buffer as a Lua chunk. This function uses `lua_load` (see
        |lua_load()|) to load the chunk in the buffer pointed to by
        `buff` with size `sz`.

        This function returns the same results as `lua_load`. `name` is the
        chunk name, used for debug information and error messages.

luaL_loadfile                                                  *luaL_loadfile()*
>c
    int luaL_loadfile (lua_State *L, const char *filename);
<
        Loads a file as a Lua chunk. This function uses `lua_load` (see
        |lua_load()|) to load the chunk in the file named `filename`. If
        `filename` is `NULL`, then it loads from the standard input. The first
        line in the file is ignored if it starts with a `#`.

        This function returns the same results as `lua_load`, but it has an
        extra error code `LUA_ERRFILE` if it cannot open/read the file.

        As `lua_load`, this function only loads the chunk; it does not run it.

luaL_loadstring                                              *luaL_loadstring()*
>c
    int luaL_loadstring (lua_State *L, const char *s);
<
        Loads a string as a Lua chunk. This function uses `lua_load` (see
        |lua_load()|) to load the chunk in the zero-terminated string
        `s`.

        This function returns the same results as `lua_load`.

        Also as `lua_load`, this function only loads the chunk; it does not
        run it.

luaL_newmetatable                                          *luaL_newmetatable()*
>c
    int luaL_newmetatable (lua_State *L, const char *tname);
<
        If the registry already has the key `tname`, returns 0. Otherwise,
        creates a new table to be used as a metatable for userdata, adds it to
        the registry with key `tname`, and returns 1.

        In both cases pushes onto the stack the final value associated with
        `tname` in the registry.

luaL_newstate                                                  *luaL_newstate()*
>c
    lua_State *luaL_newstate (void);
<
        Creates a new Lua state. It calls `lua_newstate` (see
        |lua_newstate()|) with an allocator based on the standard C
        `realloc` function and then sets a panic function (see
        |lua_atpanic()|) that prints an error message to the standard
        error output in case of fatal errors.

        Returns the new state, or `NULL` if there is a memory allocation
        error.

luaL_openlibs                                                  *luaL_openlibs()*
>c
    void luaL_openlibs (lua_State *L);
<
        Opens all standard Lua libraries into the given state. See also
        |lua-openlibs| for details on how to open individual libraries.

luaL_optint                                                      *luaL_optint()*
>c
    int luaL_optint (lua_State *L, int narg, int d);
<
        If the function argument `narg` is a number, returns this number cast
        to an `int`. If this argument is absent or is `nil`, returns `d`.
        Otherwise, raises an error.

luaL_optinteger                                              *luaL_optinteger()*
>c
    lua_Integer luaL_optinteger (lua_State *L,
                                 int narg,
                                 lua_Integer d);
<
        If the function argument `narg` is a number, returns this number cast
        to a `lua_Integer` (see |lua_Integer|). If this argument is
        absent or is `nil`, returns `d`.

Title: Lua Auxiliary Library Functions: Loading Chunks, Metatables, States, and Argument Handling
Summary
This section describes Lua auxiliary library functions for loading Lua chunks from strings, buffers, and files (luaL_loadstring, luaL_loadbuffer, luaL_loadfile), creating and retrieving metatables (luaL_newmetatable), creating a new Lua state (luaL_newstate), opening standard Lua libraries (luaL_openlibs), and handling optional integer arguments (luaL_optint, luaL_optinteger).