From 0712210768921f06505711a2edc6da38ad61fc7a Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 18 Mar 2020 14:03:23 +1100 Subject: [PATCH] better shell printing support --- lib/shell.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/shell.lua b/lib/shell.lua index 9a69cfe..7f4033d 100644 --- a/lib/shell.lua +++ b/lib/shell.lua @@ -10,6 +10,14 @@ local function shindex(self,k) return _G[k] end +local function formatValue(v) + if type(v) == "table" then + local w, rs = pcall(serial.serialize,v) + if w then return rs end + end + return tostring(v) +end + function shell.interactive() local shenv = setmetatable({}, {__index=shindex}) local run = true @@ -26,16 +34,7 @@ function shell.interactive() local rt = {pcall(f)} local rs = table.remove(rt,1) for k,v in pairs(rt) do - if type(v) == "table" then - local w, s = pcall(serial.serialize,v) - if w then - print(s) - else - print(tostring(v)) - end - else - print(tostring(v)) - end + print(formatValue(v)) end end end