Locator BtUtils

The main entry point of the library, through which one can access anything else.

The Locator class, which BtUtils is an instance of, is itself defined within this module, in order to not creator another dependency that needs to be handled through something other than a Locator.

Tables

BtUtils Locatable modules and classes.

Class Locator

Locator:New (t, locators, prefix) Creates a new Locator.
Locator:Assign (key, creator) Assigns a value to the specified key if it is still nil.
Locator:Reload () Removes currently located modules and classes.


Tables

BtUtils
Locatable modules and classes.

Fields:

Class Locator

Instances of this class have a specified set of key-path pairs, so called locators. The keys are accessible as regular fields of a table, however their value is retrieved by reading and evaluating a lua file defined by the locator. This process is done only once, when the key is first accessed, as the resulting module/class is stored directly on the instance as a regular field.
Locator:Assign (key, creator)
Assigns a value to the specified key if it is still nil.

Remarks:

    This method is supplied in order to support the idiom l.key = l.key or ... in the located modules that intend to directly place themselves into specific a Locator. This idiom would not work as it would recursively invoke the file execution, resulting in an error.

Parameters:

  • key string the key to assign under
  • creator func closure which creates the module/class that belongs to the key

Returns:

    the newly creator module/class if the key was not assigned to, current occupant of the key otherwise

Usage:

     locator:Assign("myModule", function()
         ...
         return myModule
       end)
Locator:New (t, locators, prefix)
Creates a new Locator.

Remarks:

    The locators mapping is a live table, so any changes to it end up affecting Locators functionality. That also relates to the possiblity of not defining it at the time of creating the Locator, but by adding entries to the table returned as a second return value.

Parameters:

  • t tab preexisting table to convert into a Locator or nil
  • locators {[string]=string} table mapping keys to relative paths (without the extension .lua) where to look for lua scripts defining the modules/classes or nil
  • prefix string directory prefix to where the path of the Locator is supposed to be with respect to the BtUtils root directory or nil

Returns:

  1. Locator
  2. {[string]=string} locators parameter if specified or a new empty table that is used as the mapping
Locator:Reload ()
Removes currently located modules and classes. That causes them to be reloaded when accessed again, hence the name.
generated by LDoc 1.4.3 Last updated 2017-06-01 23:07:48