You are browsing documentation for an older version. See the latest documentation here.
kong.table
kong.table
Utilities for Lua tables
kong.table.new([narr[, nrec]])
Returns a table with pre-allocated number of slots in its array and hash parts.
Parameters
- narr (number, optional): specifies the number of slots to pre-allocate in the array part.
- nrec (number, optional): specifies the number of slots to pre-allocate in the hash part.
Returns
-
table
the newly created table
Usage
local tab = kong.table.new(4, 4)
kong.table.clear(tab)
Clears a table from all of its array and hash parts entries.
Parameters
- tab (table): the table which will be cleared
Returns
- Nothing
Usage
local tab = {
"hello",
foo = "bar"
}
kong.table.clear(tab)
kong.log(tab[1]) -- nil
kong.log(tab.foo) -- nil
kong.table.merge([t1[, t2]])
Merges the contents of two tables together, producing a new one. The entries of both tables are copied non-recursively to the new one. If both tables have the same key, the second one takes precedence. If only one table is given, it returns a copy.
Parameters
- t1 (table, optional): The first table
- t2 (table, optional): The second table
Returns
-
table
The (new) merged table
Usage
local t1 = {1, 2, 3, foo = "f"}
local t2 = {4, 5, bar = "b"}
local t3 = kong.table.merge(t1, t2) -- {4, 5, 3, foo = "f", bar = "b"}