support class method versions of MAKE_SEQ

This commit is contained in:
David Rose 2010-06-13 22:03:46 +00:00
parent 94eeacbbe2
commit aa76a9f59d
3 changed files with 32 additions and 1 deletions

View File

@ -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

View File

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

View File

@ -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"