add lua/C++ dynamic_cast<>
[ardour.git] / libs / lua / LuaBridge / detail / Namespace.h
index fc8194303ba019061f57585ab4a41e3a2d169a47..79a0786d405a779fef115cbaca2d8949b5b8401b 100644 (file)
@@ -29,6 +29,7 @@
 //==============================================================================
 
 #ifdef LUABINDINGDOC
+#include <iostream>
 #include <typeinfo>
 #include <execinfo.h>
 #include <type_traits>
@@ -1038,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 */
@@ -1059,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;
@@ -1116,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
       {
@@ -1588,6 +1625,7 @@ public:
   */
   Namespace& addCFunction (char const* name, int (*const fp)(lua_State*))
   {
+    DATADOC ("Free C Function", name, fp)
     lua_pushcfunction (L, fp);
     rawsetfield (L, -2, name);