diff options
Diffstat (limited to 'runtime/doc/lua.txt')
-rw-r--r-- | runtime/doc/lua.txt | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 6cfec45523..efba10b86f 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -1880,25 +1880,22 @@ vim.deepcopy({orig}) *vim.deepcopy()* Return: ~ (table) Table of copied keys and (nested) values. -vim.defaulttable({create}) *vim.defaulttable()* - Creates a table whose members are automatically created when accessed, if - they don't already exist. +vim.defaulttable({createfn}) *vim.defaulttable()* + Creates a table whose missing keys are provided by {createfn} (like + Python's "defaultdict"). - They mimic defaultdict in python. - - If {create} is `nil`, this will create a defaulttable whose constructor - function is this function, effectively allowing to create nested tables on - the fly: >lua + 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: ~ - • {create} function?(key:any):any The function called to create a - missing value. + • {createfn} function?(key:any):any Provides the value for a missing + `key`. Return: ~ - (table) Empty table with metamethod + (table) Empty table with `__index` metamethod. vim.endswith({s}, {suffix}) *vim.endswith()* Tests if `s` ends with `suffix`. @@ -2061,13 +2058,13 @@ vim.Ringbuf:push({item}) *Ringbuf:push()* • {item} any vim.spairs({t}) *vim.spairs()* - Enumerate a table sorted by its keys. + Enumerates key-value pairs of a table, ordered by key. Parameters: ~ • {t} (table) Dict-like table Return: ~ - (function) iterator over sorted keys and their values + (function) |for-in| iterator over sorted keys and their values See also: ~ • Based on https://github.com/premake/premake-core/blob/master/src/base/table.lua @@ -2232,12 +2229,14 @@ vim.tbl_get({o}, {...}) *vim.tbl_get()* any Nested value indexed by key (if it exists), else nil vim.tbl_isarray({t}) *vim.tbl_isarray()* - Tests if a Lua table can be treated as an array (a table indexed by - integers). + 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.tbl_islist()| - Empty table `{}` is assumed to be 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|. + 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) @@ -2245,6 +2244,9 @@ vim.tbl_isarray({t}) *vim.tbl_isarray()* Return: ~ (boolean) `true` if array-like table, else `false`. + See also: ~ + • https://github.com/openresty/luajit2#tableisarray + vim.tbl_isempty({t}) *vim.tbl_isempty()* Checks if a table is empty. @@ -2258,12 +2260,12 @@ vim.tbl_isempty({t}) *vim.tbl_isempty()* • https://github.com/premake/premake-core/blob/master/src/base/table.lua vim.tbl_islist({t}) *vim.tbl_islist()* - Tests if a Lua table can be treated as a list (a table indexed by - consecutive integers starting from 1). + Tests if `t` is a "list": a table indexed only by contiguous integers starting from 1 (what |lua-length| calls a "regular + array"). - Empty table `{}` is assumed to be an list, 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|. + Empty table `{}` is a list, 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) @@ -2271,6 +2273,9 @@ vim.tbl_islist({t}) *vim.tbl_islist()* Return: ~ (boolean) `true` if list-like table, else `false`. + See also: ~ + • |vim.tbl_isarray()| + vim.tbl_keys({t}) *vim.tbl_keys()* Return a list of all keys used in a table. However, the order of the return table of keys is not guaranteed. |