add lua/C++ dynamic_cast<>
[ardour.git] / libs / lua / LuaBridge / detail / Namespace.h
index 590f25be4a1408145a5a66b9ada33f859c09aec4..79a0786d405a779fef115cbaca2d8949b5b8401b 100644 (file)
@@ -1048,6 +1048,22 @@ private:
       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 */