Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] lua: expose checktuple function
@ 2020-02-26 16:13 Chris Sosnin
  2020-02-29 16:01 ` Vladislav Shpilevoy
  2020-03-05  8:05 ` Kirill Yukhin
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Sosnin @ 2020-02-26 16:13 UTC (permalink / raw)
  To: tarantool-patches, v.shpilevoy

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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Tarantool-patches] [PATCH] lua: expose checktuple function
  2020-02-26 16:13 [Tarantool-patches] [PATCH] lua: expose checktuple function Chris Sosnin
@ 2020-02-29 16:01 ` Vladislav Shpilevoy
  2020-03-05  8:05 ` Kirill Yukhin
  1 sibling, 0 replies; 3+ messages in thread
From: Vladislav Shpilevoy @ 2020-02-29 16:01 UTC (permalink / raw)
  To: Chris Sosnin, tarantool-patches, Kirill Yukhin

LGTM.

On 26/02/2020 17:13, Chris Sosnin wrote:
> 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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Tarantool-patches] [PATCH] lua: expose checktuple function
  2020-02-26 16:13 [Tarantool-patches] [PATCH] lua: expose checktuple function Chris Sosnin
  2020-02-29 16:01 ` Vladislav Shpilevoy
@ 2020-03-05  8:05 ` Kirill Yukhin
  1 sibling, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2020-03-05  8:05 UTC (permalink / raw)
  To: Chris Sosnin; +Cc: tarantool-patches, v.shpilevoy

Hello,

On 26 фев 19:13, Chris Sosnin wrote:
> 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

LGTM.

I've checked your patch into master.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-05  8:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 16:13 [Tarantool-patches] [PATCH] lua: expose checktuple function Chris Sosnin
2020-02-29 16:01 ` Vladislav Shpilevoy
2020-03-05  8:05 ` Kirill Yukhin

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