This commit is contained in:
blueloveTH 2022-11-21 20:19:04 +08:00
parent 4c4a7fb471
commit 3ddeac241a
2 changed files with 12 additions and 3 deletions

View File

@ -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"

View File

@ -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
assert p->__call__() == 6
assert p->__call__.__call__.__call__.__call__.__call__() == 6