LuaBridge: Dedicated type for pointer-lists and const version
authorRobin Gareus <robin@gareus.org>
Thu, 23 Feb 2017 21:21:08 +0000 (22:21 +0100)
committerRobin Gareus <robin@gareus.org>
Thu, 23 Feb 2017 21:32:32 +0000 (22:32 +0100)
"class C*" cannot be defined nor resolved, so STL containers
to class instance pointers need to be special-cased.

libs/lua/LuaBridge/detail/Namespace.h

index f4f2ae21352711f3e307fc2ec4fb3b4dd6990f58..3644b9e1572ba125de74259a1ad067f04bf9a6b4 100644 (file)
@@ -1864,7 +1864,34 @@ public:
   }
 
   template <class T>
-  Class<std::vector<T> > beginStdVector (char const* name)
+  Class<std::list<T*> > beginConstStdCPtrList (char const* name)
+  {
+    typedef T* TP;
+    typedef std::list<TP> LT;
+    return beginClass<LT> (name)
+      .addVoidConstructor ()
+      .addFunction ("empty", &LT::empty)
+      .addFunction ("size", &LT::size)
+      .addFunction ("reverse", &LT::reverse)
+      .addFunction ("front", static_cast<const TP& (LT::*)() const>(&LT::front))
+      .addFunction ("back", static_cast<const TP& (LT::*)() const>(&LT::back))
+      .addExtCFunction ("iter", &CFunc::listIter<T*, LT>)
+      .addExtCFunction ("table", &CFunc::listToTable<T*, LT>);
+  }
+
+  template <class T>
+  Class<std::list<T*> > beginStdCPtrList (char const* name)
+  {
+    typedef T* TP;
+    typedef std::list<TP> LT;
+    return beginConstStdCPtrList<T> (name)
+      .addFunction ("unique", (void (LT::*)())&LT::unique)
+      .addFunction ("push_back", (void (LT::*)(const TP&))&LT::push_back);
+  }
+
+
+  template <class T>
+  Class<std::vector<T> > beginConstStdVector (char const* name)
   {
     typedef std::vector<T> LT;
     typedef typename std::vector<T>::reference T_REF;
@@ -1874,13 +1901,23 @@ public:
       .addVoidConstructor ()
       .addFunction ("empty", &LT::empty)
       .addFunction ("size", &LT::size)
-      .addFunction ("push_back", (void (LT::*)(const T&))&LT::push_back)
       .addFunction ("at", (T_REF (LT::*)(T_SIZE))&LT::at)
-      .addExtCFunction ("add", &CFunc::tableToList<T, LT>)
       .addExtCFunction ("iter", &CFunc::listIter<T, LT>)
       .addExtCFunction ("table", &CFunc::listToTable<T, LT>);
   }
 
+  template <class T>
+  Class<std::vector<T> > beginStdVector (char const* name)
+  {
+    typedef std::vector<T> LT;
+    return beginConstStdVector<T> (name)
+      .addVoidConstructor ()
+      .addFunction ("push_back", (void (LT::*)(const T&))&LT::push_back)
+      .addExtCFunction ("add", &CFunc::tableToList<T, LT>);
+  }
+
+
+
   //----------------------------------------------------------------------------
 
   template <class T>