Alexey-T / Python-for-Lazarus

Fork of Python4Delphi for Lazarus, supports Windows/Linux/macOS/*BSD/Solaris
MIT License
127 stars 42 forks source link

Support VarPyth.pas #32

Closed pyscripter closed 3 years ago

pyscripter commented 3 years ago

It appears that one of the important fpc bugs that was restricting the usefulness of VarPyth in Lazarus has been fixed. See https://bugs.freepascal.org/view.php?id=20849 https://bugs.freepascal.org/view.php?id=38429

It appears to have been fixed in Revision 48477. Do you have any clue as to when this revision will be included in Lazarus?

VarPyth is great. It makes using python in Pascal so much easier. Check https://github.com/pyscripter/python4delphi/blob/master/Tests/VarPythTest.pas to see what can be done with VarPyth. It would be nice to support VarPyth in your repo .

Also it would be nice to add the unit tests to your repo after adapting them for fpc, so we can easily test the parity between Delphi and Lazarus.

Alexey-T commented 3 years ago

It appears to have been fixed in Revision 48477. Do you have any clue as to when this revision will be included in Lazarus?

There is Laz forum with "announces" part, there you should ask to merge it https://forum.lazarus.freepascal.org/index.php?board=18.0 I guess

Alexey-T commented 3 years ago

VarPyth is great.

so do you suggest to add (copy) VarPyth.pas from your repo?

pyscripter commented 3 years ago

so do you suggest to add (copy) VarPyth.pas from your repo?

Yes

Alexey-T commented 3 years ago

I am adding it. I found compiling issue- had to change that function!

function TPythonData.GetAsWideString: UnicodeString;
begin
  if Assigned(PyObject) and GetPythonEngine.PyUnicode_Check(PyObject) then
    Result := GetPythonEngine.PyUnicode_AsWideString(PyObject) //////here
  else
    Result := UnicodeString(GetAsString);
end;
pyscripter commented 3 years ago

PyUnicode_AsWideString does not exist in my repo. I thought we had synced that.

These are the string conversions routines { String conversion } function PyUnicodeFromString(const AString : UnicodeString) : PPyObject; overload; function PyUnicodeFromString(const AString: AnsiString): PPyObject; overload; function PyUnicodeAsString( obj : PPyObject ) : UnicodeString; function PyUnicodeAsUTF8String( obj : PPyObject ) : RawByteString; function PyBytesAsAnsiString( obj : PPyObject ) : AnsiString;

The underscore _ is reserved for routines directly imported from the Python API.

PyUnicode_FromWideChar:function (const w:PWideChar; size:NativeInt):PPyObject; cdecl;
PyUnicode_FromString:function (s:PAnsiChar):PPyObject; cdecl;
PyUnicode_FromStringAndSize:function (s:PAnsiChar;i:NativeInt):PPyObject; cdecl;
PyUnicode_FromKindAndData:function (kind:integer;const buffer:pointer;size:NativeInt):PPyObject; cdecl;
PyUnicode_AsWideChar:function (unicode: PPyObject; w:PWideChar; size:NativeInt):integer; cdecl;
PyUnicode_AsUTF8:function (unicode: PPyObject):PAnsiChar; cdecl;
PyUnicode_AsUTF8AndSize:function (unicode: PPyObject; size: PNativeInt):PAnsiChar; cdecl;
Alexey-T commented 3 years ago

OK,solved it now: I didnt sync that before

pyscripter commented 3 years ago

OK,solved it now: I didnt sync that before

Great! How about adding the Unit tests as well at least those that apply MethodCallBackTest.pas, NumberServicesTest.pas and VarPythTest.pas and create an fpc testing project?

Alexey-T commented 3 years ago

Sorry, it's not simple for me.