2,875
edits
(Created page with "local StringBuilder = {} StringBuilder.__index = StringBuilder -- Constructor function StringBuilder.new() local self = setmetatable({}, StringBuilder) self.buffer = {} return self end -- Append method function StringBuilder:append(value) if value then table.insert(self.buffer, tostring(value)) end return self end function StringBuilder:appendLine(value) if value then table.insert(self.buffer, tostring(value)) end table.insert(self.buffer,...") |
m (Add tostring metafunction) |
||
Line 35: | Line 35: | ||
function StringBuilder:toString(separatorChar) | function StringBuilder:toString(separatorChar) | ||
return table.concat(self.buffer, separatorChar or '') | return table.concat(self.buffer, separatorChar or '') | ||
end | |||
function StringBuilder:__tostring() | |||
return self:toString() | |||
end | end | ||
return StringBuilder | return StringBuilder |
edits