|
3 years ago | |
---|---|---|
.. | ||
basic | 3 years ago | |
basic-units | 3 years ago | |
flat | 3 years ago | |
flat-units | 3 years ago | |
simple | 3 years ago | |
README.md | 3 years ago |
pas2js can convert the $linklib directive to a JS import statement:
The following:
{$linklib ./modules/canvas.js canvas}
is converted to
import * as canvas from "./modules/canvas.js";
If the alias is omitted, one is constructed for you:
{$linklib ./modules/some-api.js}
is converted to
import * as some_api from "./modules/some-api.js";
The import statements are always inserted in the main program. This is because modules are like windows libraries: self-contained programs, which only import and export well-defined symbols.
For this reason, a new target "operating system" has been invented: the module. This means that you must compile with target module:
pas2js -Tmodule -Jirtl.js main.pp
The nodejs target will also work, but in the future the 2 targets may diverge.
Each directory contains 1 demo. Compile with the command-line as above:
pas2js -Tmodule -Jirtl.js main.pp
This shows a simple program, no units, that uses the linklib directive to import a javascript module. It uses an external class definition to access the exported symbols from the modules.
This is the same as the Basic example, but the import definitions are split out in units.
This shows a simple program, no units, that uses the linklib directive to import a javascript module. It uses only external 'name' definitions to access the exported symbols from the modules; no external class is used.
This is the same as the flat example, but the import definitions are split out in units.