From da0bff5a9f20856210d4c5e8dffa7df82f78de8b Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 22 Sep 2016 05:36:00 +0200 Subject: added Stream:tonumber() and Stream:tostring() and simplified the __tostring metamethod --- applause.lua | 13 ++++++------- 1 file 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 -- cgit v1.2.3