lua-users home
lua-l archive

Re: Lua 5.2 custom array demo

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


On Jan 9, 2010, at 8:27 AM, David Manura wrote:
> The "end)" syntax was always a little odd, but there are ways it could
> be avoided:
> 
> local array = class ::
> function __len(t) return #t.store end
> function __newindex(t,i,val) rawset(t.store,i,val) end
> function __index(t,i) return rawget(t.store,i) end
> function __ipairs(t) return ipairs(t.store) end
> function __init() return setmetatable({store={}},array) end
> end
> 
> where "::" is basically like a "function()" but allows omitting
> parenthesis in the call.
My first reaction is that I really like that syntax. Of course, what it then wants is not "in t do end" but rather call_with_environment.
Mark

AltStyle によって変換されたページ (->オリジナル) /