Explorar el Código

support class method versions of MAKE_SEQ

David Rose hace 15 años
padre
commit
aa76a9f59d

+ 26 - 0
dtool/src/interrogate/interfaceMaker.cxx

@@ -177,6 +177,32 @@ check_protocols() {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: InterfaceMaker::Object::is_static_method
+//       Access: Public
+//  Description: Returns true if the first method found with the
+//               indicated name is a static method, false if it is an
+//               instance method.  This does not test all overloads of
+//               the indicated name, merely the first one found.
+////////////////////////////////////////////////////////////////////
+bool InterfaceMaker::Object::
+is_static_method(const string &name) {
+  Functions::const_iterator fi;
+  for (fi = _methods.begin(); fi != _methods.end(); ++fi) {
+    Function *func = (*fi);
+    if (!func->_remaps.empty()) {
+      FunctionRemap *remap = func->_remaps.front();
+      string method_name = remap->_cppfunc->get_simple_name();
+      if (method_name == name) {
+        return !func->_has_this;
+      }
+    }
+  }
+
+  // Didn't find the requested function.
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: InterfaceMaker::Constructor
 //       Access: Public

+ 1 - 0
dtool/src/interrogate/interfaceMaker.h

@@ -103,6 +103,7 @@ public:
     ~Object();
 
     void check_protocols();
+    bool is_static_method(const string &name);
 
     const InterrogateType &_itype;
     Functions _constructors;

+ 5 - 1
dtool/src/interrogate/interfaceMakerPythonNative.cxx

@@ -1259,9 +1259,13 @@ write_module_class(ostream &out,  Object *obj) {
   
   MakeSeqs::iterator msi;
   for (msi = obj->_make_seqs.begin(); msi != obj->_make_seqs.end(); ++msi) {
+    string flags = "METH_NOARGS";
+    if (obj->is_static_method((*msi)->_element_name)) {
+      flags += "|METH_CLASS";
+    }
     out << "  { \""
         << methodNameFromCppName((*msi)->_seq_name, export_calss_name)
-        << "\",(PyCFunction) &" << (*msi)->_name << ", METH_NOARGS, NULL},\n";
+        << "\",(PyCFunction) &" << (*msi)->_name << ", " << flags << ", NULL},\n";
   }
 
   out << "  { NULL, NULL }\n"