summaryrefslogtreecommitdiff
path: root/meta/3rd/OpenResty/library/table
diff options
context:
space:
mode:
Diffstat (limited to 'meta/3rd/OpenResty/library/table')
-rw-r--r--meta/3rd/OpenResty/library/table/clone.lua25
-rw-r--r--meta/3rd/OpenResty/library/table/isarray.lua23
-rw-r--r--meta/3rd/OpenResty/library/table/isempty.lua22
-rw-r--r--meta/3rd/OpenResty/library/table/nkeys.lua23
4 files changed, 93 insertions, 0 deletions
diff --git a/meta/3rd/OpenResty/library/table/clone.lua b/meta/3rd/OpenResty/library/table/clone.lua
new file mode 100644
index 00000000..ff2ce870
--- /dev/null
+++ b/meta/3rd/OpenResty/library/table/clone.lua
@@ -0,0 +1,25 @@
+---@meta
+
+--- Returns a shallow copy of the given Lua table.
+---
+--- This API can be JIT compiled.
+---
+--- Usage:
+---
+--- ```lua
+--- local clone = require "table.clone"
+---
+--- local x = {x=12, y={5, 6, 7}}
+--- local y = clone(x)
+--- ```
+---
+--- **Note:** We observe 7% over-all speedup in the edgelang-fan compiler's
+--- compiling speed whose Lua is generated by the fanlang compiler.
+---
+--- **Note bis:** Deep cloning is planned to be supported by adding `true` as a second argument.
+---
+---@param t table
+---@return table
+local function clone(t) end
+
+return clone
diff --git a/meta/3rd/OpenResty/library/table/isarray.lua b/meta/3rd/OpenResty/library/table/isarray.lua
new file mode 100644
index 00000000..f2ee3c72
--- /dev/null
+++ b/meta/3rd/OpenResty/library/table/isarray.lua
@@ -0,0 +1,23 @@
+---@meta
+
+--- Returns `true` when the given Lua table is a pure array-like Lua table, or
+--- `false` otherwise.
+---
+--- Empty Lua tables are treated as arrays.
+---
+--- This API can be JIT compiled.
+---
+--- Usage:
+---
+--- ```lua
+--- local isarray = require "table.isarray"
+---
+--- print(isarray{"a", true, 3.14}) -- true
+--- print(isarray{dog = 3}) -- false
+--- print(isarray{}) -- true
+--- ```
+---@param t table
+---@return boolean
+local function isarray(t) end
+
+return isarray
diff --git a/meta/3rd/OpenResty/library/table/isempty.lua b/meta/3rd/OpenResty/library/table/isempty.lua
new file mode 100644
index 00000000..b1cef6fb
--- /dev/null
+++ b/meta/3rd/OpenResty/library/table/isempty.lua
@@ -0,0 +1,22 @@
+---@meta
+
+--- Returns `true` when the given Lua table contains neither non-nil array elements nor non-nil key-value pairs, or `false` otherwise.
+---
+--- This API can be JIT compiled.
+--- Usage:
+---
+--- ```lua
+--- local isempty = require "table.isempty"
+---
+--- print(isempty({})) -- true
+--- print(isempty({nil, dog = nil})) -- true
+--- print(isempty({"a", "b"})) -- false
+--- print(isempty({nil, 3})) -- false
+--- print(isempty({cat = 3})) -- false
+--- ```
+---
+---@param t table
+---@return boolean
+local function isempty(t) end
+
+return isempty
diff --git a/meta/3rd/OpenResty/library/table/nkeys.lua b/meta/3rd/OpenResty/library/table/nkeys.lua
new file mode 100644
index 00000000..41a42d6a
--- /dev/null
+++ b/meta/3rd/OpenResty/library/table/nkeys.lua
@@ -0,0 +1,23 @@
+---@meta
+
+--- Returns the total number of elements in a given Lua table (i.e. from both the
+--- array and hash parts combined).
+---
+--- This API can be JIT compiled.
+---
+--- Usage:
+---
+--- ```lua
+--- local nkeys = require "table.nkeys"
+---
+--- print(nkeys({})) -- 0
+--- print(nkeys({ "a", nil, "b" })) -- 2
+--- print(nkeys({ dog = 3, cat = 4, bird = nil })) -- 2
+--- print(nkeys({ "a", dog = 3, cat = 4 })) -- 3
+--- ```
+---
+---@param t table
+---@return integer
+local function nkeys(t) end
+
+return nkeys