Sign in Join
Wiki copytemporary

Revision 1 of 1, by Mattias2 on 8-2-2020. The page as it is now.

pas2js makestub

The pas2js stub generator

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:

pascal
makestub -i jsunit.pas -o delphiunit.pas

you can add defines into the mix

pascal
makestub -d DELPHI -d DEBUG -i jsunit.pas -o delphiunit.pas

You can also include a header in the generated unit:

pascal
makestub -h copyright.pas -i jsunit.pas -o delphiunit.pas

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:

pascal
makestub -f TClassA,TClassB -i jsunit.pas -o delphiunit.pas

The special word 'all' will define all classes as forward:

pascal
makestub -f all -i jsunit.pas -o delphiunit.pas

There is the possibility of using a config file (.ini) to set some options:

pascal
makestub -c myconfig.ini -i jsunit.pas -o delphiunit.pas

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 :

Example

Here is an example config file:

pascal
[config]
input=jsunit.pas
output=delphiunit.pas
header=copyright.pas
indentsize=4
addlinenumber=1
addsourcelinenumber=1
linenumberwidth=5
forwardclasses=TClassA,TClassB
extra=mysecretunit

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.

pascal
Type
  PStubCreator = Pointer;
pascal
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;

Navigation


From the Free Pascal wiki, page "pas2js makestub", as it stood on 2020-08-02 after a change by Mattias2, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.