File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -46,3 +46,46 @@ func (a Bool) M__str__() Object {
46
46
var _ I__bool__ = Bool (false )
47
47
var _ I__index__ = Bool (false )
48
48
var _ I__str__ = Bool (false )
49
+
50
+ // Convert an Object to an Bool
51
+ //
52
+ // Retrurns ok as to whether the conversion worked or not
53
+ func convertToBool (other Object ) (Bool , bool ) {
54
+ switch b := other .(type ) {
55
+ case Bool :
56
+ return b , true
57
+ case Int :
58
+ switch b {
59
+ case 0 :
60
+ return False , true
61
+ case 1 :
62
+ return True , true
63
+ default :
64
+ return False , false
65
+ }
66
+ case Float :
67
+ switch b {
68
+ case 0 :
69
+ return False , true
70
+ case 1 :
71
+ return True , true
72
+ default :
73
+ return False , false
74
+ }
75
+ }
76
+ return False , false
77
+ }
78
+
79
+ func (a Bool ) M__eq__ (other Object ) Object {
80
+ if b , ok := convertToBool (other ); ok {
81
+ return NewBool (a == b )
82
+ }
83
+ return False
84
+ }
85
+
86
+ func (a Bool ) M__ne__ (other Object ) Object {
87
+ if b , ok := convertToBool (other ); ok {
88
+ return NewBool (a != b )
89
+ }
90
+ return True
91
+ }
You can’t perform that action at this time.
0 commit comments