From 5a7f181efc3a33f80418a70177f1fe31bcf8d209 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 8 May 2014 17:17:00 -0700 Subject: [PATCH] feat(util/name_set): improve name_set Lua API Signed-off-by: Leonardo de Moura --- src/util/name_set.cpp | 8 +++++++- tests/lua/ns2.lua | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/lua/ns2.lua diff --git a/src/util/name_set.cpp b/src/util/name_set.cpp index 9c0d5f007..b59025246 100644 --- a/src/util/name_set.cpp +++ b/src/util/name_set.cpp @@ -19,7 +19,13 @@ name mk_unique(name_set const & s, name const & suggestion) { } 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_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))); } diff --git a/tests/lua/ns2.lua b/tests/lua/ns2.lua new file mode 100644 index 000000000..7261e944e --- /dev/null +++ b/tests/lua/ns2.lua @@ -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"))