1. utku karatas
  2. delPython

Commits

utku  committed 11336da

a few more tests pass

  • Participants
  • Parent commits 25f98ff
  • Branches default

Comments (0)

Files changed (2)

File delPython.pas

View file
     procedure LoadDll(const DllPath: string); // raise exc. on errors
   end;
 
-  TLitePython = class(TPythonDLL)
+  TPythonEngine = class(TPythonDLL)
   private
     class function ConvertToPAnsiChar(const S: string): PAnsiChar;
     procedure generic_event;
   end;
 
 var
-  python: TLitePython;
+  python: TPythonEngine;
 
 implementation
 
 { -------------------------------------------------------------------------------------------------------------------- }
 { TLitePython }
 
-constructor TLitePython.Create;
+constructor TPythonEngine.Create;
 begin
   inherited;
   fPythonType_DelphiType_Map := TDictionary<PPyTypeObject, TClass>.Create;
 end;
 
-destructor TLitePython.Destroy;
+destructor TPythonEngine.Destroy;
 begin
   FreeAndNil(fPythonType_DelphiType_Map);
   inherited;
   gKeepStrings: array of AnsiString; // will leak
 
 { Convert the given Unicode value S to ANSI and increase the ref. count so that returned pointer stays valid }
-class function TLitePython.ConvertToPAnsiChar(const S: string): PAnsiChar;
+class function TPythonEngine.ConvertToPAnsiChar(const S: string): PAnsiChar;
 var temp: AnsiString;
 begin
   SetLength(gKeepStrings, Length(gKeepStrings) + 1);
       Insert(#10, result, length(result)+1 );
   end;
 
-procedure TLitePython.Exec(const Code: string);
+procedure TPythonEngine.Exec(const Code: string);
 var
   ansiCode: AnsiString;
   pyobj: PPyObject;
   Py_XDECREF(pyobj);
 end;
 
-function TLitePython.Eval(const Code: string): PPyObject;
+function TPythonEngine.Eval(const Code: string): PPyObject;
 var
   ansiCode: AnsiString;
   m, _locals, _globals: PPyObject;
   //Py_XDECREF(Result);
 end;
 
-function TLitePython.EvalStr(const Code: string): string;
+function TPythonEngine.EvalStr(const Code: string): string;
 begin
   Result := PyObjectAsString(Eval(Code));
 end;
 
   function ValueFromPyobject(pyobj: PPyObject): TValue; forward;
 
-  procedure TLitePython.generic_event;
+  procedure TPythonEngine.generic_event;
   begin
     showmessage('TLitePython.generic_event');
   end;
     end;
   end;
 
-procedure TLitePython.Wrap(aClass: TClass);
+procedure TPythonEngine.Wrap(aClass: TClass);
 begin
   CreatePythonType(aClass);
 end;
 
-function TLitePython.WrapMethodCall(anActualObj: TObject; LMethod: string): PPyObject;
+function TPythonEngine.WrapMethodCall(anActualObj: TObject; LMethod: string): PPyObject;
 begin
   // todo: need a registry
   // create a facade call object
   Py_INCREF(Result);
 end;
 
-function TLitePython.WrapProperty(anActualObj: TObject; LProp: string): PPyObject;
+function TPythonEngine.WrapProperty(anActualObj: TObject; LProp: string): PPyObject;
 var
   LLProp: TRttiProperty;
   v: TValue;
   Py_INCREF(Result);
 end;
 
-function TLitePython.WrapValue(aValue: TValue): PPyObject;
+function TPythonEngine.WrapValue(aValue: TValue): PPyObject;
 begin
   Result := nil;
   case AValue.Kind of
-    tkUnknown: ;
+    tkUnknown: Result := Py_None;  // procedure calls return this
     tkInteger: Result := PyInt_FromLong(AValue.AsInteger);
     tkChar: ;
     tkEnumeration: ;
   if Result <> nil then
     Py_INCREF(Result)
   else
-    raise Exception.Create('xxx WrapValue fail');
+    raise Exception.CreateFmt('xxx WrapValue fail for %s (%d)', [aValue.ToString, Integer(aValue.Kind)]);
 end;
 
-procedure TLitePython.CreateModule(aModuleName: ansistring);
+procedure TPythonEngine.CreateModule(aModuleName: ansistring);
 
   function MethodDefs(Count: integer): PPyMethodDef; //xxx
     begin
     Raise EPythonError.Create('Error initing module ' + aModuleName);
 end;
 
-procedure TLitePython.DeclareGlobal(const NameInPython: string; DelphiEntity: TObject);
+procedure TPythonEngine.DeclareGlobal(const NameInPython: string; DelphiEntity: TObject);
 var
   Result: PPyObjectPuppet;
   typ: PPyTypeObject;
 end;
 
 initialization
-  python := TLitePython.Create;
+  python := TPythonEngine.Create;
 finalization
   python.Free;
 end.

File demo/persist.txt

View file
 Exception while evaluating "o.Objects[0]" Details: "xxx field lookup failed TStringList.Objects"
 Exception while evaluating "o.Objects[1]" Details: "xxx field lookup failed TStringList.Objects"
 Exception while evaluating "o.Objects[2]" Details: "xxx field lookup failed TStringList.Objects"
-Exception while evaluating "o.Clear()" Details: "xxx WrapValue fail"
+Expected "" but found "None" for o.Clear()
+Expected "" but found "None" for o.Delete(1)
+Exception while evaluating "o[0]" Details: "Python raised error <type 'exceptions.TypeError'> with 'S' object is unsubscriptable"
+Exception while evaluating "o[1]" Details: "Python raised error <type 'exceptions.TypeError'> with 'S' object is unsubscriptable"
+Exception while evaluating "o.Strings[0]" Details: "xxx field lookup failed TStringList.Strings"
+Exception while evaluating "o.Strings[1]" Details: "xxx field lookup failed TStringList.Strings"
+Exception while evaluating "o.Objects[0]" Details: "xxx field lookup failed TStringList.Objects"
+Exception while evaluating "o.Objects[1]" Details: "xxx field lookup failed TStringList.Objects"
+Expected "" but found "None" for o.Exchange(0, 1)
+Exception while evaluating "o[0]" Details: "Python raised error <type 'exceptions.TypeError'> with 'I' object is unsubscriptable"
+Exception while evaluating "o[1]" Details: "Python raised error <type 'exceptions.TypeError'> with 'I' object is unsubscriptable"
+Exception while evaluating "o.Find("1",i)" Details: "xxx WrapValue fail for True (3)"
+Exception while evaluating "o.Find("2",i)" Details: "xxx WrapValue fail for True (3)"
+Expected "1" but found "0" for i
+Exception while evaluating "o.Find("2",i)" Details: "xxx WrapValue fail for True (3)"
+Expected "2" but found "0" for i
+Exception while evaluating "o[0]" Details: "Python raised error <type 'exceptions.TypeError'> with 'S' object is unsubscriptable"
+Exception while evaluating "o[1]" Details: "Python raised error <type 'exceptions.TypeError'> with 'S' object is unsubscriptable"
+Exception while evaluating "o[2]" Details: "Python raised error <type 'exceptions.TypeError'> with 'S' object is unsubscriptable"