feat(util/name_set): improve name_set Lua API
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
95262fb68d
commit
5a7f181efc
2 changed files with 12 additions and 1 deletions
|
@ -19,7 +19,13 @@ name mk_unique(name_set const & s, name const & suggestion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_UDATA(name_set)
|
DECL_UDATA(name_set)
|
||||||
static int mk_name_set(lua_State * L) { return push_name_set(L, name_set()); }
|
static int mk_name_set(lua_State * L) {
|
||||||
|
name_set r;
|
||||||
|
int nargs = lua_gettop(L);
|
||||||
|
for (int i = 1; i <= nargs; i++)
|
||||||
|
r.insert(to_name_ext(L, i));
|
||||||
|
return push_name_set(L, r);
|
||||||
|
}
|
||||||
static int name_set_insert(lua_State * L) { return push_name_set(L, insert(to_name_set(L, 1), to_name_ext(L, 2))); }
|
static int name_set_insert(lua_State * L) { return push_name_set(L, insert(to_name_set(L, 1), to_name_ext(L, 2))); }
|
||||||
static int name_set_contains(lua_State * L) { return push_boolean(L, to_name_set(L, 1).contains(to_name_ext(L, 2))); }
|
static int name_set_contains(lua_State * L) { return push_boolean(L, to_name_set(L, 1).contains(to_name_ext(L, 2))); }
|
||||||
static int name_set_erase(lua_State * L) { return push_name_set(L, erase(to_name_set(L, 1), to_name_ext(L, 2))); }
|
static int name_set_erase(lua_State * L) { return push_name_set(L, erase(to_name_set(L, 1), to_name_ext(L, 2))); }
|
||||||
|
|
5
tests/lua/ns2.lua
Normal file
5
tests/lua/ns2.lua
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
local s = name_set("a", "b", "c", {"a", 1})
|
||||||
|
assert(s:contains("a"))
|
||||||
|
assert(s:contains({"a", 1}))
|
||||||
|
assert(s:contains("b"))
|
||||||
|
assert(s:contains("c"))
|
Loading…
Reference in a new issue