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 19FDF2D850 for ; Wed, 15 May 2019 15:36:55 -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 QkzVQMLqTXKI for ; Wed, 15 May 2019 15:36:55 -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 C4B232EC26 for ; Wed, 15 May 2019 15:36:54 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 08/10] swim: allow to use cdata struct tt_uuid in Lua API Date: Wed, 15 May 2019 22:36:45 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: kostja@tarantool.org Sometimes, especially in tests, it is useful to make something like this: s:add_member({uuid = member:uuid(), uri = member:uri()}) But member:uuid() is cdata struct tt_uuid. This commit allows that. Part of #3234 --- src/lua/swim.lua | 5 ++++- test/swim/swim.result | 17 ++++++++++++++--- test/swim/swim.test.lua | 3 +++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/lua/swim.lua b/src/lua/swim.lua index 6e55ffeba..80c7375ab 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -194,7 +194,10 @@ local function swim_check_uuid(value, func_name) return nil end if type(value) ~= 'string' then - return error(func_name..': expected string UUID') + if ffi.istype('struct tt_uuid', value) then + return value + end + return error(func_name..': expected string UUID or struct tt_uuid') end value = uuid.fromstr(value) if not value then diff --git a/test/swim/swim.result b/test/swim/swim.result index d0838af48..91a8ab6e9 100644 --- a/test/swim/swim.result +++ b/test/swim/swim.result @@ -45,7 +45,7 @@ swim.new({gc_mode = 0}) ... swim.new({uuid = 123}) --- -- error: 'builtin/swim.lua:: swim:cfg: expected string UUID' +- error: 'builtin/swim.lua:: swim:cfg: expected string UUID or struct tt_uuid' ... swim.new({uuid = '1234'}) --- @@ -253,7 +253,8 @@ s1.remove_member() ... s1:remove_member(100) --- -- error: 'builtin/swim.lua:: swim:remove_member: expected string UUID' +- error: 'builtin/swim.lua:: swim:remove_member: expected string UUID or struct + tt_uuid' ... s1:remove_member('1234') --- @@ -484,12 +485,22 @@ s1:member_by_uuid(uuid(1)) ~= nil ... s1:member_by_uuid(50) --- -- error: 'builtin/swim.lua:: swim:member_by_uuid: expected string UUID' +- error: 'builtin/swim.lua:: swim:member_by_uuid: expected string UUID or struct + tt_uuid' ... s1:member_by_uuid(uuid(2)) --- - null ... +-- UUID can be cdata. +s1:member_by_uuid(s:uuid()) +--- +- uri: 127.0.0.1: + status: alive + incarnation: 1 + uuid: 00000000-0000-1000-8000-000000000001 + payload_size: 0 +... s1:quit() --- ... diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua index 9f237a540..a744b2a29 100644 --- a/test/swim/swim.test.lua +++ b/test/swim/swim.test.lua @@ -159,6 +159,9 @@ s1:member_by_uuid(uuid(1)) ~= nil s1:member_by_uuid(50) s1:member_by_uuid(uuid(2)) +-- UUID can be cdata. +s1:member_by_uuid(s:uuid()) + s1:quit() s:status() s:is_dropped() -- 2.20.1 (Apple Git-117)