diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-09-22 05:36:00 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-09-25 03:52:16 +0200 |
commit | da0bff5a9f20856210d4c5e8dffa7df82f78de8b (patch) | |
tree | 634231b7b6fb68ef89fc2836ff543b43da23a8b5 | |
parent | 503acf7dfe5fa747dbbd2576d0b78b8c54ac9e4c (diff) | |
download | applause2-da0bff5a9f20856210d4c5e8dffa7df82f78de8b.tar.gz |
added Stream:tonumber() and Stream:tostring() and simplified the __tostring metamethod
-rw-r--r-- | applause.lua | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/applause.lua b/applause.lua index 1b143b8..25bb534 100644 --- a/applause.lua +++ b/applause.lua @@ -568,6 +568,9 @@ function Stream:save(filename, format) hnd:close() end +function Stream:tonumber() return self:map(tonumber) end +function Stream:tostring() return self:map(tostring) end + function Stream:totable() if self:len() == math.huge then error("Cannot serialize infinite stream") @@ -697,17 +700,13 @@ function Stream:__len() return self:len() end -- NOTE: Will only convert the first channel function Stream:__tostring() - local t + local stream = self:tostring() if self:len() > 1024 then - t = self:sub(1, 1024):totable() - table.insert(t, "...") - else - t = self:totable() + stream = stream:sub(1, 1024)..tostream{"..."} end - for i = 1, #t do t[i] = tostring(t[i]) end - + local t = stream:totable() return "{"..table.concat(t, ", ").."}" end |