Documentation‎ > ‎

Startup Sequence

  1. All "static variables" are set to zero/false/NIL. "static variables" are the
    variables at the module level and variables in the SHARED
    section of a class.

  2. The "static variables" in builtin modules are initialized.

  3. One by one, in undetermined order, the "static variables" that have the
    @earlyInit attribute and an assignment are initialized.  This includes
    objects of a class that has the @earlyInit attribute, such as the command
    line flags in the ARG module.
    Note that the expression is evaluated while other "static variables" may
    not have been initialized yet.  It is possible to create command line
    arguments, but they cannot be used yet.

  4. The EARLYINIT() methods are invoked in undetermined order.  This is
    repeated until they all return OK.  An EARLYINIT() method is only
    called again when it previously returned FAIL.
    This is aborted with an error after 1000 rounds.
    This allows for anything that needs to be done before command line
    arguments are processed, including calling ARG.replaceRawList() and
    even a complete replacement of the ARG module.
    The Foo.EARLYREADY flag indicates whether the Foo module or class
    has finished early initialization.  It is TRUE when there is no EARLYINIT()
    method or the EARLYINIT() method has returned OK.

  5. Command line arguments are processed, unless ARG.disable() was invoked
    in one of the previous steps.

  6. One by one, in undetermined order, the "static variables" that have an
    assignment and no @earlyInit attribute are initialized.
    Note that the expression is evaluated while other "static variables" may
    not have been initialized yet.  It is possible to use command line arguments.

  7. All defined INIT() methods are invoked in undetermined order.  This is
    repeated until they all return OK.  An INIT() method is only called again when
    it previously returned FAIL
    This is aborted with an error after 1000 rounds.
    This allows modules and classes to perform initializations that depend
    on other modules and classes.
    The Foo.READY flag indicates whether the Foo module or class finished
    initialization.  It is TRUE when there is no INIT() method or the INIT()
    method has returned OK.

Example:

MODULE Foo
  # A boolean command line argument "-v" or "--verbose".
  # This will be initialized in step 3, because ARG.Bool has the @earlyInit attribute.
  ARG.Bool verbose = NEW("v", "verbose", FALSE, "Verbose messages")

  # This will be initialized in step 6, after "verbose".
  string leader = verbose.value() ? "Foo module: " : ""

  # This will be invoked in step 7, after "leader" was initialized.
  FUNC INIT(): status
    IF Bar.READY    # when Bar has been initialized
      Bar.setLeader(leader)
      RETURN OK     # initialization of Foo is done
    }
    RETURN FAIL     # we need another round
  }
}