lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> example = {["foo"], ["bar"], ["baz"]}
> 
> as an abbreviation for
> 
> example = {["foo"] = true, ["bar"] = true, ["baz"] = true}

This hadn't come up until now, but a common idiom is to let Lua do the work:

function makeset(t)
	local s={}
	for i,v in ipairs(t) do
		s[v]=true
	end
	return s
end

example = makeset{"foo", "bar", "baz"}

--lhf