Util util

General utility functions.

Functions

getPathFromFilePath (filepath[, sep='/']) Get the path from a file path.
choose (...) Choose a random parameter from the provided parameters
weightedChoice (...) Choose a weighted random parameter from the provided parameters and weights.
array (...) Turn a list of parameters into a sequential table.
equalsAll (value, list) Returns if every parameter equals the specified value.
equalsAny (value, list) Returns if any of the parameters equals the specified value.
toggle (x) Toggles between 0 and 1.
lua (str) Runs the string as lua code.
memoize (fn) Wraps the specified function, caching results based on set of parameters.
readParticleSystem (name) Reads particle system configuration.
openSaveDirectory () Opens the save directory in the user's operating system.


Functions

getPathFromFilePath (filepath[, sep='/'])
Get the path from a file path.

Parameters:

  • filepath string path to file
  • sep string path seperator (default '/')

Returns:

    string path

Usage:

    local path = util.getPathFromFilePath( "C:/test/myfile.lua" ) -- Returns "C:/test/"
choose (...)
Choose a random parameter from the provided parameters

Parameters:

  • ... mixed multiple parameters

Returns:

    random parameters

Usage:

    local param = util.choose("Five", 5, Vector(0,5)) -- Returns either the string, number or vector
weightedChoice (...)
Choose a weighted random parameter from the provided parameters and weights.

Parameters:

  • ... mixed multiple parameters and weights, with weights on the even indices

Returns:

    random parameters

Usage:

    local param = util.weightedChoice("duck", 20, "cat", 10) -- String "duck" is twice as likely to be returned than "cat"
array (...)
Turn a list of parameters into a sequential table.

Parameters:

  • ... mixed list of parameters

Returns:

    table table containing parameters
equalsAll (value, list)
Returns if every parameter equals the specified value.

Parameters:

  • value
  • list of parameters

Returns:

    bool true if every parameter equals the value
equalsAny (value, list)
Returns if any of the parameters equals the specified value.

Parameters:

  • value
  • list of parameters

Returns:

    bool true if at least one parameter equals the value
toggle (x)
Toggles between 0 and 1.

Parameters:

  • x number 0 or 1

Returns:

    number 0 or 1
lua (str)
Runs the string as lua code. Throws assertion if there's an error.

Parameters:

memoize (fn)
Wraps the specified function, caching results based on set of parameters. Useful for functions that do deterministic and complex operations that can be sped up by caching the results for subsequent calls.

Parameters:

  • fn function function to wrap

Returns:

    function wrapped function
readParticleSystem (name)
Reads particle system configuration. Looks for the particle system in the directory stored in FOLDER.PARTICLESYSTEMS. Returns a ParticleSystem.

Parameters:

  • name string name of particle system

Returns:

    ParticleSystem particle system
openSaveDirectory ()
Opens the save directory in the user's operating system.
generated by LDoc 1.4.3 Last updated 2015-04-20 03:01:38