Lua: provide instance-equal check as '==' comparator.
authorRobin Gareus <robin@gareus.org>
Thu, 16 Mar 2017 19:08:17 +0000 (20:08 +0100)
committerRobin Gareus <robin@gareus.org>
Thu, 16 Mar 2017 19:08:17 +0000 (20:08 +0100)
This deprecated explicit the "sameinstance()" method

libs/lua/LuaBridge/detail/CFunctions.h
libs/lua/LuaBridge/detail/Namespace.h

index 2f1c3f635b4e2fd972d5a716dbc76df89f8f4316..2f94ab90e9230fea3f0445090e255a67f2844451 100644 (file)
@@ -378,7 +378,6 @@ struct CFunc
     }
   };
 
-
   template <class T, class R>
   struct CastClass
   {
@@ -461,6 +460,24 @@ struct CFunc
     }
   };
 
+  template <class T>
+  struct ClassEqualCheck<boost::shared_ptr<T> >
+  {
+    static int f (lua_State* L)
+    {
+      return PtrEqualCheck<T>::f (L);
+    }
+  };
+
+  template <class T>
+  struct ClassEqualCheck<boost::weak_ptr<T> >
+  {
+    static int f (lua_State* L)
+    {
+      return WPtrEqualCheck<T>::f (L);
+    }
+  };
+
   template <class C, typename T>
   static int getPtrProperty (lua_State* L)
   {
index 3644b9e1572ba125de74259a1ad067f04bf9a6b4..b661093e2b25db3eb620b9f5e55112eeaffb16b8 100644 (file)
@@ -579,10 +579,14 @@ private:
         createConstTable (name);
         lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
         rawsetfield (L, -2, "__gc");
+        lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+        rawsetfield (L, -2, "__eq");
 
         createClassTable (name);
         lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
         rawsetfield (L, -2, "__gc");
+        lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+        rawsetfield (L, -2, "__eq");
 
         createStaticTable (name);
 
@@ -626,10 +630,14 @@ private:
       createConstTable (name);
       lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
       rawsetfield (L, -2, "__gc");
+      lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+      rawsetfield (L, -2, "__eq");
 
       createClassTable (name);
       lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
       rawsetfield (L, -2, "__gc");
+      lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+      rawsetfield (L, -2, "__eq");
 
       createStaticTable (name);
 
@@ -1159,10 +1167,14 @@ private:
         createConstTable (name);
         lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
         rawsetfield (L, -2, "__gc");
+        lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+        rawsetfield (L, -2, "__eq");
 
         createClassTable (name);
         lua_pushcfunction (L, &CFunc::gcMetaMethod <T>);
         rawsetfield (L, -2, "__gc");
+        lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+        rawsetfield (L, -2, "__eq");
 
         createStaticTable (name);