lua-users home
lua-l archive

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


On 19 February 2014 16:56, Steven Mak <tcmak@yahoo.com> wrote:
> Hi all,
>
> Can I know why there is no such operators as ++ or += (or similarly others
> like string concatenation) in Lua? What are the better alternatives instead
> of writing it in full "x = x + 1" or "this_string = this_string .. "Another
> string ""?

One of the reasons is that each new operator would require a new
overload metamethod. In Python for example, you need
separate overloads for x = x + y and x += y (__add__ and __iadd__).
Python has 13 of these extra, largely redundant overload methods.
Each new operator also needs a new opcode and makes the
VM larger.

Using a string buffer or rope is often more appropriate if you find
yourself doing a lot of string concatenation.