From a199940d576fec51ea5a804acaf15aa4f7583f73 Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja@tarantool.org>
Date: Fri, 8 Feb 2013 16:40:12 +0400
Subject: [PATCH] box.tuple.new(): review fixes.

---
 src/box/box_lua.m   | 35 ++++++++++++++++++++++-------------
 test/box/lua.result | 26 +++++++++++++-------------
 test/box/lua.test   | 12 ++++++------
 3 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/src/box/box_lua.m b/src/box/box_lua.m
index e6956e33b1..fabd761754 100644
--- a/src/box/box_lua.m
+++ b/src/box/box_lua.m
@@ -79,6 +79,9 @@ static const char *tuplelib_name = "box.tuple";
 static void
 lbox_pushtuple(struct lua_State *L, struct tuple *tuple);
 
+static struct tuple *
+lua_totuple(struct lua_State *L, int index);
+
 static inline struct tuple *
 lua_checktuple(struct lua_State *L, int narg)
 {
@@ -100,6 +103,17 @@ lua_istuple(struct lua_State *L, int narg)
 	return tuple;
 }
 
+static int
+lbox_tuple_new(lua_State *L)
+{
+	int argc = lua_gettop(L);
+	if (argc < 1)
+		luaL_error(L, "tuple.new(): bad arguments");
+	struct tuple *tuple = lua_totuple(L, 1);
+	lbox_pushtuple(L, tuple);
+	return 1;
+}
+
 static int
 lbox_tuple_gc(struct lua_State *L)
 {
@@ -495,7 +509,7 @@ lbox_tuple_pairs(struct lua_State *L)
 	return 3;
 }
 
-static const struct luaL_reg lbox_tuple_meta [] = {
+static const struct luaL_reg lbox_tuple_meta[] = {
 	{"__gc", lbox_tuple_gc},
 	{"__len", lbox_tuple_len},
 	{"__index", lbox_tuple_index},
@@ -510,6 +524,11 @@ static const struct luaL_reg lbox_tuple_meta [] = {
 	{NULL, NULL}
 };
 
+static const struct luaL_reg lbox_tuplelib[] = {
+	{"new", lbox_tuple_new},
+	{NULL, NULL}
+};
+
 /* }}} */
 
 /** {{{ box.index Lua library: access to spaces and indexes
@@ -1151,20 +1170,8 @@ static int lbox_process(lua_State *L)
 	return lua_gettop(L) - top;
 }
 
-static int
-lbox_totuple(lua_State *L)
-{
-	int argc = lua_gettop(L);
-	if (argc < 1)
-		luaL_error(L, "box.totuple(): bad arguments");
-	struct tuple *tuple = lua_totuple(L, 1);
-	lbox_pushtuple(L, tuple);
-	return 1;
-}
-
 static const struct luaL_reg boxlib[] = {
 	{"process", lbox_process},
-	{"totuple", lbox_totuple},
 	{NULL, NULL}
 };
 
@@ -1249,6 +1256,8 @@ mod_lua_init(struct lua_State *L)
 {
 	/* box, box.tuple */
 	tarantool_lua_register_type(L, tuplelib_name, lbox_tuple_meta);
+	luaL_register(L, tuplelib_name, lbox_tuplelib);
+	lua_pop(L, 1);
 	luaL_register(L, "box", boxlib);
 	lua_pop(L, 1);
 	/* box.index */
diff --git a/test/box/lua.result b/test/box/lua.result
index 8ae5254177..3b091689e6 100644
--- a/test/box/lua.result
+++ b/test/box/lua.result
@@ -13,9 +13,9 @@ lua print('  lua says: hello')
 lua for n in pairs(box) do print('  - box.', n) end
 ---
   - box.fiber
-  - box.totuple
+  - box.select_reverse_range
   - box.uuid
-  - box.ipc
+  - box.select_limit
   - box.delete
   - box.space
   - box.replace
@@ -29,15 +29,15 @@ lua for n in pairs(box) do print('  - box.', n) end
   - box.info
   - box.session
   - box.uuid_hex
-  - box.select_reverse_range
+  - box.select
   - box.dostring
   - box.process
-  - box.select
-  - box.select_limit
+  - box.ipc
+  - box.slab
   - box.stat
   - box.flags
   - box.unpack
-  - box.slab
+  - box.tuple
   - box.index
   - box.pack
 ...
@@ -1732,24 +1732,24 @@ lua tostring(tonumber64(tonumber64(3)))
 ---
  - 3ULL
 ...
-# box.totuple test
-lua box.totuple()
+# box.tuple.new test
+lua box.tuple.new()
 ---
-error: 'box.totuple(): bad arguments'
+error: 'tuple.new(): bad arguments'
 ...
-lua box.totuple(1)
+lua box.tuple.new(1)
 ---
  - 1: {}
 ...
-lua box.totuple('string')
+lua box.tuple.new('string')
 ---
  - 'string': {}
 ...
-lua box.totuple(tonumber64('18446744073709551615'))
+lua box.tuple.new(tonumber64('18446744073709551615'))
 ---
  - 18446744073709551615: {}
 ...
-lua box.totuple({tonumber64('18446744073709551615'), 'string', 1})
+lua box.tuple.new({tonumber64('18446744073709551615'), 'string', 1})
 ---
  - 18446744073709551615: {'string', 1}
 ...
diff --git a/test/box/lua.test b/test/box/lua.test
index e32c77e398..778f01daa7 100644
--- a/test/box/lua.test
+++ b/test/box/lua.test
@@ -578,9 +578,9 @@ print """# A test case for Bug#1061747 'tonumber64 is not transitive'"""
 exec admin "lua tonumber64(tonumber64(2))"
 exec admin "lua tostring(tonumber64(tonumber64(3)))"
 
-print """# box.totuple test"""
-exec admin "lua box.totuple()"
-exec admin "lua box.totuple(1)"
-exec admin "lua box.totuple('string')"
-exec admin "lua box.totuple(tonumber64('18446744073709551615'))"
-exec admin "lua box.totuple({tonumber64('18446744073709551615'), 'string', 1})"
+print """# box.tuple.new test"""
+exec admin "lua box.tuple.new()"
+exec admin "lua box.tuple.new(1)"
+exec admin "lua box.tuple.new('string')"
+exec admin "lua box.tuple.new(tonumber64('18446744073709551615'))"
+exec admin "lua box.tuple.new({tonumber64('18446744073709551615'), 'string', 1})"
-- 
GitLab