lua-users home
lua-l archive

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

as far as i remember all strings share one metatable, so if you change it all strings behavious will change. so better don't touch strings metatable...

On Wed, Feb 6, 2013 at 3:24 AM, TNHarris <> wrote:
>From the manual:
     function concat_event (op1, op2)
       if (type(op1) == "string" or type(op1) == "number") and
          (type(op2) == "string" or type(op2) == "number") then
         return op1 .. op2  -- primitive string concatenation
         -- call the metamethod

     function len_event (op)
       if type(op) == "string" then
         return strlen(op)      -- primitive string length
         -- call the metamethod

So if I wanted to, say, return the character length of a UTF-8 string, I
couldn't use
     getmetatable("").__len = utf8length

What is the motivation for not allowing the __concat and __len metamethods to
be set on strings?

tom <>