所以我创建了一个所有字符串都可以使用的函数,它被称为 append。
local strmt = getmetatable("")
function strmt.__index.append(self, str)
self = self..str
return self
end
然后像这样使用该函数:
self = self:append("stuff")
有没有办法创建一个函数来做到这一点:
local stuff = "hi "
stuff:append("bye")
print(stuff)
并生产
hi bye