lua-users home
lua-l archive

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

On Mon, Nov 19, 2018 at 11:36 AM Felipe Tavares <> wrote:

I am writing an lightweight (and bare bones) implementation of the += operator.

I already got it working, many thanks to the power patch by Olsen (" title="" target="_blank">

+= etc. is not simple to implement if you want to keep the regular Lua semantics, for instance in this case:

t[f()] += 1

This has to be translated into: 

local tmp = f()
t[tmp] = t[tmp] + 1
tmp = nil

If 't' has a metatable it may trigger __index and __newindex metamethod calls, so you can't just obtain the location of t[tmp] and update it.

It may be exceedingly tricky to efficiently generate this kind of code in a single-pass top-down translator, but I have not studied that in detail so I don't know.