[Tarantool-patches] [PATCH v2 2/3] box: introduce box_return_mp() public C function

Nikita Pettik korablev at tarantool.org
Mon Apr 27 18:14:08 MSK 2020


On 23 Apr 02:12, Vladislav Shpilevoy wrote:
> +
> +int
> +test_return_mp(box_function_ctx_t *ctx, const char *args, const char *args_end)
> +{
> +	(void) args;
> +	(void) args_end;
> +	char buf[512];
> +	char *pos = mp_encode_uint(buf, 1);
> +	int rc = box_return_mp(ctx, buf, pos);
> +	if (rc != 0)
> +		return rc;
> +
> +	pos = mp_encode_int(buf, -1);
> +	rc = box_return_mp(ctx, buf, pos);
> +	if (rc != 0)
> +		return rc;
> +
> +	pos = mp_encode_uint(buf, UINT64_MAX);
> +	rc = box_return_mp(ctx, buf, pos);
> +	if (rc != 0)
> +		return rc;
> +
> +	const char *str = "123456789101112131415";
> +	pos = mp_encode_str(buf, str, strlen(str));
> +	rc = box_return_mp(ctx, buf, pos);
> +	if (rc != 0)
> +		return rc;
> +
> +	pos = mp_encode_array(buf, 1);
> +	pos = mp_encode_uint(pos, 2);
> +	box_tuple_t *tuple = box_tuple_new(box_tuple_format_default(),
> +					   buf, pos);
> +	if (tuple == NULL)
> +		return -1;
> +	rc = box_return_tuple(ctx, tuple);

Probably I'm missing something (since I've never used C API) but
when I do:

res = net:connect(box.cfg.listen):call(name)
print(type(res[5]))

I get table. But shouldn't it be tuple (cdata), since it (last member)
is explicitly wrapped into tuple)? I guess it is due to certain
convention but failed to find it in docs. Could you please clarify?



More information about the Tarantool-patches mailing list