From f530d8d11178abcb1750028bea2b9a8fc215cc17 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 6 Mar 2025 19:53:45 +0800 Subject: [PATCH] Update modules.c --- src/public/modules.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/public/modules.c b/src/public/modules.c index c07e9be6..9c65134b 100644 --- a/src/public/modules.c +++ b/src/public/modules.c @@ -804,11 +804,27 @@ static bool function__name__(int argc, py_Ref argv) { return true; } +static bool function__repr__(int argc, py_Ref argv) { + // + PY_CHECK_ARGC(1); + Function* func = py_touserdata(py_arg(0)); + c11_sbuf buf; + c11_sbuf__ctor(&buf); + c11_sbuf__write_cstr(&buf, "decl->code.name->data); + c11_sbuf__write_cstr(&buf, " at "); + c11_sbuf__write_ptr(&buf, func); + c11_sbuf__write_char(&buf, '>'); + c11_sbuf__py_submit(&buf, py_retval()); + return true; +} + py_Type pk_function__register() { py_Type type = pk_newtype("function", tp_object, NULL, (void (*)(void*))Function__dtor, false, true); py_bindproperty(type, "__doc__", function__doc__, NULL); py_bindproperty(type, "__name__", function__name__, NULL); + py_bindmagic(type, __repr__, function__repr__); return type; }