Home Explore Blog CI



neovim

27th chunk of `runtime/doc/lua.txt`
fe185844a834d99927724e99913b6ded4dda13ec2ea0a2280000000100000fc4
 to
    the same functions as those in the input table. Userdata and threads are
    not copied and will throw an error.

    Note: `noref=true` is much more performant on tables with unique table
    fields, while `noref=false` is more performant on tables that reuse table
    fields.

    Parameters: ~
      • {orig}   (`table`) Table to copy
      • {noref}  (`boolean?`) When `false` (default) a contained table is only
                 copied once and all references point to this single copy.
                 When `true` every occurrence of a table results in a new
                 copy. This also means that a cyclic reference can cause
                 `deepcopy()` to fail.

    Return: ~
        (`table`) Table of copied keys and (nested) values.

vim.defaulttable({createfn})                              *vim.defaulttable()*
    Creates a table whose missing keys are provided by {createfn} (like
    Python's "defaultdict").

    If {createfn} is `nil` it defaults to defaulttable() itself, so accessing
    nested keys creates nested tables: >lua
        local a = vim.defaulttable()
        a.b.c = 1
<

    Parameters: ~
      • {createfn}  (`fun(key:any):any?`) Provides the value for a missing
                    `key`.

    Return: ~
        (`table`) Empty table with `__index` metamethod.

vim.endswith({s}, {suffix})                                   *vim.endswith()*
    Tests if `s` ends with `suffix`.

    Parameters: ~
      • {s}       (`string`) String
      • {suffix}  (`string`) Suffix to match

    Return: ~
        (`boolean`) `true` if `suffix` is a suffix of `s`

vim.gsplit({s}, {sep}, {opts})                                  *vim.gsplit()*
    Gets an |iterator| that splits a string at each instance of a separator,
    in "lazy" fashion (as opposed to |vim.split()| which is "eager").

    Example: >lua
        for s in vim.gsplit(':aa::b:', ':', {plain=true}) do
          print(s)
        end
<

    If you want to also inspect the separator itself (instead of discarding
    it), use |string.gmatch()|. Example: >lua
        for word, num in ('foo111bar222'):gmatch('([^0-9]*)(%d*)') do
          print(('word: %s num: %s'):format(word, num))
        end
<

    Parameters: ~
      • {s}     (`string`) String to split
      • {sep}   (`string`) Separator or pattern
      • {opts}  (`table?`) Keyword arguments |kwargs|:
                • {plain}? (`boolean`) Use `sep` literally (as in
                  string.find).
                • {trimempty}? (`boolean`) Discard empty segments at start and
                  end of the sequence.

    Return: ~
        (`fun():string?`) Iterator over the split components

    See also: ~
      • |string.gmatch()|
      • |vim.split()|
      • |lua-pattern|s
      • https://www.lua.org/pil/20.2.html
      • http://lua-users.org/wiki/StringLibraryTutorial

vim.is_callable({f})                                       *vim.is_callable()*
    Returns true if object `f` can be called as a function.

    Parameters: ~
      • {f}  (`any`) Any object

    Return: ~
        (`boolean`) `true` if `f` is callable, else `false`

vim.isarray({t})                                               *vim.isarray()*
    Tests if `t` is an "array": a table indexed only by integers (potentially
    non-contiguous).

    If the indexes start from 1 and are contiguous then the array is also a
    list. |vim.islist()|

    Empty table `{}` is an array, unless it was created by |vim.empty_dict()|
    or returned as a dict-like |API| or Vimscript result, for example from
    |rpcrequest()| or |vim.fn|.

    Parameters: ~
      • {t}  (`table?`)

    Return: ~
        (`boolean`) `true` if array-like table, else `false`.

    See also: ~
      • https://github.com/openresty/luajit2#tableisarray

vim.islist({t})                                                 *vim.islist()*
    Tests if `t` is a "list": a table indexed only by contiguous integers
    starting from 1 (what |lua-length| calls a "regular array").


Title: Lua API: vim.defaulttable(), vim.endswith(), vim.gsplit(), vim.is_callable(), vim.isarray(), vim.islist()
Summary
This section documents more functions within the Lua API for Neovim. It covers `vim.defaulttable()`, which creates a table with default values generated by a function; `vim.endswith()` which checks if a string ends with a given suffix; `vim.gsplit()`, which provides an iterator for splitting a string at each occurrence of a separator; `vim.is_callable()` to test if an object is callable as a function; `vim.isarray()` to check if a table is an array; and `vim.islist()` to test if a table is a list.