aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_core/table.lua
blob: f6ab94afd9bb8f808dbb99a54dd62c82453fb0a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- Basic shim for LuaJIT's table.new and table.clear.
local has_new, new = pcall(require, 'table.new')
local has_clear, clear = pcall(require, 'table.clear')

local M = {}

if not has_new then
  new = function(_narr, _nrec)
    return {}
  end
end

if not has_clear then
  --- @param tab table
  clear = function(tab)
    for k in pairs(tab) do
      tab[k] = nil
    end
  end
end

---@cast new fun(narr: integer, nrec: integer): table
---@cast clear fun(tab: table)
M.new = new
M.clear = clear

return M