Use correct type of std::map::count
[ardour.git] / libs / lua / LuaBridge / detail / Namespace.h
index 722d02e4a766065b4e1f02a822cf09ad8752b2b7..92aed815305aa1f4cf68532dd769cf6f6ddbd06d 100644 (file)
@@ -1039,6 +1039,31 @@ private:
       return addConstructor <void (*) ()> ();
     }
 
+    Class <T>& addEqualCheck ()
+    {
+      PRINTDOC("Member Function", _name << "sameinstance", std::string("bool"), std::string("void (*)(" + type_name <T>() + ")"))
+      assert (lua_istable (L, -1));
+      lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+      rawsetfield (L, -3, "sameinstance");
+      return *this;
+    }
+
+    template <class U>
+    Class <T>& addCast (char const* name)
+    {
+      PRINTDOC("Cast", _name << name,
+          type_name< U >(),
+          type_name< U >() << " (" << type_name< T >() << "::*)()")
+
+      assert (lua_istable (L, -1));
+      lua_pushcclosure (L, &CFunc::CastClass <T, U>::f, 0);
+      rawsetfield (L, -3, name); // class table
+
+      lua_pushcclosure (L, &CFunc::CastConstClass <T, U>::f, 0);
+      rawsetfield (L, -4, name); // const table
+      return *this;
+    }
+
   };
 
   /** C Array to/from table */
@@ -1060,6 +1085,10 @@ private:
           std::string(""), "int (*)(lua_State*)")
       PRINTDOC ("Ext C Function", _name << "set_table",
           std::string(""), "int (*)(lua_State*)")
+      PRINTDOC("Member Function", _name << "sameinstance",
+          std::string("bool"), std::string("bool (*)(" + type_name <T>() + "*)"))
+      PRINTDOC("Member Function", _name << "offset",
+          std::string(type_name <T>() + "*"), std::string(type_name <T>() + "* (*)(unsigned int)"))
 
       m_stackSize = parent->m_stackSize + 3;
       parent->m_stackSize = 0;
@@ -1117,6 +1146,13 @@ private:
 
         lua_pushcclosure (L, &CFunc::setTable <T>, 0);
         rawsetfield (L, -3, "set_table"); // class table
+
+        lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+        rawsetfield (L, -3, "sameinstance");
+
+        lua_pushcclosure (L, &CFunc::offsetArray <T>, 0);
+        rawsetfield (L, -3, "offset"); // class table
+
       }
       else
       {
@@ -1622,12 +1658,14 @@ public:
     typedef std::map<K, V> LT;
     typedef std::pair<const K, V> T;
 
+    typedef typename std::map<K, V>::size_type T_SIZE;
+
     return beginClass<LT> (name)
       .addVoidConstructor ()
       .addFunction ("empty", &LT::empty)
       .addFunction ("size", &LT::size)
       .addFunction ("clear", (void (LT::*)())&LT::clear)
-      .addFunction ("count", (void (LT::*)())&LT::count)
+      .addFunction ("count", (T_SIZE (LT::*)(const K&) const)&LT::count)
       .addExtCFunction ("add", &CFunc::tableToMap<K, V>)
       .addExtCFunction ("iter", &CFunc::mapIter<K, V>)
       .addExtCFunction ("table", &CFunc::mapToTable<K, V>);