]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
table_print: print multiple values
authorPetr Špaček <petr.spacek@nic.cz>
Mon, 20 Jul 2020 09:08:00 +0000 (11:08 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 2 Nov 2020 09:28:54 +0000 (10:28 +0100)
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

index 87132bb3ff5ccb76f687d82b8b73e114d9679210..d9d1bc05b1187fedb65f6b13c0bbb7ae6ee53a01 100644 (file)
@@ -476,7 +476,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