[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 custom array demo
- From: Mark Hamburg <mark@...>
- Date: Sat, 9 Jan 2010 09:45:38 -0800
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