Package openmw_aux.utilΒΆ

OpenMW version: 0.49.0
core.API_REVISION: 62 *

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 tostring but shows also content of tables.

util.findMinScore(array, scoreFn)

Finds the element the minimizes scoreFn.

util.mapFilter(array, scoreFn)

Computes scoreFn for each element of array and filters out elements with false and nil results.

util.mapFilterSort(array, scoreFn)

Filters and sorts array by the scores calculated by scoreFn.

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

  1. element The element the minimizes scoreFn

  2. #number: score The output of scoreFn(element)

  3. #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 of array and filters out elements with false and nil results.

Parameters

  • #table array : Any array

  • #function scoreFn : Filter function

Return values

  1. #table: Output array

  2. #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 by scoreFn.

The same as aux_util.mapFilter, but the result is sorted.

Parameters

  • #table array : Any array

  • #function scoreFn : Filter function

Return values

  1. #table: Output array

  2. #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)