Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2021-09

Import module support

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt

Hello,

Modern javascript has the possibility to import other modules:

import { create, createReportList } from './modules/canvas.js';
import * as Square from './modules/square.js';

pas2js now supports the latter form of the import syntax. We re-use the $LINKLIB directive from FPC for this.

{$linklib ./modules/square.js}

will be converted to

import * as square from './modules/square.js';

or

{$linklib ./modules/square.js mysquare}
import * as mysquare from './modules/square.js';

There are 4 demos that show how to use the importer libraries.

Some more explanations can be found in:

https://wiki.freepascal.org/pas2js_modules

The demos can be browsed at:

https://gitlab.com/freepascal.org/fpc/pas2js/-/tree/main/demo/modules

The next step is the creation of modules using the "library" concept of object pascal.

Michael.

Reply by email