From 3ddeac241a99ce854a2e28ca2e9fab7f3f28cc1b Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 21 Nov 2022 20:19:04 +0800 Subject: [PATCH] some fix --- src/pocketpy.h | 11 +++++++++-- tests/pointer.py | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pocketpy.h b/src/pocketpy.h index a3cdbda9..bcafbc21 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -556,15 +556,22 @@ void __initializeBuiltinFunctions(VM* _vm) { }); _vm->bindMethod("_native_function", "__call__", [](VM* vm, const pkpy::ArgList& args) { - vm->__checkType(args[0], vm->_tp_native_function); const _CppFunc& _self = vm->PyNativeFunction_AS_C(args[0]); return _self(vm, args.subList(1)); }); _vm->bindMethod("function", "__call__", [](VM* vm, const pkpy::ArgList& args) { - vm->__checkType(args[0], vm->_tp_function); return vm->call(args[0], args.subList(1)); }); + + _vm->bindMethod("_bounded_method", "__call__", [](VM* vm, const pkpy::ArgList& args) { + vm->__checkType(args[0], vm->_tp_bounded_method); + const _BoundedMethod& _self = vm->PyBoundedMethod_AS_C(args[0]); + pkpy::ArgList newArgs(args.size()); + newArgs[0] = _self.obj; + for(int i = 1; i < args.size(); i++) newArgs[i] = args[i]; + return vm->call(_self.method, newArgs); + }); } #include "builtins.h" diff --git a/tests/pointer.py b/tests/pointer.py index 311f7783..1c287eff 100644 --- a/tests/pointer.py +++ b/tests/pointer.py @@ -28,7 +28,9 @@ def add(a, b): p = &add assert p->__call__(1, 2) == 3 +assert p->__call__.__call__.__call__.__call__.__call__(3, 4) == 7 fun = lambda :6 p = &fun -assert p->__call__() == 6 \ No newline at end of file +assert p->__call__() == 6 +assert p->__call__.__call__.__call__.__call__.__call__() == 6 \ No newline at end of file