Merge pull request #11958 from batrick/cls-lua-lua_next

lua: use simpler lua_next traversal structure

Reviewed-by: John Spray <john.spray@redhat.com>
This commit is contained in:
John Spray 2016-11-15 21:52:36 +00:00 committed by GitHub
commit 212b9737b8
2 changed files with 2 additions and 7 deletions

View File

@ -509,8 +509,7 @@ static int clslua_map_set_vals(lua_State *L)
map<string, bufferlist> kvpairs;
lua_pushnil(L);
while (lua_next(L, 1) != 0) {
for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) {
/*
* In the case of a numeric key a copy is made on the stack because
* converting to a string would otherwise manipulate the original key and
@ -553,8 +552,6 @@ static int clslua_map_set_vals(lua_State *L)
}
kvpairs[key] = val;
lua_pop(L, 1);
}
int ret = cls_cxx_map_set_vals(hctx, &kvpairs);

View File

@ -143,15 +143,13 @@ int Mantle::balance(const string &script,
/* fill in return value */
mds_rank_t it = mds_rank_t(0);
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
if (!lua_isnumber(L, -1)) {
dout(0) << "WARNING: mantle script returned a malformed response" << dendl;
lua_close(L);
return -EINVAL;
}
my_targets[it] = (lua_tonumber(L, -1));
lua_pop(L, 1);
it++;
}