From aa76a9f59da530c1dedb48f6ef1ca9f5670b7672 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 13 Jun 2010 22:03:46 +0000 Subject: [PATCH] support class method versions of MAKE_SEQ --- dtool/src/interrogate/interfaceMaker.cxx | 26 +++++++++++++++++++ dtool/src/interrogate/interfaceMaker.h | 1 + .../interfaceMakerPythonNative.cxx | 6 ++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dtool/src/interrogate/interfaceMaker.cxx b/dtool/src/interrogate/interfaceMaker.cxx index 2fb060dfa7..ab6354dab0 100644 --- a/dtool/src/interrogate/interfaceMaker.cxx +++ b/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 diff --git a/dtool/src/interrogate/interfaceMaker.h b/dtool/src/interrogate/interfaceMaker.h index 2eb0f2131d..3f43a9772e 100644 --- a/dtool/src/interrogate/interfaceMaker.h +++ b/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; diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 6e71c3814d..4f9f9a5e76 100755 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/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"