Commit 30e7d45b authored by Kevin Modzelewski's avatar Kevin Modzelewski

Support the callable() function

parent 0d2a3b1c
......@@ -673,6 +673,12 @@ Box* eval(Box* code) {
return runEval(static_cast<BoxedString*>(code)->s.c_str(), locals, module);
}
static Box* callable(Box* obj) {
Box* r = PyBool_FromLong((long)PyCallable_Check(obj));
checkAndThrowCAPIException();
return r;
}
BoxedClass* notimplemented_cls;
BoxedModule* builtins_module;
......@@ -1146,6 +1152,8 @@ void setupBuiltins() {
builtins_module->giveAttr(
"eval", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)eval, UNKNOWN, 1, 0, false, false), "eval"));
builtins_module->giveAttr("callable",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)callable, UNKNOWN, 1), "callable"));
BoxedClass* buffer_cls = BoxedHeapClass::create(type_cls, object_cls, NULL, 0, 0, sizeof(Box), false, "buffer");
builtins_module->giveAttr("buffer", buffer_cls);
......
......@@ -92,3 +92,7 @@ print l
print bytes
print bytes is str
print repr(b'1234')
print callable(1)
print callable(int)
print callable(lambda: 1)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment