I have a program written in Free Pascal. It imports functions from a DLL selected at runtime. They are imported with the pascal;
keyword. I want to extend this program using python code. As I found out shedskin could be helpful for me in this situation. How do I need to proceed? In fact I want to "compile python code to a DLL". Additional to any free or open source tool/compiler I can use Microsoft Visual Studio 2012 and VC++ to solve my problem.

- 949
- 10
- 27
2 Answers
Assuming Pascal can use c foreign functions, using the python c-api directly is possible. I think your first step though, is understanding the api python exposes for embedding cpython in other applications.

- 2,845
- 18
- 27
-
1Free Pascal also supports ActiveX IDispatch interfaces, like Delphi. This is sometimes more convenient to interface to scripting languages. Maybe it is wiser to have a look at various Delphi<->Python bridges. – Marco van de Voort Sep 24 '13 at 13:46
The pascal
modifier is a statement of a calling convention. Parameters are pushed onto the stack left to right. Compare to the cdecl
calling convention where the parameters are pushed right to left to support variadic functions in C. The stdcall
modifier is another right to left calling convention.
Free Pascal supports both calling conventions. Here is cdecl, stdcall and pascal for Free Pascal. The calling conventions are definitely NOT compatible. If you call a function expected it arguments in a certain order with the stack arranged in the other order -- bad things will happen.
You will probably need to use cdecl to extend Free Pascal with Python that has been compiled into C++ code with shedskin. I think all Windows DLL's use the pascal conversion regardless of the language the DLL was written in however.
So make sure you use the right calling convention -- depending where you are using the code.

- 98,345
- 23
- 131
- 206
-
Afaik Pascal<>stdcall on Free Pascal. For windows dlls you want stdcall. http://www.freepascal.org/docs-html/ref/refsu79.html#x183-19300014.9.16 – Marco van de Voort Sep 24 '13 at 11:23