A variety of small fixes

This commit is contained in:
2021-07-09 13:52:03 -04:00
parent 496190d5cf
commit dba5bccfa0
4 changed files with 12 additions and 44 deletions

View File

@@ -119,13 +119,7 @@ LuaDefine(table_empty, "c") {
LuaDefine(table_count, "c") {
luaL_checktype(L, -1, LUA_TTABLE);
lua_pushnil(L);
lua_Integer total = 0;
while (lua_next(L, -2) != 0) {
total += 1;
lua_pop(L, 1);
}
lua_pop(L, 1);
int total = lua_nkeys(L, -1);
lua_pushinteger(L, total);
return 1;
}
@@ -367,7 +361,7 @@ int table_getpairs(lua_State *L, bool sort, bool *unsortable) {
//
/////////////////////////////////////////////////////////////
LuaDefine(table_nextpair, "c") {
LuaDefine(table_nextsortedpair, "c") {
if (lua_gettop(L) < 2) {
luaL_error(L, "Not enough arguments to nextpair");
}
@@ -386,32 +380,7 @@ LuaDefine(table_nextpair, "c") {
}
}
/////////////////////////////////////////////////////////////
//
// Replace the lua 'pairs' and 'next' iterators.
//
/////////////////////////////////////////////////////////////
LuaDefine(table_unsafenext, "c") {
luaL_checktype(L, 1, LUA_TTABLE);
lua_settop(L, 2); /* create a 2nd argument if there isn't one */
if (lua_next(L, 1))
return 2;
else {
lua_pushnil(L);
return 1;
}
}
LuaDefine(table_unsafepairs, "c") {
luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */
lua_pushcfunction(L, table_unsafenext); /* will return generator, */
lua_pushvalue(L, 1); /* state, */
lua_pushnil(L);
return 3;
}
LuaDefine(table_pairs, "f") {
LuaDefine(table_sortedpairs, "c") {
LuaArg tab;
LuaRet closure, rtab, key;
LuaStack LS(L, tab, closure, rtab, key);
@@ -422,16 +391,11 @@ LuaDefine(table_pairs, "f") {
luaL_error(L, "Cannot iterate over a table with unsortable keys");
}
lua_replace(L, rtab.index());
LS.set(closure, table_nextpair);
LS.set(closure, table_nextsortedpair);
LS.set(key, LuaNil);
return LS.result();
}
LuaDefine(table_next, "f") {
luaL_error(L, "The 'next' iterator is not allowed in this version of lua");
return 0;
}
LuaDefine(table_genlt, "f") {
LuaArg o1,o2;
LuaRet lt;