A variety of small fixes
This commit is contained in:
@@ -253,7 +253,7 @@ void LuaStack::cleartable(LuaSlot tab) const {
|
|||||||
lua_pop(L_, 1); // Pop the old value.
|
lua_pop(L_, 1); // Pop the old value.
|
||||||
lua_pushvalue(L_, -1); // Clone the key
|
lua_pushvalue(L_, -1); // Clone the key
|
||||||
lua_pushnil(L_); // Push the new value.
|
lua_pushnil(L_); // Push the new value.
|
||||||
lua_settable(L_, tab.index());
|
lua_rawset(L_, tab.index());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,13 +119,7 @@ LuaDefine(table_empty, "c") {
|
|||||||
|
|
||||||
LuaDefine(table_count, "c") {
|
LuaDefine(table_count, "c") {
|
||||||
luaL_checktype(L, -1, LUA_TTABLE);
|
luaL_checktype(L, -1, LUA_TTABLE);
|
||||||
lua_pushnil(L);
|
int total = lua_nkeys(L, -1);
|
||||||
lua_Integer total = 0;
|
|
||||||
while (lua_next(L, -2) != 0) {
|
|
||||||
total += 1;
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_pushinteger(L, total);
|
lua_pushinteger(L, total);
|
||||||
return 1;
|
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) {
|
if (lua_gettop(L) < 2) {
|
||||||
luaL_error(L, "Not enough arguments to nextpair");
|
luaL_error(L, "Not enough arguments to nextpair");
|
||||||
}
|
}
|
||||||
@@ -386,32 +380,7 @@ LuaDefine(table_nextpair, "c") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////
|
LuaDefine(table_sortedpairs, "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") {
|
|
||||||
LuaArg tab;
|
LuaArg tab;
|
||||||
LuaRet closure, rtab, key;
|
LuaRet closure, rtab, key;
|
||||||
LuaStack LS(L, tab, 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");
|
luaL_error(L, "Cannot iterate over a table with unsortable keys");
|
||||||
}
|
}
|
||||||
lua_replace(L, rtab.index());
|
lua_replace(L, rtab.index());
|
||||||
LS.set(closure, table_nextpair);
|
LS.set(closure, table_nextsortedpair);
|
||||||
LS.set(key, LuaNil);
|
LS.set(key, LuaNil);
|
||||||
return LS.result();
|
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") {
|
LuaDefine(table_genlt, "f") {
|
||||||
LuaArg o1,o2;
|
LuaArg o1,o2;
|
||||||
LuaRet lt;
|
LuaRet lt;
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ local tostring = tostring
|
|||||||
inspect.KEY = {}
|
inspect.KEY = {}
|
||||||
inspect.METATABLE = {}
|
inspect.METATABLE = {}
|
||||||
|
|
||||||
local function rawpairs(t)
|
|
||||||
return table.unsafepairs(t)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
||||||
-- Otherwise, it returns a regular quoted string
|
-- Otherwise, it returns a regular quoted string
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
|
|
||||||
makeclass("unittests")
|
makeclass("unittests")
|
||||||
|
|
||||||
|
function cmt()
|
||||||
|
for i=1,100000 do
|
||||||
|
local t = {1,2,3,4,5,a=1,b=2,c=3,d=4,e=5}
|
||||||
|
table.clear(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function unittests.tables()
|
function unittests.tables()
|
||||||
-- check table.count
|
-- check table.count
|
||||||
assert(table.count({}) == 0)
|
assert(table.count({}) == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user