Community
    • Login

    Perl subroutine calltips - with PythonScript

    Scheduled Pinned Locked Moved General Discussion
    52 Posts 4 Posters 3.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PeterJonesP
      PeterJones @Ekopalypse
      last edited by

      @Ekopalypse ,

      I don’t know the guts (I was going to say “very well”, but that would be understatement; I think the unqualified comes closest to the truth), but perldoc perlembed shows how to embed the perl interpreter into an application, and takes a bit about perl_parse and perl_run.

      But I wouldn’t know where to begin on using those functions, or even the output of -MO=Deparse, and implementing a stronger version of what @Michael-Vincent has shown. And even if I did, I already have my huge project of the Win32::Mechanize::NotepadPlusPlus which isn’t quite to where I want it, and the PerlScript plugin wrapper that I haven’t even started writing yet – and I cannot take on another big project until I’ve got those to a reasonably-functional level.

      EkopalypseE 1 Reply Last reply Reply Quote 1
      • EkopalypseE
        Ekopalypse @PeterJones
        last edited by

        @PeterJones

        no problem … I was curious and played already a bit with it.
        If I’m right, then 5 lines of pythonscript might give you an embedded perl.

        PeterJonesP 1 Reply Last reply Reply Quote 1
        • PeterJonesP
          PeterJones @Ekopalypse
          last edited by

          @Ekopalypse said in Perl subroutine calltips - with PythonScript:

          5 lines of pythonscript might give you an embedded perl.

          Oh, the irony. :-)

          EkopalypseE 2 Replies Last reply Reply Quote 1
          • EkopalypseE
            Ekopalypse @PeterJones
            last edited by

            @PeterJones

            :-D

            this seems to do something, not sure what but it doesn’t crash my npp … so … still crossing fingers ;-)

            from ctypes import CDLL, POINTER, c_int, c_char_p
            
            perllib = CDLL(r'd:\perl\bin\perl531.dll')
            
            ["-le", "print 'something \"with\" quotes';"]
            
            perllib.RunPerl.restype = c_int
            perllib.RunPerl.argtypes = c_int, POINTER(c_char_p), POINTER(c_char_p)
            args = (c_char_p * 2)(b"-le", b"print 'something \"with\" quotes';")
            print(perllib.RunPerl(len(args),args, None))
            
            1 Reply Last reply Reply Quote 2
            • EkopalypseE
              Ekopalypse @PeterJones
              last edited by Ekopalypse

              @PeterJones

              can you give me a qiuck “Win32::Mechanize::NotepadPlusPlus for dummies äh ekopalypses” to open a new npp buffer?

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @Ekopalypse
                last edited by

                @Ekopalypse ,

                From the command line, to just open a new file tab:

                perl -le "use Win32::Mechanize::NotepadPlusPlus qw/:main/; notepad->newFile();"
                

                If you want to call a script.pl instead,

                use Win32::Mechanize::NotepadPlusPlus qw/:main/; 
                notepad->newFile();
                

                But that assumes that perl has the right @INC (include library paths) to find Win32::Mechanize::NotepadPlusPlus.

                EkopalypseE 1 Reply Last reply Reply Quote 2
                • EkopalypseE
                  Ekopalypse @PeterJones
                  last edited by

                  @PeterJones

                  D:\perl\bin>perl D:\temp\perl\Win32-Mechanize-NotepadPlusPlus-0.005\Makefile.PL
                  Could not open 'lib/Win32/Mechanize/NotepadPlusPlus.pm': No such file or directory at D:/perl/lib/ExtUtils/MM_Unix.pm line 2973.
                  

                  Now you know why I said “… for ekopalypses” ;-)

                  PeterJonesP 2 Replies Last reply Reply Quote 1
                  • EkopalypseE
                    Ekopalypse
                    last edited by

                    hah, it is the other way around … from within the source call perl …

                    1 Reply Last reply Reply Quote 1
                    • PeterJonesP
                      PeterJones @Ekopalypse
                      last edited by

                      @Ekopalypse said in Perl subroutine calltips - with PythonScript:

                      @PeterJones

                      D:\perl\bin>perl D:\temp\perl\Win32-Mechanize-NotepadPlusPlus-0.005\Makefile.PL
                      Could not open 'lib/Win32/Mechanize/NotepadPlusPlus.pm': No such file or directory at D:/perl/lib/ExtUtils/MM_Unix.pm line 2973.
                      

                      For the installation, you need to be in the D:\temp\perl\Win32-Mechanize-NotepadPlusPlus-0.005\ directory, and run d:\perl\bin\perl Makefile.PL instead: you need to be in the same directory as the Makefile.PL, so that the relative paths are all correct.

                      EkopalypseE 1 Reply Last reply Reply Quote 2
                      • EkopalypseE
                        Ekopalypse @PeterJones
                        last edited by

                        @PeterJones

                        and then I used nmake to create the pm’s.
                        I’ve copied the resulting Win32 to …/perl/lib/
                        but now I get Can't locate Win32/API.pm in @INC (you may need to install the Win32::API module) (@INC contains: d:/perl/site/lib d:/perl/lib) at d:/perl/lib/Win32/Mechanize/NotepadPlusPlus/Notepad.pm line 9.

                        1 Reply Last reply Reply Quote 1
                        • PeterJonesP
                          PeterJones @Ekopalypse
                          last edited by

                          @Ekopalypse ,

                          The other thing I realized: you probably won’t have all the prerequisite modules installed. I normally use the cpanm utility, which distributes with strawberry perl, and that automatically downloads and installs prereqs before the module you’re trying to install. Without such a tool (and if you built your own perl, which I think you did to get the DLL), I don’t know that you have that.

                          I think the make process will tell you what prereqs you’re missing … but it’s been a long time since I’ve done a complicated manual install of a module.

                          Oh, yep, there, you posted the error while I was typing. You’re going to have to install at least Win32::API first… doing that manually is a pain.

                          When you built your own perl, did you at least get cpan, if not cpanm? I think one or both would be in the same directory as perl.exe… if you have cpanm, just do cpanm Win32::Mechanize::NotepadPlusPlus, and everything should work. If you have just cpan, I forget whether it handles prereqs; try cpan Win32::Mechanize::NotepadPlusPlus; if that’s not sufficient, do the missing prereqs one at a time with the cpan client. If you have neither… um… That’s going to be tough.

                          Michael VincentM 1 Reply Last reply Reply Quote 1
                          • Michael VincentM
                            Michael Vincent @PeterJones
                            last edited by

                            @PeterJones said in Perl subroutine calltips - with PythonScript:

                            If you have just cpan, I forget whether it handles prereqs

                            I believe it does - I normally just use CPAN and it fetches what I need to build.

                            Cheers.

                            1 Reply Last reply Reply Quote 1
                            • EkopalypseE
                              Ekopalypse
                              last edited by

                              I have cpan and it keeps installing stuff - did I choose to install the world??

                              1 Reply Last reply Reply Quote 0
                              • EkopalypseE
                                Ekopalypse
                                last edited by

                                it does this now since ~10 minutes

                                1 Reply Last reply Reply Quote 0
                                • EkopalypseE
                                  Ekopalypse
                                  last edited by

                                  finished - but no Win32::API. started cpan Win32::API now.

                                  1 Reply Last reply Reply Quote 0
                                  • Michael VincentM
                                    Michael Vincent
                                    last edited by

                                    @Ekopalypse
                                    @PeterJones

                                    Is there a reason you build your own Perl? I have Strawberry 5.24 installed and doing this works:

                                    970a1b75-52c3-4044-b6aa-e253bb3e979c-image.png

                                    That’s @Ekopalypse script from above using my “system” Strawberry Perl 5.24 DLL (the Perl that has my Win32::Mechanize::NotepadPlusPlus and all my other stull installed on it). Not sure why it’s printing “9” in the PythonScript console - is that what it’s supposed to do? I thought I’d get that string "print something ...

                                    Cheers.

                                    EkopalypseE 1 Reply Last reply Reply Quote 1
                                    • EkopalypseE
                                      Ekopalypse @Michael Vincent
                                      last edited by Ekopalypse

                                      @Michael-Vincent

                                      I get also 9 and from the function it seems correct to return an int.
                                      See my previous post. RunPerl returns only an int. Not sure how to get the result (the print output), so far.

                                      Michael VincentM 1 Reply Last reply Reply Quote 1
                                      • Michael VincentM
                                        Michael Vincent @Ekopalypse
                                        last edited by

                                        @Ekopalypse said in Perl subroutine calltips - with PythonScript:

                                        I get also 9

                                        Oh, OK - great then. Seems I may be able to keep testing along without having to build a Perl and just use my Strawberry install.

                                        Cheers.

                                        EkopalypseE 1 Reply Last reply Reply Quote 1
                                        • EkopalypseE
                                          Ekopalypse @Michael Vincent
                                          last edited by

                                          @Michael-Vincent

                                          My Win32::API has been built but not installed because of failing tests I guess. Can you try the "use Win32::Mechanize::NotepadPlusPlus qw/:main/; notepad->newFile();" and see what happens?

                                          Michael VincentM 2 Replies Last reply Reply Quote 1
                                          • Michael VincentM
                                            Michael Vincent @Ekopalypse
                                            last edited by

                                            This post is deleted!
                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors