<div dir="ltr">Hi! Thanks for the patch.<br><br>While reviewing it, I've noticed that the autocompletion doesn't work<br>for a net.box.future object. I guess it's a topic for another issue,<br>isn't it? Besides that, LGTM.<br><br>Best regards<br>Yaroslav Dynnikov</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 25 Aug 2021 at 16:35, Vladimir Davydov <<a href="mailto:vdavydov@tarantool.org">vdavydov@tarantool.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Aug 25, 2021 at 12:39:27AM +0200, Vladislav Shpilevoy wrote:<br>
> > diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c<br>
> > index 1783da607dcc..3ed464a93437 100644<br>
> > --- a/src/box/lua/net_box.c<br>
> > +++ b/src/box/lua/net_box.c<br>
> > @@ -1432,6 +1432,29 @@ luaT_netbox_request_gc(struct lua_State *L)<br>
> > return 0;<br>
> > }<br>
> > <br>
> > +static int<br>
> > +luaT_netbox_request_tostring(struct lua_State *L)<br>
> > +{<br>
> > + lua_pushstring(L, netbox_request_typename);<br>
> > + return 1;<br>
> > +}<br>
> > +<br>
> > +static int<br>
> > +luaT_netbox_request_serialize(struct lua_State *L)<br>
> > +{<br>
> > + struct netbox_request *request = luaT_check_netbox_request(L, 1);<br>
> > + /*<br>
> > + * If there are user-defined fields attached to the future object,<br>
> > + * return them, otherwise push the type name, like __tostring does.<br>
> > + */<br>
> > + if (request->index_ref != LUA_NOREF) {<br>
> > + lua_rawgeti(L, LUA_REGISTRYINDEX, request->index_ref);<br>
> > + } else {<br>
> > + lua_pushstring(L, netbox_request_typename);<br>
> > + }<br>
> > + return 1;<br>
> > +}<br>
> <br>
> 1. It does not look good that __serialize might return both a table<br>
> and a string depending on the object content. Perhaps it is worth to<br>
> return an empty table when it has no members. Otherwise, say, if I<br>
> store an optional value in the index and want to get it like this:<br>
> <br>
> serialized_req.member<br>
> <br>
> then I will get sometimes nil, sometimes an error would be thrown.<br>
> <br>
<br>
Agree. Fixed the patch to return an empty table in case there's no user<br>
data stored in the future object.<br>
<br>
> > +<br>
> > static int<br>
> > luaT_netbox_request_index(struct lua_State *L)<br>
> > {<br>
> > @@ -2107,6 +2130,8 @@ luaopen_net_box(struct lua_State *L)<br>
> > <br>
> > static const struct luaL_Reg netbox_request_meta[] = {<br>
> > { "__gc", luaT_netbox_request_gc },<br>
> > + {"__tostring", luaT_netbox_request_tostring },<br>
> > + {"__serialize", luaT_netbox_request_serialize },<br>
> <br>
> 2. You have a whitespace after { in all the other lines. Could you<br>
> please add them here too?<br>
<br>
Sorry about that. Fixed.<br>
<br>
Incremental diff:<br>
--<br>
diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c<br>
index 3ed464a93437..7a72cb324df7 100644<br>
--- a/src/box/lua/net_box.c<br>
+++ b/src/box/lua/net_box.c<br>
@@ -1443,14 +1443,10 @@ static int<br>
luaT_netbox_request_serialize(struct lua_State *L)<br>
{<br>
struct netbox_request *request = luaT_check_netbox_request(L, 1);<br>
- /*<br>
- * If there are user-defined fields attached to the future object,<br>
- * return them, otherwise push the type name, like __tostring does.<br>
- */<br>
if (request->index_ref != LUA_NOREF) {<br>
lua_rawgeti(L, LUA_REGISTRYINDEX, request->index_ref);<br>
} else {<br>
- lua_pushstring(L, netbox_request_typename);<br>
+ lua_newtable(L);<br>
}<br>
return 1;<br>
}<br>
@@ -2130,8 +2126,8 @@ luaopen_net_box(struct lua_State *L)<br>
<br>
static const struct luaL_Reg netbox_request_meta[] = {<br>
{ "__gc", luaT_netbox_request_gc },<br>
- {"__tostring", luaT_netbox_request_tostring },<br>
- {"__serialize", luaT_netbox_request_serialize },<br>
+ { "__tostring", luaT_netbox_request_tostring },<br>
+ { "__serialize", luaT_netbox_request_serialize },<br>
{ "__index", luaT_netbox_request_index },<br>
{ "__newindex", luaT_netbox_request_newindex },<br>
{ "is_ready", luaT_netbox_request_is_ready },<br>
diff --git a/test/box/net.box_fiber-async_gh-3107.result b/test/box/net.box_fiber-async_gh-3107.result<br>
index 450934cd6593..98c9af953efa 100644<br>
--- a/test/box/net.box_fiber-async_gh-3107.result<br>
+++ b/test/box/net.box_fiber-async_gh-3107.result<br>
@@ -263,7 +263,7 @@ tostring(future)<br>
...<br>
future<br>
---<br>
-- net.box.request<br>
+- []<br>
...<br>
future.abc = 123<br>
---<br>
</blockquote></div>