Skip to content[{MAP}])

Create a new domain map, optionally seeded with an initial set of key/value pairs.

A domain map is a dictionary type that allows resolving the value associated with a domain name key, supporting wildcard domain keys in the mapping.

For simple inputs, the mapping behaves as you might expect for a dictionary type:

local dmap =
dmap['foo'] = 'bar'
assert(dmap['foo'] == 'bar')
assert(dmap['not.set'] == nil)

you can define wildcard keys:

local dmap =

dmap['*'] = 'wildcard'

-- An exact lookup for won't match the wildcard
assert(dmap[''] == nil)

-- but any nodes "below" that will match the wildcard entry:
assert(dmap[''] == 'wildcard')

-- Any explicitly added entries will take precedence
-- over the wildcard:
dmap[''] = 'explicit'
assert(dmap[''] == 'explicit')

You may seed an initial value from a pre-existing lua table:

local dmap = {
  ['*'] = 123,
  [''] = 24,

-- and mutate the table after is has been constructed:
dmap['*'] = 42

assert(dmap[''] == 42)
assert(dmap[''] == 24)
assert(dmap[''] == nil)
assert(dmap[''] == 123)