diff --git a/doc/index.html b/doc/index.html index ce54b6e..175102b 100644 --- a/doc/index.html +++ b/doc/index.html @@ -31,42 +31,42 @@

Modules

@@ -78,86 +78,45 @@

Modules

- - + + - - + + - - + + - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + @@ -165,28 +124,37 @@ does not use the VoxelManip object, but the Minetest get_node/set_node functions. + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - @@ -196,40 +164,72 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
stringutilVarious utility functions for working with strings.interpolateVarious mathematical functions for interpolating values.
randomRandom is a static utility that provides fast and easy access to - random numbers.tableutilVarious utility functions for working with tables.
noisemanagerThe NoiseManager manages seeds and creates PRNG of various kinds, always - with a new, unique seed.stopwatchAllows to easily time blocks of code.
nodeutilVarious functions related to nodes.facedirutilVarious functions and constants for working with the facedir value.
posutil Various functions for working with positions.
pathutilVarious utility functions for working with paths.
objectrefutil Provides various utility methods for manipulating ObjectRefs.
mapmanipulatorThe MapManipulator is a thin wrapper around the VoxelManip object - provided by minetest.
fisheryatesAn implementation of the Fisher-Yates algorithm, which allows to access - an array in a random or pseudo-random order.
textureutilUtil for various functions regarding textures.
blockutilVarious functions related to blocks/chunks.
tangoThe tango color scheme.
arraymanipulatorThe ArrayManipulator is similiar to the MapManipulator, except that it - does not use the VoxelManip object, but has an internal array which contains - all set values.
inventoryutil A util for working with inventories.
entityutilProvides various utility methods for manipulating entities.wallmountedutilVarious functions and constants for working with the wallmounted + value.
schedulerThe Scheduler allows you to easily schedule functions for execution.
blockedcacheA simple cache for caching values based on x and z coordinates.
mathutilVarious mathematical functions.
logA simple utility for logging purposes.
arrayutilVarious utility functions for working with arrays.tangoThe tango color scheme.
directmapmanipulator
randomRandom is a static utility that provides fast and easy access to + random numbers.
logA simple utility for logging purposes.
rotationutil Various functions for rotating nodes.
textureutilUtil for various functions regarding textures.
mapmanipulatorThe MapManipulator is a thin wrapper around the VoxelManip object + provided by minetest.
stringutilVarious utility functions for working with strings.
settings Encapsulates the settings API of minetest and extends it with further functions.
pathutilVarious utility functions for working with paths.
wallmountedutilVarious functions and constants for working with the wallmounted - value.
interpolateVarious mathematical functions for interpolating values.
transform Various mathematical functions for transforming values.Various functions for working with numbers.
testA simple utility for testing values and running unit tests.schedulerThe Scheduler allows you to easily schedule functions for execution.
facedirutilVarious functions and constants for working with the facedir value.
constantsVarious constants.
minetestexProvides various extensions to the builtin functions.
listA simple list that keeps the order in which the items are added to it.
stopwatchAllows to easily time blocks of code.
itemutilProvides various utility functions for working with items.mathutilVarious mathematical functions.
color A simple container for a color and its hex string representation.
tableutilVarious utility functions for working with tables.blockutilVarious functions related to blocks/chunks.
nodeutilVarious functions related to nodes.
arrayutilVarious utility functions for working with arrays.
itemutilProvides various utility functions for working with items.
noisemanagerThe NoiseManager manages seeds and creates PRNG of various kinds, always + with a new, unique seed.
arraymanipulatorThe ArrayManipulator is similiar to the MapManipulator, except that it + does not use the VoxelManip object, but has an internal array which contains + all set values.
constantsVarious constants.
listA simple list that keeps the order in which the items are added to it.
blockedcacheA simple cache for caching values based on x and z coordinates.
entityutilProvides various utility methods for manipulating entities.
fisheryatesAn implementation of the Fisher-Yates algorithm, which allows to access + an array in a random or pseudo-random order.
testA simple utility for testing values and running unit tests.
minetestexProvides various extensions to the builtin functions.
diff --git a/doc/modules/arraymanipulator.html b/doc/modules/arraymanipulator.html index 3265904..d249892 100644 --- a/doc/modules/arraymanipulator.html +++ b/doc/modules/arraymanipulator.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/arrayutil.html b/doc/modules/arrayutil.html index 5708430..60ed93a 100644 --- a/doc/modules/arrayutil.html +++ b/doc/modules/arrayutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/blockedcache.html b/doc/modules/blockedcache.html index 37acc49..55fba81 100644 --- a/doc/modules/blockedcache.html +++ b/doc/modules/blockedcache.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/blockutil.html b/doc/modules/blockutil.html index 6aa9357..d4daf50 100644 --- a/doc/modules/blockutil.html +++ b/doc/modules/blockutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/color.html b/doc/modules/color.html index f98a54c..d1ec56a 100644 --- a/doc/modules/color.html +++ b/doc/modules/color.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/constants.html b/doc/modules/constants.html index facbf56..8e3ca0b 100644 --- a/doc/modules/constants.html +++ b/doc/modules/constants.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/directmapmanipulator.html b/doc/modules/directmapmanipulator.html index 888e5b9..915e152 100644 --- a/doc/modules/directmapmanipulator.html +++ b/doc/modules/directmapmanipulator.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/entityutil.html b/doc/modules/entityutil.html index fed928e..cc0de71 100644 --- a/doc/modules/entityutil.html +++ b/doc/modules/entityutil.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/facedirutil.html b/doc/modules/facedirutil.html index 27783ca..a478f60 100644 --- a/doc/modules/facedirutil.html +++ b/doc/modules/facedirutil.html @@ -40,42 +40,42 @@

Modules

diff --git a/doc/modules/fisheryates.html b/doc/modules/fisheryates.html index 93a17ab..52b349c 100644 --- a/doc/modules/fisheryates.html +++ b/doc/modules/fisheryates.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/interpolate.html b/doc/modules/interpolate.html index 7959286..248950c 100644 --- a/doc/modules/interpolate.html +++ b/doc/modules/interpolate.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/inventoryutil.html b/doc/modules/inventoryutil.html index 3154d5a..449a6bc 100644 --- a/doc/modules/inventoryutil.html +++ b/doc/modules/inventoryutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/itemutil.html b/doc/modules/itemutil.html index 37cb99e..43f0ebe 100644 --- a/doc/modules/itemutil.html +++ b/doc/modules/itemutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/list.html b/doc/modules/list.html index 8a4ff32..208b64a 100644 --- a/doc/modules/list.html +++ b/doc/modules/list.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/log.html b/doc/modules/log.html index db0a8dc..3dd634f 100644 --- a/doc/modules/log.html +++ b/doc/modules/log.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/mapmanipulator.html b/doc/modules/mapmanipulator.html index 23bed9a..a80a70a 100644 --- a/doc/modules/mapmanipulator.html +++ b/doc/modules/mapmanipulator.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/mathutil.html b/doc/modules/mathutil.html index 91530b1..d2b6505 100644 --- a/doc/modules/mathutil.html +++ b/doc/modules/mathutil.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/minetestex.html b/doc/modules/minetestex.html index bcaf8c4..4e9f4ce 100644 --- a/doc/modules/minetestex.html +++ b/doc/modules/minetestex.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/nodeutil.html b/doc/modules/nodeutil.html index c9845e8..fa45799 100644 --- a/doc/modules/nodeutil.html +++ b/doc/modules/nodeutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/noisemanager.html b/doc/modules/noisemanager.html index 6b36447..57413fd 100644 --- a/doc/modules/noisemanager.html +++ b/doc/modules/noisemanager.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/numberutil.html b/doc/modules/numberutil.html index 78e8213..3e926aa 100644 --- a/doc/modules/numberutil.html +++ b/doc/modules/numberutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/objectrefutil.html b/doc/modules/objectrefutil.html index 1a5533b..54e5964 100644 --- a/doc/modules/objectrefutil.html +++ b/doc/modules/objectrefutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/pathutil.html b/doc/modules/pathutil.html index b9d6f01..580a325 100644 --- a/doc/modules/pathutil.html +++ b/doc/modules/pathutil.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/posutil.html b/doc/modules/posutil.html index ea80277..5a46414 100644 --- a/doc/modules/posutil.html +++ b/doc/modules/posutil.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/random.html b/doc/modules/random.html index 5a292a4..ab4b9a3 100644 --- a/doc/modules/random.html +++ b/doc/modules/random.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/rotationutil.html b/doc/modules/rotationutil.html index fa90a34..36262e7 100644 --- a/doc/modules/rotationutil.html +++ b/doc/modules/rotationutil.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/scheduler.html b/doc/modules/scheduler.html index 583c169..24c8477 100644 --- a/doc/modules/scheduler.html +++ b/doc/modules/scheduler.html @@ -39,42 +39,42 @@

Modules

diff --git a/doc/modules/settings.html b/doc/modules/settings.html index 530a610..5ef4724 100644 --- a/doc/modules/settings.html +++ b/doc/modules/settings.html @@ -39,42 +39,42 @@

Modules

@@ -98,6 +98,10 @@ Gets a boolean from the configuration. + get_list (name, default_value, The) + Gets a list from the configuration. + + get_number (name, default_value) Gets a number from the configuration. @@ -114,6 +118,10 @@ Gets a string from the configuration. + get_table (name, default_value, ...) + Gets a table with the given keys form the configuration. + + save () Saves all settings to configuration file. @@ -201,6 +209,34 @@ + +
+ + get_list (name, default_value, The) +
+
+ Gets a list from the configuration. + + +

Parameters:

+ + + + + +
@@ -321,6 +357,39 @@ + +
+ + get_table (name, default_value, ...) +
+
+ Gets a table with the given keys form the configuration. + + +

Parameters:

+ + +

Returns:

+
    + + The table with the given name and the given keys, or the default + value it is nil. +
+ + + +
diff --git a/doc/modules/stopwatch.html b/doc/modules/stopwatch.html index c3b853d..0d79f14 100644 --- a/doc/modules/stopwatch.html +++ b/doc/modules/stopwatch.html @@ -38,42 +38,42 @@

Modules

diff --git a/doc/modules/stringutil.html b/doc/modules/stringutil.html index 05ef869..9bcf6fc 100644 --- a/doc/modules/stringutil.html +++ b/doc/modules/stringutil.html @@ -38,42 +38,42 @@

Modules

@@ -101,13 +101,17 @@ mathutil.SIGNED_32BIT_MAX (which is roughly -2 billion to 2 billion). - split (text, split) + split (text, split, trim_values) Splits the given text using the given split value. startswith (text, value) Tests if the given text starts with the given value. + + trim (text) + Trims the given text from any leading and trailing whitespace. +
@@ -201,7 +205,7 @@
- split (text, split) + split (text, split, trim_values)
Splits the given text using the given split value. Returns the splitted text @@ -220,6 +224,10 @@
  • split The split value.
  • +
  • trim_values + Optional. If the values should be trimmed, defaults to + true. +
  • Returns:

    @@ -259,6 +267,31 @@ +
    +
    + + trim (text) +
    +
    + Trims the given text from any leading and trailing whitespace. + + +

    Parameters:

    + + +

    Returns:

    +
      + + The trimmed text. +
    + + + +
    diff --git a/doc/modules/tableutil.html b/doc/modules/tableutil.html index 1320eed..1219d97 100644 --- a/doc/modules/tableutil.html +++ b/doc/modules/tableutil.html @@ -38,42 +38,42 @@

    Modules

    diff --git a/doc/modules/tango.html b/doc/modules/tango.html index 90c68d5..2473276 100644 --- a/doc/modules/tango.html +++ b/doc/modules/tango.html @@ -34,42 +34,42 @@

    Modules

    diff --git a/doc/modules/test.html b/doc/modules/test.html index 3bd17cd..3f7c133 100644 --- a/doc/modules/test.html +++ b/doc/modules/test.html @@ -38,42 +38,42 @@

    Modules

    diff --git a/doc/modules/textureutil.html b/doc/modules/textureutil.html index 61e221c..621dc53 100644 --- a/doc/modules/textureutil.html +++ b/doc/modules/textureutil.html @@ -38,42 +38,42 @@

    Modules

    diff --git a/doc/modules/transform.html b/doc/modules/transform.html index 152f358..55e684f 100644 --- a/doc/modules/transform.html +++ b/doc/modules/transform.html @@ -38,42 +38,42 @@

    Modules

    diff --git a/doc/modules/wallmountedutil.html b/doc/modules/wallmountedutil.html index df1cd3f..6d26521 100644 --- a/doc/modules/wallmountedutil.html +++ b/doc/modules/wallmountedutil.html @@ -40,42 +40,42 @@

    Modules

    diff --git a/mods/utils/settings.lua b/mods/utils/settings.lua index 4214e9e..b0fbf70 100644 --- a/mods/utils/settings.lua +++ b/mods/utils/settings.lua @@ -159,6 +159,38 @@ function settings.get_string(name, default_value) return settings.get(name, default_value, tostring) end +--- Gets a table with the given keys form the configuration. +-- +-- @param name The name of the value to get. +-- @param default_value The default value to return if the value is nil, can be +-- nil. +-- @param ... The name of the keys. +-- @return The table with the given name and the given keys, or the default +-- value it is nil. +function settings.get_table(name, default_value, ...) + local value = settings.get_list(name, nil) + + if value ~= nil then + local table = {} + + if ... ~= nil then + for index, key in ipairs({...}) do + table[key] = value:get(index) + end + end + + if ... == nil or #{...} < value:size() then + for index = #{...} + 1, value:size(), 1 do + table[index] = value:get(index) + end + end + + return table + else + return default_value + end +end + --- Saves all settings to configuration file. function settings.save() minetest.setting_save() diff --git a/test/settings.lua b/test/settings.lua index c183105..cde2022 100644 --- a/test/settings.lua +++ b/test/settings.lua @@ -103,3 +103,12 @@ test.run("get_string", function() test.equals("Some String", settings.get_string("string")) end) +test.run("get_table", function() + test.equals(nil, settings.get_table("nonexistent")) + test.equals({ a = "b", c = "d" }, settings.get_table("nonexistent", { a = "b", c = "d" })) + + test.equals({ a = "a", b = "b", c = "c", d = "d", e = "e" }, settings.get_table("list", nil, "a", "b", "c", "d", "e")) + test.equals({ a = "a", b = "b", [3] = "c", [4] = "d", [5] = "e" }, settings.get_table("list", nil, "a", "b")) + test.equals({ a = "a", b = "b", c = "c", d = "d", e = "e" }, settings.get_table("list", nil, "a", "b", "c", "d", "e", "f", "g", "h")) +end) +