lua-users home
lua-l archive

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

On Fri, Mar 27, 2015 at 10:40 AM, Roberto Ierusalimschy
<> wrote:
>> Perfomance Question:
>> I'm not *that* concerned about concatenation performance, but I am
>> curious to know if the presence of a metatable slows Lua down for all
>> numbers, or not. I figured that someone here might know that off of
>> the top of their head and save me some bench marking time effort, in
>> the case that it does not.
> A metatable for numbers would not affect performance at all. But you do
> not need it; you can use the string metatable :-) A quick hack could
> be like this:
> getmetatable''.__concat = function (a,b)
>   return tostring(a) .. tostring(b)
> end
> -- Roberto

Yes, and this might be better than any other solution. For example, if
I wanted to use __tostring on a List, such like `"Error, your list
'List: 0001234' is bad"`, then this solution makes it work, even
though __concat is overridden for appending one list to another.

Thank you. I'm going to add this right now.