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 671BA2A6D7 for ; Tue, 2 Oct 2018 16:51:03 -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 iLXdtIiMHMUX for ; Tue, 2 Oct 2018 16:51:03 -0400 (EDT) Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 079852768D for ; Tue, 2 Oct 2018 16:51:02 -0400 (EDT) Received: by mail-lf1-f68.google.com with SMTP id g89-v6so2498383lfl.5 for ; Tue, 02 Oct 2018 13:51:02 -0700 (PDT) From: AlexeyIvushkin Subject: [tarantool-patches] [PATCH] box: add tuple:size function Date: Tue, 2 Oct 2018 23:50:33 +0300 Message-Id: <1538513455-11240-1-git-send-email-ivushkinalex@gmail.com> In-Reply-To: References: 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: Morgan-iv From: Morgan-iv When operating with tuples, we only have tuple:bsize function to get size of tuple. tuple:bsize returns only size of MessagePack part of struct tuple, without tuple_meta. New function tuple:size returns size of all tuple, with MessagePack and tuple_meta Closes #2256 --- https://github.com/tarantool/tarantool/issues/2256 https://github.com/tarantool/tarantool/tree/Morgan-iv/gh-2256 src/box/lua/tuple.c | 10 ++++++++++ src/box/lua/tuple.lua | 1 + test/box/tuple.result | 12 ++++++++++++ test/box/tuple.test.lua | 6 ++++++ 4 files changed, 29 insertions(+) diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c index 65660ce..1ae49d6 100644 --- a/src/box/lua/tuple.c +++ b/src/box/lua/tuple.c @@ -489,6 +489,15 @@ lbox_tuple_to_string(struct lua_State *L) return 1; } +static int +lbox_tuple_size(struct lua_State *L) +{ + struct tuple *tuple = lua_checktuple(L, 1); + size_t size = tuple_size(tuple); + lua_pushinteger(L, size); + return 1; +} + void luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple) { @@ -506,6 +515,7 @@ static const struct luaL_Reg lbox_tuple_meta[] = { {"__gc", lbox_tuple_gc}, {"tostring", lbox_tuple_to_string}, {"slice", lbox_tuple_slice}, + {"size", lbox_tuple_size}, {"transform", lbox_tuple_transform}, {"tuple_to_map", lbox_tuple_to_map}, {"tuple_field_by_path", lbox_tuple_field_by_path}, diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index 63ea73e..801ee3c 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -286,6 +286,7 @@ local methods = { ["update"] = tuple_update; ["upsert"] = tuple_upsert; ["bsize"] = tuple_bsize; + ["size"] = internal.tuple.size; ["tomap"] = internal.tuple.tuple_to_map; } diff --git a/test/box/tuple.result b/test/box/tuple.result index e035cb9..418f5f8 100644 --- a/test/box/tuple.result +++ b/test/box/tuple.result @@ -186,6 +186,18 @@ t:bsize() --- - 5 ... +-- tuple:size() +t = box.tuple.new('abc') +--- +... +t +--- +- ['abc'] +... +t:size() +--- +- 15 +... -- -- Test cases for #106 box.tuple.new fails on multiple items -- diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua index 9df978d..7f4e2b3 100644 --- a/test/box/tuple.test.lua +++ b/test/box/tuple.test.lua @@ -49,6 +49,12 @@ t = box.tuple.new('abc') t t:bsize() +-- tuple:size() + +t = box.tuple.new('abc') +t +t:size() + -- -- Test cases for #106 box.tuple.new fails on multiple items -- -- 2.7.4