From: Cyrill Gorcunov <gorcunov@gmail.com> To: Konstantin Osipov <kostja@tarantool.org> Cc: tml <tarantool-patches@freelists.org>, Alexander Turenko <alexander.turenko@tarantool.org>, Kirill Yukhin <kyukhin@tarantool.org> Subject: [tarantool-patches] Re: [PATCH 4/5] box/console: Fix hang in remote console lua mode Date: Tue, 3 Sep 2019 22:18:13 +0300 [thread overview] Message-ID: <20190903191813.GL2801@uranus.lan> (raw) In-Reply-To: <20190903190002.GC15611@atlas> On Tue, Sep 03, 2019 at 10:00:02PM +0300, Konstantin Osipov wrote: > * Cyrill Gorcunov <gorcunov@gmail.com> [19/08/31 00:51]: > > The approach is fine, but I can not stop myself from nitpicking on > the implementation consistency. Somehow I find this code rather hard to > read, I tried to find out why, please see below. This is perfectly fine, I send the series to gather comments and fix the nits, so I really appreciate it! > > > > > +local function current_eos() > > No comment for the function. ok > > > + local d = current_output() > > + return output_eos[d["fmt"]] > > Why do you need a local variable? to make code shorter, the line return output_eos[current_output()["fmt"]] looks too heavy for me. But I must confess I always forget that we're in lua, where no optimization would happen (I think) and it will cause jit to allocate a variable first. On the other hand the lua handling here should not be a hot path and make code a bit slower for beauty/readability sake looks like acceptable trade off? > > +end > > Actually, the function is so simple, it is questionable why you > need it at all. Can't you keep the value pre-computed in the > object or in the metatable? Since eos may be changed on the fly I think we can't precompute it and keep somewhere. > > +-- Map output format into a "\set" command. > > +local function output_cmd_string() > > + local d = current_output() > > + if d["fmt"] == "yaml" then > > + return "\\set output yaml" > > + elseif d["fmt"] == "lua" then > > + local cmd = "\\set output lua" > > + if d["opts"] == "block" then > > + cmd = cmd .. ",block" > > + end > > + return cmd > > + end > > + return "" > > +end > > You could use string.format here: > string.format("\\set output %s", format) Will try to use, thanks! > > The code would win if you pass in 'd' as an argument, rather than > compute it locally, and give it a meaningful name. > > Ideally, why not store the whole thing in self and compute once. But the eos is per session value, can be changed dynamically. Or you mean pre-compute this command for each output once and just fetch it from the precomputed set? > > > + -- The command might modify EOS so > > + -- we have to parse and preprocess it > > + -- first to not stuck in :read() forever. > > + preprocess_eval = function(self, text) > > + local command = get_command(text) > > Why get_command() but not get_current_eos()? Because it generates \set output command, not eos as a symbol. Probably better name it gen_eos_command. > > > + if command == nil then > > + return > > + end > > + local nr_items, items = parse_operators(command) > > + if nr_items == 3 then > > + local err, fmt, opts = output_parse(items[3]) > > why parse_operators but output_parse? Because I try to use output_ as a prefix to "output" engine, ie everything related to output would have this prefix. Easier for grep. > > + if not err then > > + self.eos = output_eos[fmt] > > why self.eos but global output_eos? because this is not global output but the value bound to a particular session, you can have one server and several clients, where each client have own eos setting. Same applies to next your comment. So that why we need to carry it into object instance. > > > > + end > > + end > > + end, > > Why is this function part of the metatable? Can not it be a > standalone function, not exported in the metatable? > > > + local cmd_set_output = output_cmd_string() .. '\n' > > + local cmd_delimiter = 'require("console").delimiter("$EOF$")\n' > > + if not conn:write(cmd_set_output) or not conn:read() then > > + conn:set_error() > > + end > > + if not conn:write(cmd_delimiter) or not conn:read() then > > conn:set_error() > > Please add a comment for what's going on here. OK
next prev parent reply other threads:[~2019-09-04 14:53 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-30 21:48 [tarantool-patches] [PATCH v2 0/5] box/console: Improve lua mode for remote console Cyrill Gorcunov 2019-08-30 21:48 ` [tarantool-patches] [PATCH 1/5] box/console: Add mapping for direct symbols Cyrill Gorcunov [not found] ` <20190903082351.GB9438@atlas> 2019-09-03 8:26 ` [tarantool-patches] " Cyrill Gorcunov [not found] ` <20190903082446.GC9438@atlas> 2019-09-03 8:28 ` Cyrill Gorcunov 2019-08-30 21:48 ` [tarantool-patches] [PATCH 2/5] box/console: Add explicit output EOS mapping Cyrill Gorcunov [not found] ` <20190903082725.GD9438@atlas> 2019-09-03 8:32 ` [tarantool-patches] " Cyrill Gorcunov 2019-08-30 21:48 ` [tarantool-patches] [PATCH 3/5] box/console: Refactor command handling Cyrill Gorcunov 2019-08-30 21:48 ` [tarantool-patches] [PATCH 4/5] box/console: Fix hang in remote console lua mode Cyrill Gorcunov [not found] ` <20190903190002.GC15611@atlas> 2019-09-03 19:18 ` Cyrill Gorcunov [this message] [not found] ` <20190904064657.GD30636@atlas> 2019-09-04 7:12 ` [tarantool-patches] " Cyrill Gorcunov 2019-08-30 21:48 ` [tarantool-patches] [PATCH 5/5] box/console: Provide console.eos() api Cyrill Gorcunov [not found] ` <20190903190057.GD15611@atlas> 2019-09-03 19:19 ` [tarantool-patches] " Cyrill Gorcunov [not found] ` <20190904064725.GE30636@atlas> 2019-09-04 7:12 ` Cyrill Gorcunov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190903191813.GL2801@uranus.lan \ --to=gorcunov@gmail.com \ --cc=alexander.turenko@tarantool.org \ --cc=kostja@tarantool.org \ --cc=kyukhin@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH 4/5] box/console: Fix hang in remote console lua mode' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox