From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 5306624BEC for ; Wed, 16 May 2018 08:51:51 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SQkS_j2_oQuS for ; Wed, 16 May 2018 08:51:51 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 1136324BEB for ; Wed, 16 May 2018 08:51:49 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] box: ability to omit box.cfg() call in sql Date: Wed, 16 May 2018 15:51:43 +0300 Message-Id: <6056f62646b1aee1ce8c99b7d3fe5cc3d78a993d.1526475084.git.kshcherbatov@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov This makes possible to call box.sql.execute without pre-calling box.cfg. Introduced metatable __index function for box.sql that called when no appropriate box.sql methods (execute, debug) is defined. It calls box.cfg() itself that redefines box.sql table. Closes #3266 --- src/box/lua/load_cfg.lua | 15 +++++++++++++++ test/box/cfg.result | 17 +++++++++++++++++ test/box/cfg.test.lua | 10 ++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index 4ace1e1..781de3e 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -418,6 +418,21 @@ local function load_cfg(cfg) end box.cfg = load_cfg +-- +-- gh-3266: box.cfg{} still not optional on 2.0 brach +-- +-- This makes possible do box.sql.execute without calling box.cfg +-- manually. The load_cfg call would overwrite following table and +-- metatable. +-- +box.sql = {} +setmetatable(box.sql, { + __index = function(table, index) + load_cfg() + return box.sql[index] + end, +}) + -- gh-810: -- hack luajit default cpath -- commented out because we fixed luajit to build properly, see diff --git a/test/box/cfg.result b/test/box/cfg.result index 14dceac..42a0a89 100644 --- a/test/box/cfg.result +++ b/test/box/cfg.result @@ -434,6 +434,23 @@ box.cfg{net_msg_max = old + 1000} box.cfg{net_msg_max = old} --- ... +-- +-- gh-3266: box.cfg{} still not optional on 2.0 brach +-- +-- box.sql defined with __index function in metatable overriten with first +-- sql.cfg() call +-- +box.cfg() +--- +... +assert(next(box.sql) ~= box.NULL) +--- +- true +... +assert(getmetatable(box.sql) == box.NULL) +--- +- true +... test_run:cmd("clear filter") --- - true diff --git a/test/box/cfg.test.lua b/test/box/cfg.test.lua index 2d819c9..b1f4dc9 100644 --- a/test/box/cfg.test.lua +++ b/test/box/cfg.test.lua @@ -91,4 +91,14 @@ box.cfg{net_msg_max = 2} box.cfg{net_msg_max = old + 1000} box.cfg{net_msg_max = old} +-- +-- gh-3266: box.cfg{} still not optional on 2.0 brach +-- +-- box.sql defined with __index function in metatable overriten with first +-- sql.cfg() call +-- +box.cfg() +assert(next(box.sql) ~= box.NULL) +assert(getmetatable(box.sql) == box.NULL) + test_run:cmd("clear filter") -- 2.7.4