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
| Manager.event.names | Sub set to Manger.event and acts as a coverter between event_name and event_id |
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 settingtostring(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 callbackManager.sandbox() -- returns and empty sandboxManager.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 loadedtostring(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 eventManager.event[event_name] = nil -- clears the callback for that event
Manager.event(event_name,callback) -- sets the callback for that eventManager.event[event_name] -- returns the callback for that event or the event id if not registeredManager.event(event_name) -- runs all the call backs for that eventManager.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 registeredpairs(Manager.events) -- returns event_id,table of callbacks