Skip to content

External Modules

Stephen Reindl edited this page Nov 19, 2018 · 2 revisions

External modules can be used to implement parts of your logic in a separate component (aka DLL).

External modules differ from regular oberon 0 source files by marking exportable elements with a star ('*'). To use an external module (or at least parts of them, use the IMPORT statement).

The following module exports a procedure and a type:

MODULE ExportModule;

TYPE
  ExportType* = RECORD 
    a: INTEGER
  END;

PROCEDURE Demo (VAR r: ExportType)*;
BEGIN
  r.a := r.a -1
END Demo;

BEGIN (* ExportModule *)
  (* Init code executed on program start *)
  WriteString('Hello - This is export module'); WriteLn
END ExportModule.

The following code uses ExportModule:

MODULE MyNiceApplication;

IMPORT ExportModule;

VAR 
  r: ExportType;

BEGIN
  WriteString('Welcome to MyNiceApplication'); 
  WriteLn;
  r.a := 100;
  Demo(r);
  WriteInt(r.a);
  WriteLn
END Demo.

Compilation:

C:> Oberon0Msil MyNiceApplication.ob0 ExportModule.ob0
....
C:>

The output would be

C:> MyNiceApplication.exe
Hello - This is export module
Welcome to MyNiceApplication
99

Rules

  • Starred elements are allowed only on global level
  • If types are used as part of starred procedure's paramters/global variables, the corresponding type need to be starred as well (exception: basic types)
  • recursive imports need to be disallowed (A imports B imports A)
Clone this wiki locally