Tarantool development patches archive
 help / color / mirror / Atom feed
From: Chris Sosnin <k.sosnin@tarantool.org>
To: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org
Subject: [Tarantool-patches] [PATCH] lua: expose checktuple function
Date: Wed, 26 Feb 2020 19:13:21 +0300	[thread overview]
Message-ID: <20200226161321.73229-1-k.sosnin@tarantool.org> (raw)

All lua types feature check, push and is functions. We expose lua_checktuple
for full consistency.

Closes #2553
---
branch: https://github.com/tarantool/tarantool/tree/ksosnin/gh-2553-expose-luaT_checktuple
issue: https://github.com/tarantool/tarantool/issues/2553

 extra/exports       |  1 +
 src/box/lua/tuple.c | 18 +++++++++---------
 src/box/lua/tuple.h | 14 +++++++++++++-
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/extra/exports b/extra/exports
index 7b84a1452..3a0637317 100644
--- a/extra/exports
+++ b/extra/exports
@@ -162,6 +162,7 @@ luaL_checkuint64
 luaL_checkint64
 luaL_touint64
 luaL_toint64
+luaT_checktuple
 luaT_pushtuple
 luaT_istuple
 luaT_error
diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
index 1cbdacd0b..1e3c3d65c 100644
--- a/src/box/lua/tuple.c
+++ b/src/box/lua/tuple.c
@@ -69,13 +69,13 @@ extern char tuple_lua[]; /* Lua source */
 
 uint32_t CTID_STRUCT_TUPLE_REF;
 
-static inline box_tuple_t *
-lua_checktuple(struct lua_State *L, int narg)
+box_tuple_t *
+luaT_checktuple(struct lua_State *L, int idx)
 {
-	struct tuple *tuple = luaT_istuple(L, narg);
+	struct tuple *tuple = luaT_istuple(L, idx);
 	if (tuple == NULL)  {
 		luaL_error(L, "Invalid argument #%d (box.tuple expected, got %s)",
-		   narg, lua_typename(L, lua_type(L, narg)));
+		   idx, lua_typename(L, lua_type(L, idx)));
 	}
 
 	return tuple;
@@ -162,7 +162,7 @@ lbox_tuple_new(lua_State *L)
 static int
 lbox_tuple_gc(struct lua_State *L)
 {
-	struct tuple *tuple = lua_checktuple(L, 1);
+	struct tuple *tuple = luaT_checktuple(L, 1);
 	box_tuple_unref(tuple);
 	return 0;
 }
@@ -191,7 +191,7 @@ lbox_tuple_slice_wrapper(struct lua_State *L)
 static int
 lbox_tuple_slice(struct lua_State *L)
 {
-	struct tuple *tuple = lua_checktuple(L, 1);
+	struct tuple *tuple = luaT_checktuple(L, 1);
 	int argc = lua_gettop(L) - 1;
 	uint32_t start, end;
 	int32_t offset;
@@ -325,7 +325,7 @@ lbox_tuple_to_map(struct lua_State *L)
 		names_only = lua_toboolean(L, -1);
 	}
 
-	struct tuple *tuple = lua_checktuple(L, 1);
+	struct tuple *tuple = luaT_checktuple(L, 1);
 	struct tuple_format *format = tuple_format(tuple);
 	const char *pos = tuple_data(tuple);
 	int field_count = (int)mp_decode_array(&pos);
@@ -375,7 +375,7 @@ error:
 static int
 lbox_tuple_transform(struct lua_State *L)
 {
-	struct tuple *tuple = lua_checktuple(L, 1);
+	struct tuple *tuple = luaT_checktuple(L, 1);
 	int argc = lua_gettop(L);
 	if (argc < 3)
 		luaL_error(L, "tuple.transform(): bad arguments");
@@ -506,7 +506,7 @@ lbox_tuple_field_by_path(struct lua_State *L)
 static int
 lbox_tuple_to_string(struct lua_State *L)
 {
-	struct tuple *tuple = lua_checktuple(L, 1);
+	struct tuple *tuple = luaT_checktuple(L, 1);
 	size_t used = region_used(&fiber()->gc);
 	char *res = tuple_to_yaml(tuple);
 	if (res == NULL) {
diff --git a/src/box/lua/tuple.h b/src/box/lua/tuple.h
index dd3aa0f08..fd280f565 100644
--- a/src/box/lua/tuple.h
+++ b/src/box/lua/tuple.h
@@ -47,6 +47,18 @@ typedef struct tuple_format box_tuple_format_t;
 
 /** \cond public */
 
+/**
+ * Checks whether the argument idx is a tuple and
+ * returns it.
+ *
+ * @param L Lua State
+ * @param idx the stack index
+ * @retval non-NULL argument is tuple
+ * @throws error if the argument is not a tuple.
+ */
+box_tuple_t *
+luaT_checktuple(struct lua_State *L, int idx);
+
 /**
  * Push a tuple onto the stack.
  * @param L Lua State
@@ -57,7 +69,7 @@ void
 luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple);
 
 /**
- * Checks whether argument idx is a tuple
+ * Checks whether argument idx is a tuple.
  *
  * @param L Lua State
  * @param idx the stack index
-- 
2.21.1 (Apple Git-122.3)

             reply	other threads:[~2020-02-26 16:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 16:13 Chris Sosnin [this message]
2020-02-29 16:01 ` Vladislav Shpilevoy
2020-03-05  8:05 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200226161321.73229-1-k.sosnin@tarantool.org \
    --to=k.sosnin@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] lua: expose checktuple function' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox