Results 1 to 9 of 9

Thread: Python scripting in delphi

  1. #1

    Python scripting in delphi

    im a python addict and pascal lover, and i'm currently studding the python API to start a project (i already did some tests).

    The project will be started from zero expect the dynamic loading of python dll methods taken from "Python for Delphi".

    I did not find a good name for the project, any suggestion is welcome.


    (sorry for english errors)
    From brazil (:

    Pascal pownz!

  2. #2

    Python scripting in delphi

    what is the idea behind your project?
    Integrating python as an scripting language inside delphi?
    Does not the mentioned python for delphi already do that?
    http://www.atug.com/andypatterns/pythonDelphiTalk.htm
    http://membres.lycos.fr/marat/delphi/python.htm
    http://3das.noeska.com - create adventure games without programming

  3. #3

    Python scripting in delphi

    easy , simple, fast integration, i'm currently using python for delphi but its too strange -.-' it really need an simplification and redesign (at least for me)

    edit: it takes 10 lines to make a work of 4
    From brazil (:

    Pascal pownz!

  4. #4

    Python scripting in delphi

    i already did some work, removed TPythonEngine, defined some const's,

    what features will be interesting to have?
    From brazil (:

    Pascal pownz!

  5. #5

    Python scripting in delphi

    I'm having a problem with assembler here,

    [pascal]function PyArg_Parse(args: PPyObject; format: PChar;
    argp: array of Pointer): Integer; cdecl;
    begin
    {$IFDEF DELPHI6_OR_HIGHER}
    Result := 0;
    { Do not optimize this to a "pure" assembler routine, because such
    a routine does not copy the array arguments in the prologue code }
    asm
    lea edx, format
    push [edx]

    sub edx, TYPE PChar
    push [edx]

    mov eax, Self
    mov eax, [eax].DLL_PyArg_Parse
    call eax

    pop edx
    pop edx
    mov Result, eax
    end;
    {$ELSE}
    Result := DLL_PyArg_Parse(args, format);
    {$ENDIF}
    end;[/pascal]

    I don't know much assembly, but i think the problem is that the assembly is trying to call DLL_PyArg_Parse as a class function (as in Python for Delphi original code), but now DLL_PyArg_Parse is a normal procedure loaded from python dll.

    How can i solve the problem?


    sorry for the english ops:


    edit: same problem on some other functions, i really need help here
    From brazil (:

    Pascal pownz!

  6. #6

    Python scripting in delphi

    I don't think the code makes very much sense but I ofcourse haven't seen most of it. Would this be better?
    [pascal]function PyArg_Parse(args: PPyObject; format: PChar;
    argp: array of Pointer): Integer; cdecl;
    begin
    {$IFDEF DELPHI6_OR_HIGHER}
    Result := 0;
    { Do not optimize this to a "pure" assembler routine, because such
    a routine does not copy the array arguments in the prologue code }
    asm
    lea edx, format
    push [edx]

    sub edx, TYPE PChar
    push [edx]

    mov eax, DLL_PyArg_Parse
    call eax

    pop edx
    pop edx
    mov Result, eax
    end;
    {$ELSE}
    Result := DLL_PyArg_Parse(args, format);
    {$ENDIF}
    end;[/pascal]
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7

    Python scripting in delphi

    it works and now i know how fix another problems, thanks!
    From brazil (:

    Pascal pownz!

  8. #8

    Python scripting in delphi

    the current test

    [pascal]program Project1;

    {$APPTYPE CONSOLE}

    uses
    FastMM4,
    SysUtils,
    Classes,
    Math,
    python,
    PythonEx;

    function testfunc( Self,args : PPyObject): PPyObject; cdecl;
    var
    s : PChar;
    begin
    PyArg_ParseTuple(args,argstring,[@s]);
    Result := Py_BuildValue(argstring+argint,[s,Length(s)]);
    end;

    function testfunc2( Self,args : PPyObject): PPyObject; cdecl;
    var
    s : PChar;
    begin
    PyArg_ParseTuple(args,argstring,[@s]);
    Result := Py_BuildValue(argstring+argchar,[s,s[0]]);
    end;

    var
    i : single;
    n : single;

    begin
    Py_Initialize;

    n := DegToRad(359);

    Py_RegisterMethod('test','test',testfunc);
    Py_RegisterMethod('test2','test2',testfunc2);

    PyRun_SimpleString('import test; a , b = test.test("=.= im getting crazy with assembly"); print "length of ''%s'' is %s" % (a , b)');
    PyRun_SimpleString('import test2; a , b = test2.test2("delphi"); print "first char of ''%s'' is %s" % (a , b)');

    Py_RunMethod('math','cos',argsingle,[n],argsingle,[@i]);

    Writeln('cos of 359 degrees = ',floattostr(i));
    Py_Finalize;
    Readln;
    end.[/pascal]

    From brazil (:

    Pascal pownz!

  9. #9

    Python scripting in delphi

    looks like that the website has an rollback :?
    From brazil (:

    Pascal pownz!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •