瀏覽代碼

respect __nonzero__

David Rose 16 年之前
父節點
當前提交
0e773c8684
共有 1 個文件被更改,包括 50 次插入43 次删除
  1. 50 43
      dtool/src/interrogate/interfaceMakerPythonNative.cxx

+ 50 - 43
dtool/src/interrogate/interfaceMakerPythonNative.cxx

@@ -56,49 +56,50 @@ struct FlagSet {
 
 ///////////////////////////////////////////////////////////////////////////////////////
 RenameSet methodRenameDictionary[] = {
-    { "operator =="  , "eq",                   0 },
-    { "operator !="  , "ne",                   0 },
-    { "operator <<"  , "__lshift__",           0 },
-    { "operator >>"  , "__rshift__",           0 },
-    { "operator <"   , "lessThan",             0 },
-    { "operator >"   , "greaterThan",          0 },
-    { "operator <="  , "lessThanOrEqual",      0 },
-    { "operator >="  , "greaterThanOrEqual",   0 },
-    { "operator ="   , "assign",               0 },
-    { "operator ()"  , "__call__",             0 },
-    { "operator []"  , "__getitem__",          0 },
-    { "operator ++unary"  , "increment",            0 },
-    { "operator ++"  , "increment",            0 },
-    { "operator --unary"  , "decrement",            0 },
-    { "operator --"  , "decrement",            0 },
-    { "operator ^"   , "__xor__",              0 },
-    { "operator %"   , "__mod__",              0 },
-    { "operator !"   , "logicalNot",           0 },
-    { "operator ~unary"   , "__invert__",           0 },
-    { "operator &"   , "__and__",              0 },
-    { "operator &&"  , "logicalAnd",           0 },
-    { "operator |"   , "__or__",               0 },
-    { "operator ||"  , "logicalOr",            0 },
-    { "operator +"   , "__add__",              0 },
-    { "operator -"   , "__sub__",              0 },
-    { "operator -unary", "__neg__",            0 },
-    { "operator *"   , "__mul__",              0 },
-    { "operator /"   , "__div__",              0 },
-    { "operator +="  , "__iadd__",             1 },
-    { "operator -="  , "__isub__",             1 },
-    { "operator *="  , "__imul__",             1 },
-    { "operator /="  , "__idiv__",             1 },
-    { "operator ,"   , "concatenate",          0 },
-    { "operator |="  , "__ior__",              1 },
-    { "operator &="  , "__iand__",             1 },
-    { "operator ^="  , "__ixor__",             1 },
-    { "operator ~="  , "bitwiseNotEqual",      0 },
-    { "operator ->"  , "dereference",          0 },
-    { "operator <<=" , "__ilshift__",          1 },
-    { "operator >>=" , "__irshift__",          1 },
-    { "operator typecast bool" , "__nonzero__", 0 },
-    { "print"       , "Cprint",               0 },
-    { "CInterval.set_t" , "_priv__cSetT",      0 },
+    { "operator =="   , "eq",                   0 },
+    { "operator !="   , "ne",                   0 },
+    { "operator <<"   , "__lshift__",           0 },
+    { "operator >>"   , "__rshift__",           0 },
+    { "operator <"    , "lessThan",             0 },
+    { "operator >"    , "greaterThan",          0 },
+    { "operator <="   , "lessThanOrEqual",      0 },
+    { "operator >="   , "greaterThanOrEqual",   0 },
+    { "operator ="    , "assign",               0 },
+    { "operator ()"   , "__call__",             0 },
+    { "operator []"   , "__getitem__",          0 },
+    { "operator ++unary", "increment",          0 },
+    { "operator ++"   , "increment",            0 },
+    { "operator --unary", "decrement",          0 },
+    { "operator --"   , "decrement",            0 },
+    { "operator ^"    , "__xor__",              0 },
+    { "operator %"    , "__mod__",              0 },
+    { "operator !"    , "logicalNot",           0 },
+    { "operator ~unary", "__invert__",          0 },
+    { "operator &"    , "__and__",              0 },
+    { "operator &&"   , "logicalAnd",           0 },
+    { "operator |"    , "__or__",               0 },
+    { "operator ||"   , "logicalOr",            0 },
+    { "operator +"    , "__add__",              0 },
+    { "operator -"    , "__sub__",              0 },
+    { "operator -unary", "__neg__",             0 },
+    { "operator *"    , "__mul__",              0 },
+    { "operator /"    , "__div__",              0 },
+    { "operator +="   , "__iadd__",             1 },
+    { "operator -="   , "__isub__",             1 },
+    { "operator *="   , "__imul__",             1 },
+    { "operator /="   , "__idiv__",             1 },
+    { "operator ,"    , "concatenate",          0 },
+    { "operator |="   , "__ior__",              1 },
+    { "operator &="   , "__iand__",             1 },
+    { "operator ^="   , "__ixor__",             1 },
+    { "operator ~="   , "bitwiseNotEqual",      0 },
+    { "operator ->"   , "dereference",          0 },
+    { "operator <<="  , "__ilshift__",          1 },
+    { "operator >>="  , "__irshift__",          1 },
+    { "operator typecast bool", "__nonzero__",  0 },
+    { "__nonzero__"   , "__nonzero__",          0 },
+    { "print"         , "Cprint",               0 },
+    { "CInterval.set_t", "_priv__cSetT",        0 },
     { NULL, NULL, -1 }
     };
 
@@ -558,6 +559,12 @@ get_slotted_function_def(Object *obj, Function *func, SlottedFunctionDef &def) {
     return true;
   }
 
+  if (method_name == "__nonzero__") {
+    def._answer_location = "tp_as_number->nb_nonzero";
+    def._wrapper_type = WT_inquiry;
+    return true;
+  }
+
   if (func->_ifunc.is_operator_typecast()) {
     // A typecast operator.  Check for a supported low-level typecast type.
     if (!func->_remaps.empty()) {