diff options
author | Robin Gareus <robin@gareus.org> | 2017-03-18 14:34:02 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-03-18 14:35:29 +0100 |
commit | bc300ddab733bb15b09d9341e75655d68fbd937e (patch) | |
tree | fb078b1c0df58722bfb93b5a9ce7ccec58303cac /libs/lua | |
parent | a1116ebd6f19c30c8a85200c19ec30c00337ccda (diff) |
Make Lua std::set bindings more generic, (prepare for multiset etc)
Diffstat (limited to 'libs/lua')
-rw-r--r-- | libs/lua/LuaBridge/detail/CFunctions.h | 14 | ||||
-rw-r--r-- | 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 <class T> + template <class T, class C> static int tableToSet (lua_State *L) { - typedef std::set<T> C; C * const t = Userdata::get <C> (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 <class T> + template <class T, class C> static int setIterIter (lua_State *L) { - typedef std::set<T> C; typedef typename C::const_iterator IterType; IterType * const end = static_cast <IterType * const> (lua_touserdata (L, lua_upvalueindex (2))); IterType * const iter = static_cast <IterType * const> (lua_touserdata (L, lua_upvalueindex (1))); @@ -1377,24 +1375,22 @@ struct CFunc } // generate iterator - template <class T> + template <class T, class C> static int setIter (lua_State *L) { - typedef std::set<T> C; C * const t = Userdata::get <C> (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<T>, 2); + lua_pushcclosure (L, setIterIter<T, C>, 2); return 1; } // generate table from std::set - template <class T> + template <class T, class C> static int setToTable (lua_State *L) { - typedef std::set<T> C; C const* const t = Userdata::get <C> (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<T>) - .addExtCFunction ("iter", &CFunc::setIter<T>) - .addExtCFunction ("table", &CFunc::setToTable<T>); + .addExtCFunction ("iter", &CFunc::setIter<T, LT>) + .addExtCFunction ("table", &CFunc::setToTable<T, LT>); } template <unsigned int T> |