From 412b6a4cb9ae44403e79fd5cc75c105fea005d1e Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 30 Mar 2017 03:39:28 +0200 Subject: Lua: make external (static) functions available for const objects. This fixes iterators on const std::lists<>& and const std::map<>& --- libs/lua/LuaBridge/detail/CFunctions.h | 8 ++++---- libs/lua/LuaBridge/detail/Namespace.h | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'libs') 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 - 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 static int listIter (lua_State *L) { - C * const t = Userdata::get (L, 1, false); + C const * const t = Userdata::get (L, 1, true); return listIterHelper (L, t); } @@ -1284,7 +1284,7 @@ struct CFunc static int mapIter (lua_State *L) { typedef std::map C; - C * const t = Userdata::get (L, 1, false); + C const * const t = Userdata::get (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 static int setIter (lua_State *L) { - C * const t = Userdata::get (L, 1, false); + C const * const t = Userdata::get (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; -- cgit v1.2.3