Map works like a hashtable but preserving the key insertion order.
To install Map, run:
$ luarocks install map
local Map = require('Map') local bill = Map() bill.set('name', 'Bill Gates') bill.set('age', 65) bill.has('name') -- true bill.has('company') -- false bill.get('name') -- 'Bill Gates' bill.get('age') -- 65 bill.get('company') -- nil bill.each(function(key, value) print(key .. ' = ' .. value) end) -- name = Bill Gates -- age = 65
-
Map.
items:table
Table holds key-values pairs. -
Map.
keys:table
List of inserted keys. -
Map.
values:table
List of inserted values. -
Map.
size:number
Current Map length.
-
Map.
set(key:any, value:any):void
Sets a key to a value. -
Map.
get(key:any):any
Returns the value associated to the key. -
Map.
has(key:any):boolean
Returns the value associated to the key. -
Map.
delete(key:any):boolean
Removes item by key and returns true in case of success and false if the item doesn't exist in the Map. -
Map.
each(callback:function):void
Calls function once for each item present in the Map object preserving insertion order.