Package openmw_aux.utilΒΆ
openmw_aux.util
defines utility functions that are implemented in Lua rather than in C++.
Implementation can be found in resources/vfs/openmw_aux/util.lua
.
Usage:
local aux_util = require('openmw_aux.util')
Type util
util.deepToString(value, maxDepth) |
Works like |
util.findMinScore(array, scoreFn) |
Finds the element the minimizes |
util.mapFilter(array, scoreFn) |
Computes |
util.mapFilterSort(array, scoreFn) |
Filters and sorts |
Type util
Field(s)
- util.deepToString(value, maxDepth)
-
Works like
tostring
but shows also content of tables.Parameters
-
#any value
: The value to convert to string -
#number maxDepth
: Max depth of tables unpacking (optional, 1 by default)
-
- util.findMinScore(array, scoreFn)
-
Finds the element the minimizes
scoreFn
.Parameters
-
#table array
: Any array -
#function scoreFn
: Function that returns either nil/false or a number for each element of the array
Return values
-
element The element the minimizes
scoreFn
-
#number: score The output of
scoreFn(element)
-
#number: index The index of the chosen element in the array
Usage:
-- Find the nearest NPC local nearestNPC, distToNPC = aux_util.findMinScore( nearby.actors, function(actor) return actor.type == types.NPC and (self.position - actor.position):length() end)
-
- util.mapFilter(array, scoreFn)
-
Computes
scoreFn
for each element ofarray
and filters out elements with false and nil results.Parameters
-
#table array
: Any array -
#function scoreFn
: Filter function
Return values
-
#table: Output array
-
#table: Array of the same size with corresponding scores
Usage:
-- Find all NPCs in `nearby.actors` local NPCs = aux_util.mapFilter( nearby.actors, function(actor) return actor.type == types.NPC end)
-
- util.mapFilterSort(array, scoreFn)
-
Filters and sorts
array
by the scores calculated byscoreFn
.The same as
aux_util.mapFilter
, but the result is sorted.Parameters
-
#table array
: Any array -
#function scoreFn
: Filter function
Return values
-
#table: Output array
-
#table: Array of the same size with corresponding scores
Usage:
-- Find all NPCs in `nearby.actors` and sort them by distances local NPCs, distances = aux_util.mapFilterSort( nearby.actors, function(actor) return actor.type == types.NPC and (self.position - actor.position):length() end)
-