Bladeren bron

add color32.__hash__

blueloveTH 7 maanden geleden
bovenliggende
commit
84d7292b5d
2 gewijzigde bestanden met toevoegingen van 10 en 0 verwijderingen
  1. 1 0
      include/typings/vmath.pyi
  2. 9 0
      src/modules/vmath.c

+ 1 - 0
include/typings/vmath.pyi

@@ -186,6 +186,7 @@ class color32:
     def __eq__(self, other: object) -> bool: ...
     def __eq__(self, other: object) -> bool: ...
     def __ne__(self, other: object) -> bool: ...
     def __ne__(self, other: object) -> bool: ...
     def __repr__(self) -> str: ...
     def __repr__(self) -> str: ...
+    def __hash__(self) -> int: ...
 
 
     @property
     @property
     def r(self) -> int: ...
     def r(self) -> int: ...

+ 9 - 0
src/modules/vmath.c

@@ -1011,6 +1011,14 @@ static bool color32__repr__(int argc, py_Ref argv) {
     return true;
     return true;
 }
 }
 
 
+static bool color32__hash__(int argc, py_Ref argv) {
+    PY_CHECK_ARGC(1);
+    c11_color32 color = py_tocolor32(argv);
+    uint32_t* color_int = (uint32_t*)&color;
+    py_newint(py_retval(), *color_int);
+    return true;
+}
+
 static bool color32_ansi_fg(int argc, py_Ref argv) {
 static bool color32_ansi_fg(int argc, py_Ref argv) {
     PY_CHECK_ARGC(2);
     PY_CHECK_ARGC(2);
     c11_color32 color = py_tocolor32(argv);
     c11_color32 color = py_tocolor32(argv);
@@ -1256,6 +1264,7 @@ void pk__add_module_vmath() {
     py_bindmagic(color32, __repr__, color32__repr__);
     py_bindmagic(color32, __repr__, color32__repr__);
     py_bindmagic(color32, __eq__, color32__eq__);
     py_bindmagic(color32, __eq__, color32__eq__);
     py_bindmagic(color32, __ne__, color32__ne__);
     py_bindmagic(color32, __ne__, color32__ne__);
+    py_bindmagic(color32, __hash__, color32__hash__);
     py_bindproperty(color32, "r", color32__r, NULL);
     py_bindproperty(color32, "r", color32__r, NULL);
     py_bindproperty(color32, "g", color32__g, NULL);
     py_bindproperty(color32, "g", color32__g, NULL);
     py_bindproperty(color32, "b", color32__b, NULL);
     py_bindproperty(color32, "b", color32__b, NULL);