Forum > Suggestions

imports ease

(1/1)

mercurhyo:
I think it would be useful to add a directive so FPC compiler understands/crossplatforminterprets and reminds what libraries symbol to refer without the need to repeat it in source code


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit myimports; {$mode ObjFPC}{$H+} interface const  MyLibrary = 'mylibname' +{$ifdef WINDOWS}'.dll'{$else}{$ifdef DARWIN}'.dylib' {$else} '.so'{$endif}{$endif}; procedure proc1; external MyLibrary;procedure proc2; external MyLibrary;procedure proc3; external MyLibrary;...procedure procN; external MyLibrary; implementation end.
should be replaced by


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit myimports; {$mode ObjFPC}{$H+} interface {$DYNLIB mylibname} procedure proc1; external;procedure proc2; external;procedure proc3; external;...procedure procN; external; implementation end.
with a new compiler directive like {$dynlib name} (unit scope or block of externals scope automatycally adjusting platforms naming conventions for all the following 'external' with no name mentioned

Martin_fr:

--- Quote from: mercurhyo on December 18, 2023, 07:47:50 pm ---with a new compiler directive like {$dynlib name} (unit scope or block of externals scope} automatycally adjusting platforms naming conventions for all the following 'external' with no name mentioned

--- End quote ---

Well, to adjust platform-naming you don't need to get rid of the constant, nor the repeated "external the_lib_name".

And I think, you can use  System.SharedSuffix

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  MyLibrary = 'mylibname.' + System.SharedSuffix;

As for the repeated "MyLibrary" after the (repeated) "external" => there a lots of ways to quickly put that in.

- (regex) search/replace on "external".
- Syncro edit
- Editor Macro
- external script
- fpc macro (define a single identifier that will be replaced with the full sequence)
...

PascalDragon:

--- Quote from: mercurhyo on December 18, 2023, 07:47:50 pm ---I think it would be useful to add a directive so FPC compiler understands/crossplatforminterprets and reminds what libraries symbol to refer without the need to repeat it in source code


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit myimports; {$mode ObjFPC}{$H+} interface const  MyLibrary = 'mylibname' +{$ifdef WINDOWS}'.dll'{$else}{$ifdef DARWIN}'.dylib' {$else} '.so'{$endif}{$endif}; procedure proc1; external MyLibrary;procedure proc2; external MyLibrary;procedure proc3; external MyLibrary;...procedure procN; external MyLibrary; implementation end.
--- End quote ---

You are aware that the file extension isn't required, because FPC will add the correct suffix (and prefix) for the platform?


--- Quote from: mercurhyo on December 18, 2023, 07:47:50 pm ---should be replaced by


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit myimports; {$mode ObjFPC}{$H+} interface {$DYNLIB mylibname} procedure proc1; external;procedure proc2; external;procedure proc3; external;...procedure procN; external; implementation end.
with a new compiler directive like {$dynlib name} (unit scope or block of externals scope automatycally adjusting platforms naming conventions for all the following 'external' with no name mentioned

--- End quote ---

This will fail as soon as one wants to import from multiple libraries in the same unit (think OpenSSL which consists of two modules).

Navigation

[0] Message Index

Go to full version