[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Overloading and extending operators
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Wed, 11 Apr 2007 11:34:32 -0400
Mike Pall wrote:
> local shl = infix(function(a, b) return a*(2^b) end)
> print(5 -shl- 4)
> --> 80
> Cute, huh? Advantage: no changes to the Lua core needed.
> Drawback: one table allocation per operation.
Very nice syntax. Coupled with a simple token filter that's a very clean
way to add any operator. Managing precedence may be a bit tricky though.