Module Utilities
General utilities, that are useful to utilise.
General utilities
round (_input[, _precision]) | Rounds things to nearest integer, just like it sounds. |
switch (_keyToCheck, _caseTable) | Mimics C#/JS switch functionality. |
tobool (_input) | Turns things from string to bool, duh. |
Navigation utilities
headingToCardinal8 (_heading) | Finds approximate 8-point compass direction from input heading. |
headingToCardinal16 (_heading) | Finds approximate 16-point compass direction from input heading. |
invertDirection (_cardinalDirection) | Returns the opposite direction of a given cardinal direction. |
Unit conversion
mphToKmh (_input) | Does what it sounds like. |
mphToMs (_input) | Does what it sounds like. |
fToC (_input) | Does what it sounds like. |
General utilities
- round (_input[, _precision]) line 31
-
Rounds things to nearest integer, just like it sounds.
Somehow
Math.round()
isn't a thing. This is stupidly simple though, just adds 0.5 to our input and floors it.Parameters:
- _input number Number to round.
- _precision number Number of decimal places to round to. Default 0. (optional)
Returns:
-
Input rounded to nearest integer.
- switch (_keyToCheck, _caseTable) line 71
-
Mimics C#/JS switch functionality.
Fails to optional entry
_default
if check fails, otherwise raises error.Parameters:
- _keyToCheck
Input to check against keys in
_caseTable
- _caseTable table Key-value table, with keys being cases, and values being their returns
Returns:
-
Value of
_caseTable[_keyToCheck]
Raises:
Exception if key not found and no_default
entryUsage:
-- Function will return "I'm true", since 1 == 1 local truthiness = switch( 1 == 1, { [true] = "I'm true!", [false] = "I'm false!", _default = "I'm neither, so probably nil!" })
-- Function will retrieve function B, and then ourFunction() will be executable local functionTable = { ["Function A"] = function() echo("I'm A!") end ["Function B"] = function() echo("I'm B!") end ["Function C"] = function() echo("I'm C!") end _default = function() echo("I'm _default!") end } local ourFunction = switch( "Function B", functionTable) ourFunction() -- echo("I'm B!")
- _keyToCheck
Input to check against keys in
- tobool (_input) line 93
-
Turns things from string to bool, duh.
Parameters:
- _input string The string to check
Navigation utilities
- headingToCardinal8 (_heading) line 121
-
Finds approximate 8-point compass direction from input heading.
Parameters:
- _heading num Heading to convert.
Returns:
-
string
Nearest 8-point compass direction.
- headingToCardinal16 (_heading) line 148
-
Finds approximate 16-point compass direction from input heading.
Parameters:
- _heading num Heading to convert.
Returns:
-
string
Nearest 16-point compass direction.
- invertDirection (_cardinalDirection) line 183
-
Returns the opposite direction of a given cardinal direction.
Parameters:
- _cardinalDirection num (e.g. "north", "e", "south-southwest", "ene")
Returns:
-
float
Heading in degrees