lua-users home
lua-l archive

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


On 18.10.2011 05:53, Tang Daogang wrote:
On Tue, Oct 18, 2011 at 11:04 AM, Norbert Kiesel<nkiesel@tbdnetworks.com>wrote:

;) I am sorry, Bamboo relies on lglib (https://github.com/daogangtang/lglib),
in which I override the __add method with ..


Not a good idea if your strings look like numbers:

$ cat > adds.lua
local mt = getmetatable( "" )
mt.__add = function( a, b )
  return a .. b
end
print( "1" + "2" )
^D

$ lua adds.lua
3

Lua tries to convert arguments of '+' to numbers and apply numeric addition *before* metamethods are involved.

Philipp