Anonymous avatar Anonymous committed 8be59b9

signature matching improvement

Comments (0)

Files changed (1)

 
     procedure DeclareClass(aClass: TClass);
     procedure DeclareGlobal(const VarNameInPython: string; DelphiEntity: TObject);
+    procedure DeclareEnum(anEnum: TValue);
+    procedure DeclareSet(aSet: TValue);
+
     function WrapMethodCall(anActualObj: TObject; LMethod: string): PPyObject;
     function WrapProperty(anActualObj: TObject; LProp: string): PPyObject;
     function WrapValue(aValue: TValue): PPyObject;
       end;
     end;
 
-      function TryMatchingSignature(const pythonParams: TValueArray; const delphiParams: TArray<TRttiParameter>): boolean;
-      var
-        i: Integer;
+    function TryMatchingSignature(const pythonParams: TValueArray; const delphiParams: TArray<TRttiParameter>): boolean;
+    var
+      i: Integer;
+    begin
+      Result := True;
+      if Length(delphiParams) = Length(pythonParams) then // exact param count match
       begin
-        Result := True;
-        if Length(delphiParams) = Length(pythonParams) then // exact param count match
+        for i := 0 to Length(delphiParams) - 1 do
         begin
-          for i := 0 to Length(delphiParams) - 1 do
+          Result :=
+              ((pythonParams[i].Kind in [tkString, tkUString, tkLString, tkWString]) and
+               (delphiParams[i].ParamType.TypeKind in [tkString, tkUString, tkLString, tkWString]))
+              or
+              (pythonParams[i].Kind = delphiParams[i].ParamType.TypeKind);
+
+//          // xxx if it's an ordinal type like a set well i don't care!
+//          if delphiParams[i].ParamType.TypeKind = tkSet then
+//          begin
+//            Result := True;
+//            delphiParams[i].ParamType.AsOrdinal.
+//            LArgs[i] := TValue.FromVariant(delphiParams[i].);
+//          end
+
+          if not Result then // doesn't match!
+            Exit(False);
+        end;
+      end
+      else
+      if Length(delphiParams) > Length(pythonParams) then
+      begin
+        for i := 0 to Length(delphiParams) - 1 do
+        begin
+
+          if i > Length(pythonParams)-1 then
           begin
-            Result :=
-                ((pythonParams[i].Kind in [tkString, tkUString, tkLString, tkWString]) and
-                 (delphiParams[i].ParamType.TypeKind in [tkString, tkUString, tkLString, tkWString]))
-                or
-                (pythonParams[i].Kind = delphiParams[i].ParamType.TypeKind);
+            // these arguments better be optional
+            //xxx if delphiParams[i].Flags is optional
+            CONTINUE;
+          end;
 
-            if not Result then // doesn't match!
-              Exit(False);
-          end;
+          Result :=
+              ((pythonParams[i].Kind in [tkString, tkUString, tkLString, tkWString]) and
+               (delphiParams[i].ParamType.TypeKind in [tkString, tkUString, tkLString, tkWString]))
+              or
+              (pythonParams[i].Kind = delphiParams[i].ParamType.TypeKind);
+
+          if not Result then // doesn't match!
+            Exit(False);
         end;
       end;
+    end;
 
     function FindRTTIMethodBasedOnSignature(const aMethodName: ansistring): TRttiMethod;
     var
   CreatePythonType(aClass);
 end;
 
+procedure TPythonEngine.DeclareGlobal(const VarNameInPython: string; DelphiEntity: TObject);
+var
+  Result: PPyObjectPuppet;
+  typ: PPyTypeObject;
+begin
+  // first create a type object for the class of DelphiEntity.
+  //todo: xxx cache these types!
+  typ := CreatePythonType(DelphiEntity.ClassType);
+
+  // now create a python object from that type
+  Result := PPyObjectPuppet( _PyObject_New(typ) );
+  PPyObjectPuppet(Result).actual_obj := DelphiEntity;
+  PyModule_AddObject(python.fModule, ConvertToPAnsiChar(VarNameInPython), PPyObject(Result));
+  Py_INCREF(PPyObject(Result));
+end;
+
+procedure TPythonEngine.DeclareSet(aSet: TValue);
+begin
+
+end;
+
+procedure TPythonEngine.DeclareEnum(anEnum: TValue);
+begin
+
+end;
+
 function TPythonEngine.WrapMethodCall(anActualObj: TObject; LMethod: string): PPyObject;
 begin
   // todo: need a registry
     Raise EPythonError.Create('Error initing module ' + aModuleName);
 end;
 
-procedure TPythonEngine.DeclareGlobal(const VarNameInPython: string; DelphiEntity: TObject);
-var
-  Result: PPyObjectPuppet;
-  typ: PPyTypeObject;
-begin
-  // first create a type object for the class of DelphiEntity.
-  //todo: xxx cache these types!
-  typ := CreatePythonType(DelphiEntity.ClassType);
-
-  // now create a python object from that type
-  Result := PPyObjectPuppet( _PyObject_New(typ) );
-  PPyObjectPuppet(Result).actual_obj := DelphiEntity;
-  PyModule_AddObject(python.fModule, ConvertToPAnsiChar(VarNameInPython), PPyObject(Result));
-  Py_INCREF(PPyObject(Result));
-end;
-
 procedure TPythonEngine.FixProp;
 
   function KeyFromValue: PPyTypeObject;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.