robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
506 B27 linesraw
1-- Basic shim for LuaJIT's table.new and table.clear.
2local has_new, new = pcall(require, 'table.new')
3local has_clear, clear = pcall(require, 'table.clear')
4
5local M = {}
6
7if not has_new then
8  new = function(_narr, _nrec)
9    return {}
10  end
11end
12
13if not has_clear then
14  --- @param tab table
15  clear = function(tab)
16    for k in pairs(tab) do
17      tab[k] = nil
18    end
19  end
20end
21
22---@cast new fun(narr: integer, nrec: integer): table
23---@cast clear fun(tab: table)
24M.new = new
25M.clear = clear
26
27return M