mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
some fix
This commit is contained in:
parent
4c4a7fb471
commit
3ddeac241a
@ -556,15 +556,22 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindMethod("_native_function", "__call__", [](VM* vm, const pkpy::ArgList& args) {
|
_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]);
|
const _CppFunc& _self = vm->PyNativeFunction_AS_C(args[0]);
|
||||||
return _self(vm, args.subList(1));
|
return _self(vm, args.subList(1));
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindMethod("function", "__call__", [](VM* vm, const pkpy::ArgList& args) {
|
_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));
|
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"
|
#include "builtins.h"
|
||||||
|
@ -28,7 +28,9 @@ def add(a, b):
|
|||||||
|
|
||||||
p = &add
|
p = &add
|
||||||
assert p->__call__(1, 2) == 3
|
assert p->__call__(1, 2) == 3
|
||||||
|
assert p->__call__.__call__.__call__.__call__.__call__(3, 4) == 7
|
||||||
|
|
||||||
fun = lambda :6
|
fun = lambda :6
|
||||||
p = &fun
|
p = &fun
|
||||||
assert p->__call__() == 6
|
assert p->__call__() == 6
|
||||||
|
assert p->__call__.__call__.__call__.__call__.__call__() == 6
|
Loading…
x
Reference in New Issue
Block a user