kong.table

Uses: Kong Gateway

Utilities for Lua tables.

kong.table.new([narr[, nrec]])

Returns a table with a 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 all array and hash parts entries from a table.

Parameters

  • tab (table): The table to 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"}
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!
OSZAR »