From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EBB4846970E for ; Thu, 19 Dec 2019 20:45:29 +0300 (MSK) Received: by mail-lj1-f196.google.com with SMTP id e28so7151830ljo.9 for ; Thu, 19 Dec 2019 09:45:29 -0800 (PST) From: Cyrill Gorcunov Date: Thu, 19 Dec 2019 20:45:25 +0300 Message-Id: <20191219174525.13826-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] box/console: Handle multireturn in lua mode List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Currently we handle only first member of multireturn statement. Fix it processing each element separately. n.b.: While at this file add vim settings. | tarantool> \set output lua | true; | tarantool> 1,2,3,4 | 1, 2, 3, 4; Fixes #4604 Reported-by: Alexander Turenko Signed-off-by: Cyrill Gorcunov --- issue: https://github.com/tarantool/tarantool/issues/4604 branch: gorcunov/gh-4604-multireturn src/box/lua/console.lua | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index d4d8ec984..e9a9e8261 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -1,4 +1,6 @@ -- console.lua -- internal file +-- +-- vim: ts=4 sw=4 et local serpent = require('serpent') local internal = require('console') @@ -75,28 +77,38 @@ local serpent_map_symbols = function(tag, head, body, tail, level) return tag..head..body..tail end -output_handlers["lua"] = function(status, opts, ...) - -- - -- If no data present at least EOS should be put, - -- otherwise wire readers won't be able to find - -- where the end of string is. - if not ... then - return output_eos["lua"] - end +-- +-- Format element into lua form +local function format_lua(opts, elem) for k,v in pairs(lua_map_direct_symbols) do - if k == ... then - return v .. output_eos["lua"] + if k == elem then + return v end end local serpent_opts = { custom = serpent_map_symbols, comment = false, - nocode = true, + nocode = true, } if opts == "block" then - return serpent.block(..., serpent_opts) .. output_eos["lua"] + return serpent.block(elem, serpent_opts) + end + return serpent.line(elem, serpent_opts) +end + +output_handlers["lua"] = function(status, opts, ...) + local collect = { } + -- + -- If no data present at least EOS should be put, + -- otherwise wire readers won't be able to find + -- where the end of string is. + if not ... then + return output_eos["lua"] + end + for i = 1,select('#', ...) do + collect[i] = format_lua(opts, select(i, ...)) end - return serpent.line(..., serpent_opts) .. output_eos["lua"] + return table.concat(collect, ', ') .. output_eos["lua"] end local function output_verify_opts(fmt, opts) -- 2.20.1