From 1e00c1e9ecd9a0636dff5e8010eb9bfc99a6eeb3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20=C5=A0pa=C4=8Dek?= <petr.spacek@nic.cz>
Date: Mon, 20 Jul 2020 11:08:00 +0200
Subject: [PATCH] table_print: print multiple values

This change allows sandbox to pretty-print return values from functions
which return multiple values, e.g. future net.bufsize() from MR !1026.
---
 daemon/lua/sandbox.lua.in | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/daemon/lua/sandbox.lua.in b/daemon/lua/sandbox.lua.in
index c34d5b957..4df66273d 100644
--- a/daemon/lua/sandbox.lua.in
+++ b/daemon/lua/sandbox.lua.in
@@ -469,7 +469,24 @@ function eval_cmd(line, raw)
 end
 
 -- Pretty printing
-table_print = require('krprint').pprint
+local pprint = require('krprint').pprint
+function table_print(...)
+	local strs = {}
+	local nargs = select('#', ...)
+	if nargs == 0 then
+		return nil
+	end
+	for n=1,nargs do
+		local arg = select(n, ...)
+		local arg_str = pprint(arg)
+		if nargs > 1 then
+			table.insert(strs, string.format("%s\t-- result # %d", arg_str, n))
+		else
+			table.insert(strs, arg_str)
+		end
+	end
+	return table.concat(strs, '\n')
+end
 
 -- This extends the worker module to allow asynchronous execution of functions and nonblocking I/O.
 -- The current implementation combines cqueues for Lua interface, and event.socket() in order to not
-- 
GitLab