diff --git a/plugins/flutter/src/pocketpy.h b/plugins/flutter/src/pocketpy.h index 270b983d..53386107 100644 --- a/plugins/flutter/src/pocketpy.h +++ b/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"); diff --git a/plugins/godot/godot-cpp b/plugins/godot/godot-cpp index cb98c82a..f0c35d53 160000 --- a/plugins/godot/godot-cpp +++ b/plugins/godot/godot-cpp @@ -1 +1 @@ -Subproject commit cb98c82ac6dc5cf83cb107d1cbf3fc9219e296e4 +Subproject commit f0c35d535dca99b31b15100f82f48bc1becbca45 diff --git a/plugins/unity/com.bl.pocketpy/Plugins/iOS/pocketpy.h b/plugins/unity/com.bl.pocketpy/Plugins/iOS/pocketpy.h index 270b983d..53386107 100644 --- a/plugins/unity/com.bl.pocketpy/Plugins/iOS/pocketpy.h +++ b/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"); diff --git a/src/pocketpy.h b/src/pocketpy.h index 2cd2a36c..6361f7cc 100644 --- a/src/pocketpy.h +++ b/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"); diff --git a/tests/basic.py b/tests/basic.py index ca0c767f..de69b8af 100644 --- a/tests/basic.py +++ b/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'