-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FreePascal language support #376
Comments
I am not planning on adding any more languages at this point. Adding new language support is possible, but it's a lot more work than most people realize until they try to do it. For me, it would be the equivalent of a full-time job for about 6 weeks. For a volunteer new to the project, it would take a lot longer. I would be willing to help guide someone, but usually when I explain all the things that need to be done, people decide they don't want to do it. |
OK, understand. |
Seems to be working. I slightly modified the C header file astronomy.h, added: #ifdef _WIN32
#define _PREFIX __declspec(dllexport)
#else
#define _PREFIX
#endif // _WIN32 Then for each function just added the symbol _PREFIX, example: _PREFIX astro_time_t Astronomy_MakeTime(int year, int month, int day, int hour, int minute, double second); This way after build in Visual Studio the result library (astronomy.dll file) exports all the functions which can be called from any other language which support external functions. The wrapper Pascal unit is then: unit Astronomy;
{$mode objfpc}{$H+}
interface
uses
Classes
{ you can add units after this };
const
LibraryName = 'astronomy'; // should refer the astronomy.dll file without extension
type
AstroTime = packed record
UT: Double;
TT: Double;
Psi: Double;
Eps: Double;
ST: Double;
end;
function Astronomy_MakeTime(Year: Int32; Month: Int32; Day: Int32; Hour: Int32; Minute: Int32; Second: Double): AstroTime; cdecl; external LibraryName;
implementation
end.
To call the wrapper function from Pascal code: program Demo;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, Astronomy;
var
at1: AstroTime;
begin
at1 := Astronomy_MakeTime(2025, 1, 20, 22, 20, 0.5);
WriteLn('Astro time: ' + FloatToStr(at1.UT));
end.
It works as expected. This way we can wrap in Pascal the whole C-language functionality. |
That is really cool! I used to use Turbo Pascal back in the day, which later became Delphi. FreePascal looks very similar, right down to the {$ ...} compiler directives. I miss the elegant way modules worked, and how blazingly fast compiles were... |
The reason I use FreePascal is that it's actively developed, it's free and it supports Windows/Linux/MacOS platforms. |
Here we go, there is a PR for FreePascal language support: |
This is not a real issue, just a question, whether there is a plan to support also the FreePascal programming language, e. g. to create an Astronomy FreePascal unit (library)?
The text was updated successfully, but these errors were encountered: