blueloveTH 3 лет назад
Родитель
Сommit
f4fe849432

+ 5 - 0
plugins/flutter/src/pocketpy.h

@@ -6710,6 +6710,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
     });
 
     /************ PyBool ************/
+    _vm->bindMethod("bool", "__new__", [](VM* vm, const pkpy::ArgList& args) {
+        vm->__checkArgSize(args, 1);
+        return vm->asBool(args[0]);
+    });
+
     _vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
         bool val = vm->PyBool_AS_C(args[0]);
         return vm->PyStr(val ? "True" : "False");

+ 1 - 1
plugins/godot/godot-cpp

@@ -1 +1 @@
-Subproject commit cb98c82ac6dc5cf83cb107d1cbf3fc9219e296e4
+Subproject commit f0c35d535dca99b31b15100f82f48bc1becbca45

+ 5 - 0
plugins/unity/com.bl.pocketpy/Plugins/iOS/pocketpy.h

@@ -6710,6 +6710,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
     });
 
     /************ PyBool ************/
+    _vm->bindMethod("bool", "__new__", [](VM* vm, const pkpy::ArgList& args) {
+        vm->__checkArgSize(args, 1);
+        return vm->asBool(args[0]);
+    });
+
     _vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
         bool val = vm->PyBool_AS_C(args[0]);
         return vm->PyStr(val ? "True" : "False");

+ 5 - 0
src/pocketpy.h

@@ -534,6 +534,11 @@ void __initializeBuiltinFunctions(VM* _vm) {
     });
 
     /************ PyBool ************/
+    _vm->bindMethod("bool", "__new__", [](VM* vm, const pkpy::ArgList& args) {
+        vm->__checkArgSize(args, 1);
+        return vm->asBool(args[0]);
+    });
+
     _vm->bindMethod("bool", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
         bool val = vm->PyBool_AS_C(args[0]);
         return vm->PyStr(val ? "True" : "False");

+ 7 - 0
tests/basic.py

@@ -75,6 +75,13 @@ assert True or False
 assert not False
 assert not (not True)
 
+assert bool(0) == False
+assert bool(1) == True
+assert bool([]) == False
+assert bool("abc") == True
+assert bool([1,2]) == True
+assert bool('') == False
+
 # generate assert test for str
 
 assert 'testing' == 'test' + 'ing'