Trying to make a Python support plugin

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

Trying to make a Python support plugin

Postby jonib » Sun 04 Oct, 2015 00:46

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 HaRT on Sun 04 Oct, 2015 15:15, edited 2 times in total.
Reason: Removed special decoration (icon)

User avatar
DrKnS
Posts: 4433
Joined: Thu 04 Aug, 2005 06:44
Location: Kyiv
Has thanked: 2 times
Been thanked: 101 times
Contact:

Trying to make a Python support plugin

Postby DrKnS » Sun 04 Oct, 2015 03:52

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: 4906
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 10 times
Been thanked: 118 times

Trying to make a Python support plugin

Postby Shmuel » Sun 04 Oct, 2015 05:56

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: 71
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Postby jonib » Sun 04 Oct, 2015 11:05

DrKnS wrote:Source of the post 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: 71
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Postby jonib » Sun 04 Oct, 2015 11:21

Shmuel wrote:Source of the post 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: 4906
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 10 times
Been thanked: 118 times

Trying to make a Python support plugin

Postby Shmuel » Sun 04 Oct, 2015 11:35

jonib wrote:Source of the post 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:Source of the post 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: 7880
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 62 times
Been thanked: 93 times

Trying to make a Python support plugin

Postby HaRT » Sun 04 Oct, 2015 11:41

jonib wrote:Source of the post 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: 71
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Postby jonib » Sun 04 Oct, 2015 12:06

HaRT wrote:Source of the post
jonib wrote:Source of the post 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: 71
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Postby jonib » Sun 04 Oct, 2015 12:15

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: 71
Joined: Wed 16 Apr, 2008 19:55
Has thanked: 1 time

Trying to make a Python support plugin

Postby jonib » Tue 06 Oct, 2015 13:03

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


Return to “Plug-In Developers”

Who is online

Users browsing this forum: No registered users and 1 guest