summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/common/misc_helpers.lua9
-rw-r--r--doc/lua_api.txt2
2 files changed, 11 insertions, 0 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua
index 88a498927..199f13cd1 100644
--- a/builtin/common/misc_helpers.lua
+++ b/builtin/common/misc_helpers.lua
@@ -575,6 +575,15 @@ function table.insert_all(t, other)
end
+function table.key_value_swap(t)
+ local ti = {}
+ for k,v in pairs(t) do
+ ti[v] = k
+ end
+ return ti
+end
+
+
--------------------------------------------------------------------------------
-- mainmenu only functions
--------------------------------------------------------------------------------
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 35be95d51..374a774b1 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -2902,6 +2902,8 @@ Helper functions
* `table.insert_all(table, other_table)`:
* Appends all values in `other_table` to `table` - uses `#table + 1` to
find new indices.
+* `table.key_value_swap(t)`: returns a table with keys and values swapped
+ * If multiple keys in `t` map to the same value, the result is undefined.
* `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a
position.
* returns the exact position on the surface of a pointed node