Add LuaDefineAlias
This commit is contained in:
@@ -60,7 +60,16 @@ LuaDefine(table_equal, "table1,table2",
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
static int check_isvector(lua_State *L) {
|
||||
LuaDefine(table_isvector, "table",
|
||||
"|Return true if the table is a valid vector."
|
||||
"|"
|
||||
"|A vector is a table that has keys starting with 1, and no gaps."
|
||||
"|The empty table also counts as a valid vector. This function"
|
||||
"|scans the entire vector to verify its validity, so it takes O(N)"
|
||||
"|time. See also table.isvectorq"
|
||||
"|"
|
||||
"|The functions vector.isvector and table.isvector are identical."
|
||||
"|") {
|
||||
LuaArg table;
|
||||
LuaRet result;
|
||||
LuaVar tmp;
|
||||
@@ -81,27 +90,44 @@ static int check_isvector(lua_State *L) {
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
LuaDefine(table_isvector, "table",
|
||||
"|Return true if the table is a valid vector."
|
||||
LuaDefine(table_isvectorq, "table",
|
||||
"|Return true if the table is probably a valid vector."
|
||||
"|"
|
||||
"|A vector is a table that has keys starting with 1, and no gaps."
|
||||
"|The empty table also counts as a valid vector."
|
||||
"|The empty table also counts as a valid vector. This function"
|
||||
"|does a constant-time heuristic check: it gets the number of keys"
|
||||
"|in the table, NKEYS. Then it verifies that table[NKEYS] is not"
|
||||
"|nil and that table[NKEYS+1] is nil. If these things are both"
|
||||
"|true, the table is very likely a valid vector."
|
||||
"|"
|
||||
"|This function is identical to vector.isvector"
|
||||
"|The functions vector.isvectorq and table.isvectorq are identical."
|
||||
"|") {
|
||||
return check_isvector(L);
|
||||
LuaArg table;
|
||||
LuaRet result;
|
||||
LuaVar tmp;
|
||||
LuaDefStack LS(L, table, result, tmp);
|
||||
if (!LS.istable(table)) {
|
||||
LS.set(result, false);
|
||||
return LS.result();
|
||||
}
|
||||
int nkeys = LS.nkeys(table);
|
||||
if (nkeys > 0) {
|
||||
LS.rawget(tmp, table, nkeys);
|
||||
if (LS.isnil(tmp)) {
|
||||
LS.set(result, false);
|
||||
return LS.result();
|
||||
}
|
||||
LS.rawget(tmp, table, nkeys + 1);
|
||||
if (!LS.isnil(tmp)) {
|
||||
LS.set(result, false);
|
||||
return LS.result();
|
||||
}
|
||||
}
|
||||
LS.set(result, true);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
LuaDefine(vector_isvector, "table",
|
||||
"|Return true if the table is a valid vector."
|
||||
"|"
|
||||
"|A vector is a table that has keys starting with 1, and no gaps."
|
||||
"|The empty table also counts as a valid vector."
|
||||
"|"
|
||||
"|This function is identical to table.isvector"
|
||||
"|") {
|
||||
return check_isvector(L);
|
||||
}
|
||||
LuaDefineAlias(vector_isvector, table_isvector);
|
||||
|
||||
LuaDefine(vector_removeall, "vector,value",
|
||||
"|Remove all occurrences of value from vector."
|
||||
|
||||
Reference in New Issue
Block a user