From: Petr Špaček Date: Mon, 20 Jul 2020 09:08:00 +0000 (+0200) Subject: table_print: print multiple values X-Git-Tag: v5.2.0~4^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fcab119ea09775470de8d256f1acd1995efb2eb;p=thirdparty%2Fknot-resolver.git 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. --- diff --git a/daemon/lua/sandbox.lua.in b/daemon/lua/sandbox.lua.in index 87132bb3f..d9d1bc05b 100644 --- a/daemon/lua/sandbox.lua.in +++ b/daemon/lua/sandbox.lua.in @@ -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