From 0fa415347f1e4a8b5a318269b683f562118a9883 Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja.osipov@gmail.com>
Date: Tue, 6 Sep 2011 18:51:45 +0400
Subject: [PATCH] Fix a bug introduced with a rename of namespace to space.

---
 core/tarantool_lua.m | 18 +++++++++---------
 test/box/lua.result  | 22 +++++++++++++---------
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/core/tarantool_lua.m b/core/tarantool_lua.m
index 11755b241d..87e6f34020 100644
--- a/core/tarantool_lua.m
+++ b/core/tarantool_lua.m
@@ -272,13 +272,13 @@ struct lua_State *
 tarantool_lua_init()
 {
 	lua_State *L = luaL_newstate();
-	if (L) {
-		luaL_openlibs(L);
-		luaL_register(L, "box", boxlib);
-		lua_register(L, "print", lbox_print);
-		L = mod_lua_init(L);
-	}
+	if (L == NULL)
+		return L;
+	luaL_openlibs(L);
+	luaL_register(L, "box", boxlib);
+	lua_register(L, "print", lbox_print);
 	tarantool_lua_load_cfg(L, &cfg);
+	L = mod_lua_init(L);
 	lua_settop(L, 0); /* clear possible left-overs of init */
 	return L;
 }
@@ -389,9 +389,9 @@ void tarantool_lua_load_cfg(struct lua_State *L, struct tarantool_cfg *cfg)
 					key, quote, value, quote);
 			luaL_addstring(&b, lua_tostring(L, -1));
 			lua_pop(L, 1);
-		} else if (strncmp(key, "space[", 10) == 0) {
-			lua_pushfstring(L, "box.space%s = %s%s%s\n",
-					key+9, quote, value, quote);
+		} else if (strncmp(key, "space", strlen("space")) == 0) {
+			lua_pushfstring(L, "box.%s = %s%s%s\n",
+					key, quote, value, quote);
 			luaL_addstring(&b, lua_tostring(L, -1));
 			lua_pop(L, 1);
 		}
diff --git a/test/box/lua.result b/test/box/lua.result
index 18f2bf49d6..a31fbe80e1 100644
--- a/test/box/lua.result
+++ b/test/box/lua.result
@@ -12,15 +12,15 @@ lua print('  lua says: hello')
 ...
 lua for n in pairs(box) do print('  - box.', n) end
 ---
-  - box.space
+  - box.update
   - box.process
-  - box.delete
   - box.cfg
-  - box.select
   - box.insert
-  - box.unpack
   - box.replace
-  - box.update
+  - box.select
+  - box.unpack
+  - box.delete
+  - box.space
   - box.pack
 ...
 lua box.pack()
@@ -338,7 +338,9 @@ lua for k,v in pairs(box.cfg) do print(' - ', k, ': ', v) end
 ...
 lua for k,v in pairs(box.space[0]) do if type(v) ~= 'table' then print(' - ', k, ': ', v) end end
 ---
-error: 'Lua error: [string "for k,v in pairs(box.space[0]) do if type(v) ..."]:1: bad argument #1 to ''pairs'' (table expected, got nil)'
+ - enabled: 1
+ - cardinality: -1
+ - estimated_rows: 0
 ...
 reload configuration
 ---
@@ -381,13 +383,15 @@ lua for k,v in pairs(box.cfg) do print(' - ', k, ': ', v) end
 ...
 lua for k,v in pairs(box.space[0]) do if type(v) ~= 'table' then print(' - ', k, ': ', v) end end
 ---
-error: 'Lua error: [string "for k,v in pairs(box.space[0]) do if type(v) ..."]:1: bad argument #1 to ''pairs'' (table expected, got nil)'
+ - enabled: 1
+ - cardinality: -1
+ - estimated_rows: 0
 ...
 lua box.cfg.nosuchoption = 1
 ---
-error: 'Lua error: [string "box.cfg = {}..."]:43: Attempt to modify a read-only table'
+error: 'Lua error: [string "box.cfg = {}..."]:50: Attempt to modify a read-only table'
 ...
 lua box.space[300] = 1
 ---
-error: 'Lua error: [string "box.cfg = {}..."]:43: Attempt to modify a read-only table'
+error: 'Lua error: [string "box.cfg = {}..."]:50: Attempt to modify a read-only table'
 ...
-- 
GitLab