Difference between revisions of "pas2s stub"

From Lazarus wiki
(Replaced content with "see pas2js makestub")
(Tag: Replaced)
 
Line 1: Line 1:
= The pas2js stub generator =
+
see [[pas2js_makestub|pas2js makestub]]
 
 
== makestub utility ==
 
=== Synopsis ===
 
 
 
The ''makestub'' utility converts a Pascal import unit for importing Pascal classes to a unit that is compileable by Delphi
 
 
 
=== Command-line ===
 
command-line makestub usage is quite simple:
 
<pre>
 
makestub -i jsunit.pas -o delphiunit.pas
 
</pre>
 
you can add defines into the mix
 
<pre>
 
makestub -d DELPHI -d DEBUG -i jsunit.pas -o delphiunit.pas
 
</pre>
 
 
 
You can also include a header in the generated unit:
 
<pre>
 
makestub -h copyright.pas -i jsunit.pas -o delphiunit.pas
 
</pre>
 
It does not put comments around the header, the header file is inserted
 
as-is, at the start of the generated file.
 
 
 
''makestub'' currently has some problems with forward-defined classes.
 
There is an option to give a list of classes that must be defined forward:
 
 
 
<pre>
 
makestub -f TClassA,TClassB -i jsunit.pas -o delphiunit.pas
 
</pre>
 
The special word 'all' will define all classes as forward:
 
<pre>
 
makestub -f all -i jsunit.pas -o delphiunit.pas
 
</pre>
 
There is the possibility of using a config file (.ini) to set some options:
 
<pre>
 
makestub -c myconfig.ini -i jsunit.pas -o delphiunit.pas
 
</pre>
 
Options on the command-line override options set in the config file.
 
 
 
=== Config file ===
 
The makestub program supports a config file. This is a .INI file which has 1 section called ''config'', which can contain the following keys :
 
 
 
* ''input'': The name of an input file (corresponds to -i).
 
* ''output'': The name of an output file (corresponds to -o)
 
* ''header'': the name of a header file to insert (corresponds to -h)
 
* ''defines'': a list of defines (corresponds to -d)
 
* ''extra'': a list of units to insert at the start of the uses clause. Note that the ''jsdelphisystem'' unit is always inserted, and that you can use ''all'' to indicate that all classes must be  eclared forward.
 
* ''includepaths'' : include paths where to search for include files.
 
* ''forwardclasses'': a comma-separated list of classes that must be declared forward.
 
* ''indentsize'': number of spaces to use for indent (default 2)
 
* ''addlinenumber'': Boolean (0/1) each line is prefixed with a comment containing the line number.
 
* ''addsourcelinenumber'': Boolean (0/1) each line is prefixed with a comment containing the line number of the source file that was used to create the current line.
 
* ''linenumberwidth'': number of digits to use for line numbers (default 4)
 
 
 
==== Example ====
 
Here is an example config file:
 
<pre>
 
[config]
 
input=jsunit.pas
 
output=delphiunit.pas
 
header=copyright.pas
 
indentsize=4
 
addlinenumber=1
 
addsourcelinenumber=1
 
linenumberwidth=5
 
forwardclasses=TClassA,TClassB
 
extra=mysecretunit
 
</pre>
 
 
 
== libstub library ==
 
=== Synopsis ===
 
 
 
The ''libstub'' library is the library equivalent of the makestub command-line tool.
 
 
 
It can be used in Delphi to automate conversion of pas2js units.
 
The stub creator is written in Lazarus/Free Pascal and therefor cannot be compiled in Delphi, since it uses a lot of units not available in pas2js.
 
 
 
=== Exported functions ===
 
The following functions are exported by the library creator. Given the above explanations about config files and command-line options, their usage should be clear.
 
<pre>
 
Type
 
  PStubCreator = Pointer; 
 
 
 
Function GetStubCreator : PStubCreator; stdcall;
 
Procedure FreeStubCreator(P : PStubCreator); stdcall;
 
Procedure SetStubCreatorInputFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall;
 
Procedure SetStubCreatorConfigFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall;
 
Procedure SetStubCreatorOutputFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall;
 
Procedure SetStubCreatorHeaderFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall;
 
Procedure AddStubCreatorDefine(P : PStubCreator; ADefine : PAnsiChar); stdcall;
 
Procedure AddStubCreatorForwardClass(P : PStubCreator; AForwardClass : PAnsiChar); stdcall;
 
Procedure SetStubCreatorHeaderContent(P : PStubCreator; AContent : PAnsiChar); stdcall;
 
Procedure SetStubCreatorOuputCallBack(P : PStubCreator; AData : Pointer; ACallBack : TWriteCallBack); stdcall;
 
function ExecuteStubCreator(P : PStubCreator) : Boolean; stdcall;
 
Procedure GetStubCreatorLastError(P : PStubCreator; AError : PAnsiChar;
 
  Var AErrorLength : Longint; AErrorClass : PAnsiChar; Var AErrorClassLength : Longint); stdcall;
 
</pre>
 
 
 
= Navigation =
 
* Back to [[pas2js]]
 
* Back to [[lazarus pas2js integration]]
 
 
 
[[Category:Pas2js]]
 

Latest revision as of 18:42, 2 August 2020