From bc300ddab733bb15b09d9341e75655d68fbd937e Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 18 Mar 2017 14:34:02 +0100 Subject: [PATCH] Make Lua std::set bindings more generic, (prepare for multiset etc) --- libs/lua/LuaBridge/detail/CFunctions.h | 14 +++++--------- libs/lua/LuaBridge/detail/Namespace.h | 5 ++--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libs/lua/LuaBridge/detail/CFunctions.h b/libs/lua/LuaBridge/detail/CFunctions.h index 2f94ab90e9..b7636f8296 100644 --- a/libs/lua/LuaBridge/detail/CFunctions.h +++ b/libs/lua/LuaBridge/detail/CFunctions.h @@ -1331,10 +1331,9 @@ struct CFunc // generate std::set from table keys ( table[member] = true ) // http://www.lua.org/pil/11.5.html - template + template static int tableToSet (lua_State *L) { - typedef std::set C; C * const t = Userdata::get (L, 1, true); if (!t) { return luaL_error (L, "invalid pointer to std::set"); } if (!lua_istable (L, -1)) { return luaL_error (L, "argument is not a table"); } @@ -1358,10 +1357,9 @@ struct CFunc // iterate over a std::set, explicit "true" value. // compare to http://www.lua.org/pil/11.5.html - template + template static int setIterIter (lua_State *L) { - typedef std::set C; typedef typename C::const_iterator IterType; IterType * const end = static_cast (lua_touserdata (L, lua_upvalueindex (2))); IterType * const iter = static_cast (lua_touserdata (L, lua_upvalueindex (1))); @@ -1377,24 +1375,22 @@ struct CFunc } // generate iterator - template + template static int setIter (lua_State *L) { - typedef std::set C; C * const t = Userdata::get (L, 1, false); if (!t) { return luaL_error (L, "invalid pointer to std::set"); } typedef typename C::const_iterator IterType; new (lua_newuserdata (L, sizeof (IterType*))) IterType (t->begin()); new (lua_newuserdata (L, sizeof (IterType*))) IterType (t->end()); - lua_pushcclosure (L, setIterIter, 2); + lua_pushcclosure (L, setIterIter, 2); return 1; } // generate table from std::set - template + template static int setToTable (lua_State *L) { - typedef std::set C; C const* const t = Userdata::get (L, 1, true); if (!t) { return luaL_error (L, "invalid pointer to std::set"); } diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h index f9ec8eb636..e8c02283b5 100644 --- a/libs/lua/LuaBridge/detail/Namespace.h +++ b/libs/lua/LuaBridge/detail/Namespace.h @@ -1824,9 +1824,8 @@ public: .addFunction ("clear", (void (LT::*)())<::clear) .addFunction ("empty", <::empty) .addFunction ("size", <::size) - .addExtCFunction ("add", &CFunc::tableToSet) - .addExtCFunction ("iter", &CFunc::setIter) - .addExtCFunction ("table", &CFunc::setToTable); + .addExtCFunction ("iter", &CFunc::setIter) + .addExtCFunction ("table", &CFunc::setToTable); } template