Arithmetic on strings
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Arithmetic on strings
- From: Dirk Laurie <dirk.laurie@...>
- Date: 2012年6月13日 13:21:49 +0200
It seems to be impossible to override arithmetic operators on
strings. One can for example set the __add metamethod, but
it only gets called when at least one of the strings cannot be
coerced to a number. For example:
getmetatable''.__add = function(x,y) return x..y end
'a'+'b' --> 'ab', fine
'1'+'2' --> 3