[PATCH v4 4/6] box: export registered functions in box.func folder
Vladimir Davydov
vdavydov.dev at gmail.com
Mon Jun 24 13:25:31 MSK 2019
On Sun, Jun 23, 2019 at 04:57:55PM +0300, Kirill Shcherbatov wrote:
> diff --git a/src/box/lua/call.c b/src/box/lua/call.c
> index 8b7223a7c..8c70c1088 100644
> --- a/src/box/lua/call.c
> +++ b/src/box/lua/call.c
> @@ -284,8 +287,13 @@ port_lua_create(struct port *port, struct lua_State *L)
> }
>
> struct execute_lua_ctx {
> - const char *name;
> - uint32_t name_len;
> + union {
> + struct {
> + const char *name;
> + uint32_t name_len;
> + };
> + struct mpstream *stream;
> + };
> struct port *args;
> };
>
> @@ -340,58 +348,56 @@ execute_lua_eval(lua_State *L)
> static int
> encode_lua_call(lua_State *L)
> {
> - struct port_lua *port = (struct port_lua *) lua_topointer(L, -1);
> + struct execute_lua_ctx *ctx =
> + (struct execute_lua_ctx *) lua_topointer(L, 1);
Using the same struct for executing a function and encoding its result
looks ugly. I introduced a separate struct for this - see my changes
below - and pushed the patch to master.
diff --git a/src/box/lua/call.c b/src/box/lua/call.c
index 8c70c108..b308924c 100644
--- a/src/box/lua/call.c
+++ b/src/box/lua/call.c
@@ -287,13 +287,8 @@ port_lua_create(struct port *port, struct lua_State *L)
}
struct execute_lua_ctx {
- union {
- struct {
- const char *name;
- uint32_t name_len;
- };
- struct mpstream *stream;
- };
+ const char *name;
+ uint32_t name_len;
struct port *args;
};
@@ -345,22 +340,26 @@ execute_lua_eval(lua_State *L)
return lua_gettop(L);
}
+struct encode_lua_ctx {
+ struct port_lua *port;
+ struct mpstream *stream;
+};
+
static int
encode_lua_call(lua_State *L)
{
- struct execute_lua_ctx *ctx =
- (struct execute_lua_ctx *) lua_topointer(L, 1);
+ struct encode_lua_ctx *ctx =
+ (struct encode_lua_ctx *) lua_topointer(L, 1);
/*
* Add all elements from Lua stack to the buffer.
*
* TODO: forbid explicit yield from __serialize or __index here
*/
struct luaL_serializer *cfg = luaL_msgpack_default;
- struct port_lua *port = (struct port_lua *) ctx->args;
- int size = lua_gettop(port->L);
+ int size = lua_gettop(ctx->port->L);
for (int i = 1; i <= size; ++i)
- luamp_encode(port->L, cfg, ctx->stream, i);
- port->size = size;
+ luamp_encode(ctx->port->L, cfg, ctx->stream, i);
+ ctx->port->size = size;
mpstream_flush(ctx->stream);
return 0;
}
@@ -368,16 +367,15 @@ encode_lua_call(lua_State *L)
static int
encode_lua_call_16(lua_State *L)
{
- struct execute_lua_ctx *ctx =
- (struct execute_lua_ctx *) lua_topointer(L, 1);
+ struct encode_lua_ctx *ctx =
+ (struct encode_lua_ctx *) lua_topointer(L, 1);
/*
* Add all elements from Lua stack to the buffer.
*
* TODO: forbid explicit yield from __serialize or __index here
*/
struct luaL_serializer *cfg = luaL_msgpack_default;
- struct port_lua *port = (struct port_lua *) ctx->args;
- port->size = luamp_encode_call_16(port->L, cfg, ctx->stream);
+ ctx->port->size = luamp_encode_call_16(ctx->port->L, cfg, ctx->stream);
mpstream_flush(ctx->stream);
return 0;
}
@@ -392,8 +390,8 @@ port_lua_do_dump(struct port *base, struct mpstream *stream,
* Use the same global state, assuming the encoder doesn't
* yield.
*/
- struct execute_lua_ctx ctx;
- ctx.args = base;
+ struct encode_lua_ctx ctx;
+ ctx.port = port;
ctx.stream = stream;
struct lua_State *L = tarantool_L;
int top = lua_gettop(L);
More information about the Tarantool-patches
mailing list