pas2js makestub: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: pas2js makestub
| Old | New | Line | |
|---|---|---|---|
| 1 | + | # The pas2js stub generator | |
| 2 | + | ||
| 3 | + | ## makestub utility | |
| 4 | + | ||
| 5 | + | ### Synopsis | |
| 6 | + | ||
| 7 | + | The *makestub* utility converts a Pascal import unit for importing Pascal classes to a unit that is compileable by Delphi | |
| 8 | + | ||
| 9 | + | ### Command-line | |
| 10 | + | ||
| 11 | + | command-line makestub usage is quite simple: | |
| 12 | + | ||
| 13 | + | makestub -i jsunit.pas -o delphiunit.pas | |
| 14 | + | ||
| 15 | + | you can add defines into the mix | |
| 16 | + | ||
| 17 | + | makestub -d DELPHI -d DEBUG -i jsunit.pas -o delphiunit.pas | |
| 18 | + | ||
| 19 | + | You can also include a header in the generated unit: | |
| 20 | + | ||
| 21 | + | makestub -h copyright.pas -i jsunit.pas -o delphiunit.pas | |
| 22 | + | ||
| 23 | + | It does not put comments around the header, the header file is inserted as-is, at the start of the generated file. | |
| 24 | + | ||
| 25 | + | *makestub* currently has some problems with forward-defined classes. There is an option to give a list of classes that must be defined forward: | |
| 26 | + | ||
| 27 | + | makestub -f TClassA,TClassB -i jsunit.pas -o delphiunit.pas | |
| 28 | + | ||
| 29 | + | The special word 'all' will define all classes as forward: | |
| 30 | + | ||
| 31 | + | makestub -f all -i jsunit.pas -o delphiunit.pas | |
| 32 | + | ||
| 33 | + | There is the possibility of using a config file (.ini) to set some options: | |
| 34 | + | ||
| 35 | + | makestub -c myconfig.ini -i jsunit.pas -o delphiunit.pas | |
| 36 | + | ||
| 37 | + | Options on the command-line override options set in the config file. | |
| 38 | + | ||
| 39 | + | ### Config file | |
| 40 | + | ||
| 41 | + | The makestub program supports a config file. This is a .INI file which has 1 section called *config*, which can contain the following keys : | |
| 42 | + | ||
| 43 | + | - *input*: The name of an input file (corresponds to -i). | |
| 44 | + | - *output*: The name of an output file (corresponds to -o) | |
| 45 | + | - *header*: the name of a header file to insert (corresponds to -h) | |
| 46 | + | - *defines*: a list of defines (corresponds to -d) | |
| 47 | + | - *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. | |
| 48 | + | - *includepaths* : include paths where to search for include files. | |
| 49 | + | - *forwardclasses*: a comma-separated list of classes that must be declared forward. | |
| 50 | + | - *indentsize*: number of spaces to use for indent (default 2) | |
| 51 | + | - *addlinenumber*: Boolean (0/1) each line is prefixed with a comment containing the line number. | |
| 52 | + | - *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. | |
| 53 | + | - *linenumberwidth*: number of digits to use for line numbers (default 4) | |
| 54 | + | ||
| 55 | + | #### Example | |
| 56 | + | ||
| 57 | + | Here is an example config file: | |
| 58 | + | ||
| 59 | + | [config] | |
| 60 | + | input=jsunit.pas | |
| 61 | + | output=delphiunit.pas | |
| 62 | + | header=copyright.pas | |
| 63 | + | indentsize=4 | |
| 64 | + | addlinenumber=1 | |
| 65 | + | addsourcelinenumber=1 | |
| 66 | + | linenumberwidth=5 | |
| 67 | + | forwardclasses=TClassA,TClassB | |
| 68 | + | extra=mysecretunit | |
| 69 | + | ||
| 70 | + | ## libstub library | |
| 71 | + | ||
| 72 | + | ### Synopsis | |
| 73 | + | ||
| 74 | + | The *libstub* library is the library equivalent of the makestub command-line tool. | |
| 75 | + | ||
| 76 | + | 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. | |
| 77 | + | ||
| 78 | + | ### Exported functions | |
| 79 | + | ||
| 80 | + | 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. | |
| 81 | + | ||
| 82 | + | Type | |
| 83 | + | PStubCreator = Pointer; | |
| 84 | + | ||
| 85 | + | Function GetStubCreator : PStubCreator; stdcall; | |
| 86 | + | Procedure FreeStubCreator(P : PStubCreator); stdcall; | |
| 87 | + | Procedure SetStubCreatorInputFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall; | |
| 88 | + | Procedure SetStubCreatorConfigFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall; | |
| 89 | + | Procedure SetStubCreatorOutputFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall; | |
| 90 | + | Procedure SetStubCreatorHeaderFileName(P : PStubCreator; AFileName : PAnsiChar); stdcall; | |
| 91 | + | Procedure AddStubCreatorDefine(P : PStubCreator; ADefine : PAnsiChar); stdcall; | |
| 92 | + | Procedure AddStubCreatorForwardClass(P : PStubCreator; AForwardClass : PAnsiChar); stdcall; | |
| 93 | + | Procedure SetStubCreatorHeaderContent(P : PStubCreator; AContent : PAnsiChar); stdcall; | |
| 94 | + | Procedure SetStubCreatorOuputCallBack(P : PStubCreator; AData : Pointer; ACallBack : TWriteCallBack); stdcall; | |
| 95 | + | function ExecuteStubCreator(P : PStubCreator) : Boolean; stdcall; | |
| 96 | + | Procedure GetStubCreatorLastError(P : PStubCreator; AError : PAnsiChar; | |
| 97 | + | Var AErrorLength : Longint; AErrorClass : PAnsiChar; Var AErrorClassLength : Longint); stdcall; | |
| 98 | + | ||
| 99 | + | # Navigation | |
| 100 | + | ||
| 101 | + | - Back to [[pas2js]] | |
| 102 | + | - Back to [[lazarus pas2js integration]] | |
| 103 | + | ||
| 104 | + | --- | |
| 105 | + | *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](/wiki-contact).* | |
| 106 | + | Category: Pas2js |
