lua-users home
lua-l archive

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


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
       else
         -- call the metamethod
       end
     end

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

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 <telliamed@whoopdedo.org>