Home Explore Blog CI



neovim

56th chunk of `runtime/doc/luaref.txt`
d9715c13f9723081648918d30fd1ab9b7fe9c9cee19accf80000000100000fa8
 environment to be used by the given function. {f} can be a
        Lua function or a number that specifies the function at that stack
        level: Level 1 is the function calling `setfenv`. `setfenv` returns
        the given function.

        As a special case, when {f} is 0 `setfenv` changes the environment of
        the running thread. In this case, `setfenv` returns no values.

setmetatable({table}, {metatable})                      *setmetatable()*
        Sets the metatable for the given table. (You cannot change the
        metatable of other types from Lua, only from C.) If {metatable} is
        `nil`, removes the metatable of the given table. If the original
        metatable has a `"__metatable"` field, raises an error.

        This function returns {table}.

tonumber({e} [, {base}])                                *tonumber()*
        Tries to convert its argument to a number. If the argument is already
        a number or a string convertible to a number, then `tonumber` returns
        this number; otherwise, it returns `nil`.

        An optional argument specifies the base to interpret the numeral. The
        base may be any integer between 2 and 36, inclusive. In bases above
        10, the letter `A` (in either upper or lower case) represents 10, `B`
        represents 11, and so forth, with `Z'` representing 35. In base 10
        (the default), the number may have a decimal part, as well as an
        optional exponent part (see |lua-lexical|). In other bases,
        only unsigned integers are accepted.

tostring({e})                                           *tostring()*
        Receives an argument of any type and converts it to a string in a
        reasonable format. For complete control of how numbers are converted,
        use `string.format` (see |string.format()|).

                                                        *__tostring*
        If the metatable of {e} has a `"__tostring"` field, `tostring` calls
        the corresponding value with {e} as argument, and uses the result of
        the call as its result.

type({v})                                               *lua-type()*
        Returns the type of its only argument, coded as a string. The possible
        results of this function are `"nil"` (a string, not the value `nil`),
        `"number"`, `"string"`, `"boolean`, `"table"`, `"function"`,
        `"thread"`, and `"userdata"`.

unpack({list} [, {i} [, {j}]])                          *unpack()*
        Returns the elements from the given table. This function is equivalent
        to
>lua
          return list[i], list[i+1], ..., list[j]
<
        except that the above code can be written only for a fixed number of
        elements. By default, {i} is 1 and {j} is the length of the list, as
        defined by the length operator (see |lua-length|).

_VERSION                                                *_VERSION*
        A global variable (not a function) that holds a string containing the
        current interpreter version. The current contents of this string is
        `"Lua 5.1"` .

xpcall({f}, {err})                                      *xpcall()*
        This function is similar to `pcall` (see |pcall()|), except that you
        can set a new error handler.

        `xpcall` calls function {f} in protected mode, using {err} as the
        error handler. Any error inside {f} is not propagated; instead,
        `xpcall` catches the error, calls the {err} function with the original
        error object, and returns a status code. Its first result is the
        status code (a boolean), which is true if the call succeeds without
        errors. In this case, `xpcall` also returns all results from the call,
        after this first result. In case of any error, `xpcall` returns
        `false` plus the result from {err}.

==============================================================================
5.2  Coroutine Manipulation                     *lua-lib-coroutine*

The operations

Title: Lua Basic Functions (Continued)
Summary
This section continues describing Lua basic functions: `setfenv` (setting a function's environment), `setmetatable` (setting a table's metatable), `tonumber` (converting a value to a number), `tostring` (converting a value to a string), `type` (returning the type of a value as a string), `unpack` (returning elements from a table), `_VERSION` (a global variable holding the Lua version), and `xpcall` (calling a function in protected mode with a custom error handler). It then introduces coroutine manipulation.