diff options
author | Robin Gareus <robin@gareus.org> | 2017-03-30 03:39:28 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-03-30 04:15:28 +0200 |
commit | 412b6a4cb9ae44403e79fd5cc75c105fea005d1e (patch) | |
tree | 43c680dade05d2dc19c54ab46fb91ee4f51ca574 /libs/lua | |
parent | eb1bd9d8e205c0852742567af212450be8cbd507 (diff) |
Lua: make external (static) functions available for const objects.
This fixes iterators on const std::lists<>& and const std::map<>&
Diffstat (limited to 'libs/lua')
-rw-r--r-- | libs/lua/LuaBridge/detail/CFunctions.h | 8 | ||||
-rw-r--r-- | libs/lua/LuaBridge/detail/Namespace.h | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/libs/lua/LuaBridge/detail/CFunctions.h b/libs/lua/LuaBridge/detail/CFunctions.h index b7636f8296..7300e9cb70 100644 --- a/libs/lua/LuaBridge/detail/CFunctions.h +++ b/libs/lua/LuaBridge/detail/CFunctions.h @@ -1167,7 +1167,7 @@ struct CFunc // generate an iterator template <class T, class C> - static int listIterHelper (lua_State *L, C * const t) + static int listIterHelper (lua_State *L, C const * const t) { if (!t) { return luaL_error (L, "invalid pointer to std::list<>/std::vector"); } typedef typename C::const_iterator IterType; @@ -1180,7 +1180,7 @@ struct CFunc template <class T, class C> static int listIter (lua_State *L) { - C * const t = Userdata::get <C> (L, 1, false); + C const * const t = Userdata::get <C> (L, 1, true); return listIterHelper<T, C> (L, t); } @@ -1284,7 +1284,7 @@ struct CFunc static int mapIter (lua_State *L) { typedef std::map<K, V> C; - C * const t = Userdata::get <C> (L, 1, false); + C const * const t = Userdata::get <C> (L, 1, true); if (!t) { return luaL_error (L, "invalid pointer to std::map"); } typedef typename C::const_iterator IterType; new (lua_newuserdata (L, sizeof (IterType*))) IterType (t->begin()); @@ -1378,7 +1378,7 @@ struct CFunc template <class T, class C> static int setIter (lua_State *L) { - C * const t = Userdata::get <C> (L, 1, false); + C const * const t = Userdata::get <C> (L, 1, true); 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()); diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h index e8c02283b5..a8e190da43 100644 --- a/libs/lua/LuaBridge/detail/Namespace.h +++ b/libs/lua/LuaBridge/detail/Namespace.h @@ -984,6 +984,8 @@ private: DATADOC ("Ext C Function", name, fp) assert (lua_istable (L, -1)); lua_pushcclosure (L, fp, 0); + lua_pushvalue (L, -1); + rawsetfield (L, -5, name); // const table rawsetfield (L, -3, name); // class table return *this; } @@ -1320,11 +1322,15 @@ private: set_shared_class (); assert (lua_istable (L, -1)); lua_pushcclosure (L, fp, 0); + lua_pushvalue (L, -1); + rawsetfield (L, -5, name); // const table rawsetfield (L, -3, name); // class table set_weak_class (); assert (lua_istable (L, -1)); lua_pushcclosure (L, fp, 0); + lua_pushvalue (L, -1); + rawsetfield (L, -5, name); // const table rawsetfield (L, -3, name); // class table return *this; |