Skip to content

Commit ba0565e

Browse files
authored
Merge pull request #62 from Embarcadero/docstrargs
Docstrargs
2 parents 61f3578 + daac872 commit ba0565e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Source/WrapDelphi.pas

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ TExposedMethodImplementation = class(TAbstractExposedMemberImplementation)
939939

940940
function VirtualMethodImplementation(): pointer;
941941

942+
class function MethodDocStr(const ARttiMethod: TRttiMethod): string;
942943
class function Methods_Wrapper(const ASelf, AArgs, AKeyWords: PPyObject): PPyObject; static; cdecl;
943944

944945
property MethodHandler: TExposedMethodHandler read FMethodHandler write FMethodHandler;
@@ -1138,6 +1139,42 @@ function TExposedMethodImplementation.GetDocString(): string;
11381139
Name, FRttiType.Name, NativeInt(Self)]);
11391140
end;
11401141

1142+
class function TExposedMethodImplementation.MethodDocStr
1143+
(const ARttiMethod: TRttiMethod): string;
1144+
const
1145+
METHOD_DOC_STR_PATTERN = '%s.%s(%s)';
1146+
var
1147+
LArgsStr: string;
1148+
LRttiParameter: TRttiParameter;
1149+
begin
1150+
if (Length(ARttiMethod.GetParameters) = 0) then
1151+
Exit(String.Empty);
1152+
1153+
LArgsStr := String.Empty;
1154+
for LRttiParameter in ARttiMethod.GetParameters do begin
1155+
if not LArgsStr.IsEmpty then
1156+
LArgsStr := LArgsStr + ', ';
1157+
1158+
if not Assigned(LRttiParameter.ParamType) then
1159+
LArgsStr := LArgsStr + LRttiParameter.Name
1160+
else
1161+
LArgsStr := LArgsStr
1162+
+ LRttiParameter.Name
1163+
+ ': '
1164+
+ LRttiParameter.ParamType.Name.Replace('T', '', []);
1165+
end;
1166+
1167+
Result := String.Format(METHOD_DOC_STR_PATTERN, [
1168+
ARttiMethod.Parent.Name, ARttiMethod.Name, LArgsStr]);
1169+
1170+
if Assigned(ARttiMethod.ReturnType) then
1171+
Result := Result
1172+
+ ' -> '
1173+
+ ARttiMethod.ReturnType.Name.Replace('T', '', []);
1174+
1175+
Result := Result + #10;
1176+
end;
1177+
11411178
function TExposedMethodImplementation.VirtualMethodImplementation(): pointer;
11421179
var
11431180
LRttiCtx: TRttiContext;
@@ -3400,6 +3437,11 @@ class procedure TPyDelphiObject.ExposeMethods(const AClass: TClass;
34003437
LClass := LClass.ClassParent;
34013438
end;
34023439

3440+
//Build the DocStr including method args
3441+
LExposedMethod.DocString :=
3442+
AnsiString(TExposedMethodImplementation.MethodDocStr(LRttiMethod))
3443+
+ LExposedMethod.DocString;
3444+
34033445
//Adds the Python method
34043446
if LRttiMethod.IsStatic then
34053447
APythonType.AddStaticMethodWithKeywords(

0 commit comments

Comments
 (0)