lua: Set and Sequence
This commit is contained in:
committed by
Patrick Niklaus
parent
24c2708d1e
commit
5d564ee510
@@ -0,0 +1,10 @@
|
||||
-- Sequence of items
|
||||
-- Ordered, but no have to loop through items to check for inclusion.
|
||||
-- Currently the same as a table.
|
||||
|
||||
|
||||
function Sequence(source)
|
||||
return source
|
||||
end
|
||||
|
||||
return Sequence
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Set of items
|
||||
-- Fast check for inclusion, but unordered.
|
||||
--
|
||||
-- Instead of having to do:
|
||||
-- whitelist = { 'apple'=true, 'cherries'=true, 'melons'=true }
|
||||
--
|
||||
-- you can do:
|
||||
-- whitelist = Set { 'apple', 'cherries', 'melons' }
|
||||
--
|
||||
-- and then use it as:
|
||||
-- print( whitelist['cherries'] ) => true
|
||||
|
||||
function Set(source)
|
||||
set = {}
|
||||
if source then
|
||||
for i,v in ipairs(source) do
|
||||
set[v] = true
|
||||
end
|
||||
end
|
||||
return set
|
||||
end
|
||||
|
||||
return Set
|
||||
Reference in New Issue
Block a user