Trying to make a Python support plugin

A place where plug-in developers can share their knowledge and experience.
Post Reply
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Post by jonib »

So I am tired to wait for someone to add Python support for Far manager, so I'll try myself.

I did some basic courses in C/C++ about 20 years ago and I really never liked to code in it. So I'm rusty/have no idea what I'm doing.

So my first problem I tried to add the "Python.h" header to the "HelloWorld" example plugin, and got some error that I can't figure out:

Code: Select all

making depends for PythonFAR.cpp
compiling PythonFAR.cpp
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:3:
d:\mingw\include\ctype.h: In function 'int isdigit(int)':
d:\mingw\include\ctype.h:157:42: error: redefinition of 'int isdigit(int)'
 __CRT_INLINE int __cdecl __MINGW_NOTHROW isdigit(int c) {return __ISCTYPE(c, _DIGIT);}
                                          ^
In file included from PythonFAR.cpp:1:0:
../common/CRT/crt.hpp:95:24: error: 'int isdigit(int)' previously defined here
   __inline int __cdecl isdigit(int c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:3:
d:\mingw\include\ctype.h: In function 'int isspace(int)':
d:\mingw\include\ctype.h:162:42: error: redefinition of 'int isspace(int)'
 __CRT_INLINE int __cdecl __MINGW_NOTHROW isspace(int c) {return __ISCTYPE(c, _SPACE);}
                                          ^
In file included from PythonFAR.cpp:1:0:
../common/CRT/crt.hpp:105:24: error: 'int isspace(int)' previously defined here
   __inline int __cdecl isspace(int c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:3:
d:\mingw\include\ctype.h: In function 'int isxdigit(int)':
d:\mingw\include\ctype.h:164:42: error: redefinition of 'int isxdigit(int)'
 __CRT_INLINE int __cdecl __MINGW_NOTHROW isxdigit(int c) {return __ISCTYPE(c, _HEX);}
                                          ^
In file included from PythonFAR.cpp:1:0:
../common/CRT/crt.hpp:115:24: error: 'int isxdigit(int)' previously defined here
   __inline int __cdecl isxdigit(int c)
                        ^
../makefile_gcc_target_inc:18: recipe for target 'final.32W.gcc/obj/PythonFAR.o' failed
mingw32-make.EXE: *** [final.32W.gcc/obj/PythonFAR.o] Error 1
Apperently some functions are declared multiple times and I have no idea how to handle it?

Bonus question: How do I specify where the compiler searches for the .h files as I need to specify the full path for the Python.h file.

jonib
Last edited by jonib on Thu 01 Jan, 1970 01:00, edited 0 times in total.
Reason: Removed special decoration (icon)
User avatar
DrKnS
Posts: 6114
Joined: Thu 04 Aug, 2005 06:44
Location: Kyiv
Has thanked: 12 times
Been thanked: 426 times

Trying to make a Python support plugin

Post by DrKnS »

1. Add the following lines
NEEDENTRY = 1
NEEDDEFLIB = 1
EXCLUDECRT = 1
to makefile_gcc before the first "include" entry.

2. Look for "-I $(COMMON)" in plugins\makefile_gcc_def_inc and add "-I your_python_path" there.
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

Trying to make a Python support plugin

Post by Shmuel »

jonib, just in case you didn't hear about it: there is a framework for writing Far Manager plugins in Lua language.
See %FARHOME%\Encyclopedia\luafar_manual.chm.
Also, many tasks you may want to accomplish via plugins can be done with Lua macros (even easier than with plugins).
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Post by jonib »

DrKnS wrote: 1. Add the following lines
to makefile_gcc before the first "include" entry.
Thanks, but that didn't help I get the same error still. Damn I'm starting to feel stupid when I can't even get the basic stuff to work. :?
2. Look for "-I $(COMMON)" in plugins\makefile_gcc_def_inc and add "-I your_python_path" there.
OK.

jonib
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Post by jonib »

Shmuel wrote: jonib, just in case you didn't hear about it: there is a framework for writing Far Manager plugins in Lua language.
See %FARHOME%\Encyclopedia\luafar_manual.chm.
Hmm, whats this, it's is you helping me convert a macro to LUA. :)
Also, many tasks you may want to accomplish via plugins can be done with Lua macros (even easier than with plugins).
Well I started a project in LUA that I though would be fairly simple, so started to learn what I needed but then I discovered that it was not possible to get both the stdout and stderror redirected from a program in LUA. As I was trying to make a front-end to a command-line program I needed all output from it.

Is it possible to have stdout and stderror redirected in LUA now? As far as I know that is possible in Python.

And basically I didn't really like the syntax of LUA and I want to use Python in FAR as I have to use it in other projects anyway.

jonib
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

Trying to make a Python support plugin

Post by Shmuel »

jonib wrote: Is it possible to have stdout and stderror redirected in LUA now?
I don't know but I'd be surprised if it was not the case.
jonib wrote: And basically I didn't really like the syntax of LUA and I want to use Python in FAR as I have to use it in other projects anyway.
Good luck.
Last edited by Shmuel on Sun 04 Oct, 2015 11:44, edited 1 time in total.
User avatar
HaRT
Moderator
Posts: 10822
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Trying to make a Python support plugin

Post by HaRT »

jonib wrote: I didn't really like the syntax of LUA
There's also another mature framework for creating Far plugins in a managed language: FarNet. It has rich infrastructure, many good examples and an active author.
Фар есть инструмент, а не нянька. © 2009 DrKnS
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Post by jonib »

HaRT wrote:
jonib wrote: I didn't really like the syntax of LUA
There's also another mature framework for creating Far plugins in a managed language: FarNet. It has rich infrastructure, many good examples and an active author.
I know of it, but unless it supports Python I'm not interested at this time. so please no more unrelated to Python suggestions.

jonib
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Post by jonib »

So I did some more reading and apparently the Python.h file needs to be imported first, but that just gives me more errors:

Code: Select all

making depends for PythonFAR.cpp
compiling PythonFAR.cpp
In file included from PythonFAR.cpp:2:0:
../common/CRT/crt.hpp: In function 'int isdigit(int)':
../common/CRT/crt.hpp:95:24: error: redefinition of 'int isdigit(int)'
   __inline int __cdecl isdigit(int c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:1:
d:\mingw\include\ctype.h:157:42: error: 'int isdigit(int)' previously defined here
 __CRT_INLINE int __cdecl __MINGW_NOTHROW isdigit(int c) {return __ISCTYPE(c, _DIGIT);}
                                          ^
In file included from PythonFAR.cpp:2:0:
../common/CRT/crt.hpp: In function 'int iswdigit(wint_t)':
../common/CRT/crt.hpp:100:24: error: redefinition of 'int iswdigit(wint_t)'
   __inline int __cdecl iswdigit(wint_t c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:1:
d:\mingw\include\ctype.h:228:42: error: 'int iswdigit(wint_t)' previously defined here
 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));}
                                          ^
In file included from PythonFAR.cpp:2:0:
../common/CRT/crt.hpp: In function 'int isspace(int)':
../common/CRT/crt.hpp:105:24: error: redefinition of 'int isspace(int)'
   __inline int __cdecl isspace(int c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:1:
d:\mingw\include\ctype.h:162:42: error: 'int isspace(int)' previously defined here
 __CRT_INLINE int __cdecl __MINGW_NOTHROW isspace(int c) {return __ISCTYPE(c, _SPACE);}
                                          ^
In file included from PythonFAR.cpp:2:0:
../common/CRT/crt.hpp: In function 'int iswspace(wint_t)':
../common/CRT/crt.hpp:110:24: error: redefinition of 'int iswspace(wint_t)'
   __inline int __cdecl iswspace(wint_t c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:1:
d:\mingw\include\ctype.h:233:42: error: 'int iswspace(wint_t)' previously defined here
 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswspace(wint_t wc) {return (iswctype(wc,_SPACE));}
                                          ^
In file included from PythonFAR.cpp:2:0:
../common/CRT/crt.hpp: In function 'int isxdigit(int)':
../common/CRT/crt.hpp:115:24: error: redefinition of 'int isxdigit(int)'
   __inline int __cdecl isxdigit(int c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:1:
d:\mingw\include\ctype.h:164:42: error: 'int isxdigit(int)' previously defined here
 __CRT_INLINE int __cdecl __MINGW_NOTHROW isxdigit(int c) {return __ISCTYPE(c, _HEX);}
                                          ^
In file included from PythonFAR.cpp:2:0:
../common/CRT/crt.hpp: In function 'int iswxdigit(wint_t)':
../common/CRT/crt.hpp:120:24: error: redefinition of 'int iswxdigit(wint_t)'
   __inline int __cdecl iswxdigit(wint_t c)
                        ^
In file included from /Python27/include/unicodeobject.h:57:0,
                 from /Python27/include/Python.h:85,
                 from PythonFAR.cpp:1:
d:\mingw\include\ctype.h:235:42: error: 'int iswxdigit(wint_t)' previously defined here
 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));}
                                          ^
../makefile_gcc_target_inc:18: recipe for target 'final.32W.gcc/obj/PythonFAR.o' failed
mingw32-make.EXE: *** [final.32W.gcc/obj/PythonFAR.o] Error 1
And I can't find any hints how I'm supposed to handle them.

jonib
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Post by jonib »

So after reading the Internet twice and trying all kinds of stuff and not having any luck, I was about to give up.

So I figured I would remove the duplicate declarations from crt.hpp that didn't work, just other errors.
Then I tried to remove them from ctype.h and that worked, I was able to compile and get the Python code working in a plugin from FAR. :Yahoo!:
But that seemed like the wrong and too hackish way to solve it. So when looking in luafar sources I discovered it didn't use the crt.hpp, I assumed it was important for a plugin but apparently not.

So I removed the crt import and I only needed to copy a ARRAYSIZE define, and now I finally can move on with actually working on the Python support in the plugin.

Damn, too much wasted time for a simple ARRAYSIZE define. :facepalm:

Hopefully there are no more unnecessary roadblocks anymore. :evil:

jonib
User avatar
techie
Posts: 795
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 35 times
Been thanked: 6 times

Trying to make a Python support plugin

Post by techie »

There is a usable implementation of Python plugin in Russian side of the board http://forum.farmanager.com/viewtopic.php?f=8&t=9998
jonib
Posts: 73
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Post by jonib »

techie wrote: There is a usable implementation of Python plugin in Russian side of the board http://forum.farmanager.com/viewtopic.php?f=8&t=9998
That's kinda old news. You even posted in the same thread on the same day. :)

I just wish I knew that there was a better interface before I put in a lot of time in the implementation I was working on, as I kinda lost most of my motivation working on this project. :cry:

jonib
Last edited by jonib on Fri 28 Apr, 2017 01:04, edited 1 time in total.
User avatar
techie
Posts: 795
Joined: Mon 03 Oct, 2005 22:42
Has thanked: 35 times
Been thanked: 6 times

Trying to make a Python support plugin

Post by techie »

Yes. Just needed to revisit the thing and Google showed me this result first. `pygin` still needs a lot of polishing.
Post Reply

Return to “Plug-In Developers”