Table concatenation
Very Vanilla
Being able to do ["foo", "boo"] + "moo", is a powerful bit of LSL, and Lua can't do that by default. As someone who's never touched Lua before tonight, it was delightfully easy to add that behavior back in, and might be something very useful for others.
local mt = {
__tostring = function(a)
return ll.DumpList2String(a, " ")
end,
__add = function(a, b)
if type(b) == "table" then
for _, v in ipairs(b) do a[#a+1]=v end
else
a[#a+1]=b
end
return a
end
}
function ct(tbl)
return setmetatable(tbl or {}, mt)
end
-- Usage:
ll.OwnerSay("=================")
local t = ct() + {1, 2} + {3, 4} + "hi"
ll.OwnerSay(`{tostring(t)}`)
Log In
Thunder Rahja
The concatenation operator in Lua is two periods
..
However, when joining multiple strings and values,
table.concat
is the preferred method for constructing longer strings because it runs faster due to strings being immutable. I don't know if strings are still immutable in Luau or SL's implementation of it.