From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id A00D86EC55; Wed, 25 Aug 2021 01:39:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A00D86EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629844770; bh=4ud61pwtk2aWY7VMhu8VXtAryRdB3yUNYr45aGEa2Yc=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=NucK2m2pzN/g2HZSq44kNPGmMC8Bnt4060ObOItlkzxf28/yWzYHi3MEuuTgPTOWj NdMAb5AJ463sbjme2fsmuoFCjZZyzF/90gFrHd1Cn9gdBdEnFx22ZFRKkpKwNG0xPH 7xpJdvwiWn64I71Zj09Ru23QCKMpMFU2X0URxi7I= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id A56D16EC55 for ; Wed, 25 Aug 2021 01:39:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A56D16EC55 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mIf4q-0001Sc-69; Wed, 25 Aug 2021 01:39:28 +0300 To: Vladimir Davydov , yaroslav.dynnikov@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <20210817075856.xkelwdonp5kmdofs@esperanza> <38b7f8367e68ece293394d9cf88200e7929341de.1629186968.git.vdavydov@tarantool.org> Message-ID: <726cc8fe-c43b-26a3-b810-da7dc9c295fc@tarantool.org> Date: Wed, 25 Aug 2021 00:39:27 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <38b7f8367e68ece293394d9cf88200e7929341de.1629186968.git.vdavydov@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F6525B29142351271182A05F5380850404EB19A17A89D37BC050FAC77900BBE505AC8ABB77CBBDD7E4EAC8950049713CD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AD2F2D6F6013FF7FC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7832AD58179B12F4FEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2FAE37697121D25068C0D050AAA55B85FCC7F00164DA146DAFE8445B8C89999728AA50765F7900637DCE3DBD6F8E38AFD389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC817119E5299B287EEF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDCE939D40DBB93CA75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505367CEBE794E4F449FA4DA9F2B7888E54 X-C1DE0DAB: 0D63561A33F958A57101F7DD548B0AB8C19175CD0C3C8E3ADBB9763DCB412621D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753177526CD55AFC11410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34BD150993ED26DDF473055ACA7C80B5DBC801A83E2CE087CA887E517DE77C4D4A815BA4BB62B1A3EA1D7E09C32AA3244C160C88B69176E437B560D43424A33E295595C85A795C7BAEFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4xwK62Bfefttqqy4Cm7yVA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DEB7CA4FA0D8C652B0C53456399B7B6DC3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2] net.box: add __serialize and __tostring methods for future objects X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! See 2 comments below. > diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c > index 1783da607dcc..3ed464a93437 100644 > --- a/src/box/lua/net_box.c > +++ b/src/box/lua/net_box.c > @@ -1432,6 +1432,29 @@ luaT_netbox_request_gc(struct lua_State *L) > return 0; > } > > +static int > +luaT_netbox_request_tostring(struct lua_State *L) > +{ > + lua_pushstring(L, netbox_request_typename); > + return 1; > +} > + > +static int > +luaT_netbox_request_serialize(struct lua_State *L) > +{ > + struct netbox_request *request = luaT_check_netbox_request(L, 1); > + /* > + * If there are user-defined fields attached to the future object, > + * return them, otherwise push the type name, like __tostring does. > + */ > + if (request->index_ref != LUA_NOREF) { > + lua_rawgeti(L, LUA_REGISTRYINDEX, request->index_ref); > + } else { > + lua_pushstring(L, netbox_request_typename); > + } > + return 1; > +} 1. It does not look good that __serialize might return both a table and a string depending on the object content. Perhaps it is worth to return an empty table when it has no members. Otherwise, say, if I store an optional value in the index and want to get it like this: serialized_req.member then I will get sometimes nil, sometimes an error would be thrown. > + > static int > luaT_netbox_request_index(struct lua_State *L) > { > @@ -2107,6 +2130,8 @@ luaopen_net_box(struct lua_State *L) > > static const struct luaL_Reg netbox_request_meta[] = { > { "__gc", luaT_netbox_request_gc }, > + {"__tostring", luaT_netbox_request_tostring }, > + {"__serialize", luaT_netbox_request_serialize }, 2. You have a whitespace after { in all the other lines. Could you please add them here too? > { "__index", luaT_netbox_request_index }, > { "__newindex", luaT_netbox_request_newindex }, > { "is_ready", luaT_netbox_request_is_ready },