> -- even a function can be a key > t = {} > function t.add(i,j) >> return(i j) >> end > print(t.add(1,2)) 3 > print(t[ add ](1,2)) 3 > -- and another variation of a function as a key > t = {} > function v(x) >> print(x) >> end > t[v] = "The Big Store" > for key,value in t do key(value) end The Big Store
-- Overload the add operation -- to do string concatenation -- mt = {}
function String(string) return setmetatable({value = string or }, mt) end
-- The first operand is a String table -- The second operand is a string -- .. is the Lua concatenate operator -- function mt.__add(a, b) return String(a.value..b) end
s = String( Hello ) print((s There World! ).value )