Skip to content
Snippets Groups Projects
Commit 82cc5631 authored by Chris Sosnin's avatar Chris Sosnin Committed by Kirill Yukhin
Browse files

lua: expose checktuple function

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

Closes #2553
parent 12694d72
No related branches found
No related tags found
No related merge requests found
...@@ -162,6 +162,7 @@ luaL_checkuint64 ...@@ -162,6 +162,7 @@ luaL_checkuint64
luaL_checkint64 luaL_checkint64
luaL_touint64 luaL_touint64
luaL_toint64 luaL_toint64
luaT_checktuple
luaT_pushtuple luaT_pushtuple
luaT_istuple luaT_istuple
luaT_error luaT_error
......
...@@ -69,13 +69,13 @@ extern char tuple_lua[]; /* Lua source */ ...@@ -69,13 +69,13 @@ extern char tuple_lua[]; /* Lua source */
uint32_t CTID_STRUCT_TUPLE_REF; uint32_t CTID_STRUCT_TUPLE_REF;
static inline box_tuple_t * box_tuple_t *
lua_checktuple(struct lua_State *L, int narg) 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) { if (tuple == NULL) {
luaL_error(L, "Invalid argument #%d (box.tuple expected, got %s)", 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; return tuple;
...@@ -162,7 +162,7 @@ lbox_tuple_new(lua_State *L) ...@@ -162,7 +162,7 @@ lbox_tuple_new(lua_State *L)
static int static int
lbox_tuple_gc(struct lua_State *L) 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); box_tuple_unref(tuple);
return 0; return 0;
} }
...@@ -191,7 +191,7 @@ lbox_tuple_slice_wrapper(struct lua_State *L) ...@@ -191,7 +191,7 @@ lbox_tuple_slice_wrapper(struct lua_State *L)
static int static int
lbox_tuple_slice(struct lua_State *L) 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; int argc = lua_gettop(L) - 1;
uint32_t start, end; uint32_t start, end;
int32_t offset; int32_t offset;
...@@ -325,7 +325,7 @@ lbox_tuple_to_map(struct lua_State *L) ...@@ -325,7 +325,7 @@ lbox_tuple_to_map(struct lua_State *L)
names_only = lua_toboolean(L, -1); 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); struct tuple_format *format = tuple_format(tuple);
const char *pos = tuple_data(tuple); const char *pos = tuple_data(tuple);
int field_count = (int)mp_decode_array(&pos); int field_count = (int)mp_decode_array(&pos);
...@@ -375,7 +375,7 @@ lbox_tuple_to_map(struct lua_State *L) ...@@ -375,7 +375,7 @@ lbox_tuple_to_map(struct lua_State *L)
static int static int
lbox_tuple_transform(struct lua_State *L) 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); int argc = lua_gettop(L);
if (argc < 3) if (argc < 3)
luaL_error(L, "tuple.transform(): bad arguments"); luaL_error(L, "tuple.transform(): bad arguments");
...@@ -506,7 +506,7 @@ lbox_tuple_field_by_path(struct lua_State *L) ...@@ -506,7 +506,7 @@ lbox_tuple_field_by_path(struct lua_State *L)
static int static int
lbox_tuple_to_string(struct lua_State *L) 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); size_t used = region_used(&fiber()->gc);
char *res = tuple_to_yaml(tuple); char *res = tuple_to_yaml(tuple);
if (res == NULL) { if (res == NULL) {
......
...@@ -47,6 +47,18 @@ typedef struct tuple_format box_tuple_format_t; ...@@ -47,6 +47,18 @@ typedef struct tuple_format box_tuple_format_t;
/** \cond public */ /** \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. * Push a tuple onto the stack.
* @param L Lua State * @param L Lua State
...@@ -57,7 +69,7 @@ void ...@@ -57,7 +69,7 @@ void
luaT_pushtuple(struct lua_State *L, box_tuple_t *tuple); 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 L Lua State
* @param idx the stack index * @param idx the stack index
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment