[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Shorthand for appending to a table (was Re: 5.2 feature list?)
- From: PA <petite.abeille@...>
- Date: Tue, 12 Sep 2006 20:13:38 +0200
On Sep 12, 2006, at 19:23, Jerome Vuarand wrote:
Perf is not very good, but syntax is short. Above all it does not
require any Lua syntax modification (only some semantics of your
tables).
Talking of which:
local aTable = setmetatable( {}, { __add = function( aTable, aValue )
aTable[ #aTable + 1 ] = aValue return aTable end } )
_ = aTable + "one"
_ = aTable + "two"
_ = aTable + "three"
for anIndex, aValue in ipairs( aTable ) do
print( anIndex, aValue )
end
> 1 one
> 2 two
> 3 three