diff --git a/core/tarantool_lua.m b/core/tarantool_lua.m index 11755b241d9f2f956df0c5940185adf6bbc8f33c..87e6f34020494f60ede77acfc68afbd7d9069005 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 18f2bf49d6f3d2f2482a19d7ef20231827ce8362..a31fbe80e104b378cfd8f632a0345b18019cfc45 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' ...