[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Module Interface File

A module's public interface is contained in a module interface file, conventionally with the .m suffix. It is analogous to the C/C++ header file (.h).

The Inferno Reference API module interface files are conventionally stored in the <inferno_root>/module directory.

A module interface file declares the public data and function members. It specifies the types and function interfaces that can be used by other programs. It is the module interface declaration.

Program Listing 3-1 is an example of a simple module interface file.

Program Listing 3-1 greet.m

  1. Greet: module {
  2. init: fn(ctxt: ref Draw->Context, argv: list of string);
  3. };

This declares one function, init.

Program Listing 3-2 shows another small example, the Random Module of the Inferno Reference API (in the <inferno_root>/module/rand.m file).

Program Listing 3-2 rand.m

  1. Rand: module
  2. {
  3. PATH: con "/dis/lib/rand.dis";
  4. # init sets a seed
  5. init: fn(seed: int);
  6. # rand returns something in 0 .. modulus-1
  7. # (if 0 < modulus < 2^31)
  8. rand: fn(modulus: int): int;
  9. # (if 0 < modulus < 2^53)
  10. bigrand: fn(modulus: big): big;
  11. };

This declares a string constant, PATH, that contains the specific path to the compiled implementation file and three functions, init, rand, and bigrand. The string constant PATH is a convention in Limbo modules.



[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Copyright © 1998, Lucent Technologies, Inc. All rights reserved.