On 14 May 2012 22:05, Mike Pall <mike-1205@xxxxxxxxxx> wrote: > Daurnimator wrote: >> I disagree somewhat with this; >> IMO, pointer comparisons should be handled just like table comparisons: >> pointer equality being table equality; but when "raw equality" fails: >> should fall back to metamethods. >> lua doesn't have a rawequal function for this case.... > > Ok, so you maybe you get away without rawequal(), if you're lucky. > But then it gets inconsistent with pointer arithmetic and other > metamethods. Ok, so one would need to run __add for p1 + 1. But > that means you cannot _ever_ do plain pointer arithmetic on such a > pointer without rawadd(), rawsub() and so on. This quickly leads > to an inflation of raw fallback functions. > What if pointer types could have a default metatable? That is, if all pointer types came with a metatable where __add implemented point arithmetic; But a developer could set a new metatable; implementing their own (non pointer arithmetic) __add metamethod. We seem to do without a range of raw* functions in lua as it is (though I admit, I sometimes miss them) > This is a low-level API -- I don't want this to become as opaque > as C++. > > --Mike > It is low level, but needing to wrap pointers in a table or struct or some such to implement metamethods seems like a waste... D