[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Concat and len metamethods are not for strings
- From: TNHarris <telliamed@...>
- Date: Tue, 5 Feb 2013 20:24:21 -0500
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>