# Module `FSM`

Factorio Softmod Manager

### Usage:

    Manager = require("FactorioSoftmodManager")

### Info:

- Author: Cooldude2606

## Functions

_verbose (rtn) | Default output for the verbose
verbose (rtn, action) | Used to call the output of the verbose when the current state allows it
setVerbose (settings) | Main logic for allowing verbose at different stages though out the script
sandbox (callback[, env]) | Creates a sand box envorment and runs a callback in that sand box; provents global pollution
loadModules () | Loads the modules that are present in the index list
error (err, callback) | A more detailed replacement for the lua error function to allow for handlers to be added; repleaces default error so error can be used instead of Manager.error
event (event_name, callback) | Event handler that modules can use, each module can register one function per event

## Tables

verboseSettings | Different verbose settings used for setVerbose
Manager.event.names | Sub set to Manger.event and acts as a coverter between event_name and event_id

## Fields

global | Used to avoid conflicts in the global table

## Functions

_verbose (rtn)
  Default output for the verbose

  ### Parameters:

  - rtn string the value that will be returned though verbose output

  ### Usage:

      Manager.verbose('Hello, World!')

verbose (rtn, action)
  Used to call the output of the verbose when the current state allows it

  ### Parameters:

  - rtn string the value that will be returned though verbose output
  - action string is used to decide which verbose this is error || event etc

  ### Usage:

      Manager.verbose('Hello, World!')

setVerbose (settings)
  Main logic for allowing verbose at different stages though out the script

  ### Parameters:

  - settings newTbl the table that will be searched for settings to be updated

  ### Usage:

  -     Manager.setVerbose{output=log}

  -     Manager.setVerbose[setting] -- returns the value of that setting

  -     tostring(Manager.setVerbose) -- returns a formated list of the current settings

sandbox (callback[, env])
  Creates a sand box envorment and runs a callback in that sand box; provents global pollution

  ### Parameters:

  - callback function the function that will be ran in the sandbox
  - env any other params that the function will use (optional)

  ### Usage:

  -     Manager.sandbox(callback) -- return sandbox, success, other returns from callback

  -     Manager.sandbox() -- returns and empty sandbox

  -     Manager.sandbox[key] -- returns the sand box value in that key

loadModules ()
  Loads the modules that are present in the index list

  ### Usage:

  -     Manager.loadModules() -- loads all moddules in the index list

  -     #Manager.loadModules -- returns the number of modules loaded

  -     tostring(Manager.loadModules) -- returns a formatted list of all modules loaded

  -     pairs(Manager.loadModules) -- loops over the loaded modules moduleName, module

error (err, callback)
  A more detailed replacement for the lua error function to allow for handlers to be added; repleaces default error so error can be used instead of Manager.error

  ### Parameters:

  - err string or fucntion the string to be passed to handlers; if a function it will register a handler
  - callback function if given the err param will be used to given the handler a name

  ### Usage:

  -     Manager.error(err) -- calls all error handlers that are set or if none then prints to game and if that fails crashs game

  -     Manager.error() -- returns an error constant that can be used to crash game

  -     Manager.error(Manager.error()) -- crashs the game

  -     Manager.error.addHandler(name,callback) -- adds a new handler if handler returns Manager.error() then game will crash

  -     Manager.error[name] -- returns the handler of that name if present

  -     #Manager.error -- returns the number of error handlers that are present

  -     pairs(Manager.error) -- loops over only the error handlers handler_name,hander

event (event_name, callback)
  Event handler that modules can use, each module can register one function per event

  ### Parameters:

  - event_name int or string that referes to an event
  - callback function the function that will be set for that event

  ### Usage:

  -     Manager.event[event_name] = callback -- sets the callback for that event

  -     Manager.event[event_name] = nil -- clears the callback for that event

  -     Manager.event(event_name,callback) -- sets the callback for that event

  -     Manager.event[event_name] -- returns the callback for that event or the event id if not registered

  -     Manager.event(event_name) -- runs all the call backs for that event

  -     Manager.event() -- returns the stop value for the event proccessor, if returned during an event will stop all other callbacks

  -     #Manager.event -- returns the number of callbacks that are registered

  -     pairs(Manager.events) -- returns event_id,table of callbacks

## Tables

verboseSettings
  Different verbose settings used for setVerbose

  ### Fields:

  - selfInit boolean called while the manager is being set up
  - moduleLoad boolean when a module is required by the manager
  - moduleInit boolean when and within the initation of a module
  - moduleEnv boolean during module runtime, this is a global option set within each module(module_verbose=true ln:1) for fine control
  - eventRegistered boolean when a module registers its event handlers
  - errorCaught boolean when an error is caught during runtime
  - output function can be: print || log || or other function
  - _output a constant value that can used to store output data
Manager.event.names
  Sub set to Manger.event and acts as a coverter between event_name and event_id

  ### Usage:

      Manager.event[event_name]

## Fields

global
  Used to avoid conflicts in the global table
  - if table, string or true table then the default for the global, if a string then the module to get the global of, if true then reset the global to default (default {})

  ### Usage:

  -     global[key] -- used like the normal global table

  -     global{'foo','bar'} -- sets the default value

  -     global(true) -- restores global to default

  -     global(mopdule_name) -- returns that module's global

generated by LDoc 1.4.6 Last updated 2018-06-07 12:58:23