Browse Source

Add table.key_value_swap (#9248)

Port of Old MT commit f9c7e46a34
From: HybridDog <3192173+HybridDog@users.noreply.github.com>
Date: Sat, 4 Jan 2020 15:44:48 +0100
master
OldCoder 8 months ago
parent
commit
ba7ad8613f
2 changed files with 14 additions and 1 deletions
  1. +9
    -0
      builtin/common/misc_helpers.lua
  2. +5
    -1
      doc/lua_api.txt

+ 9
- 0
builtin/common/misc_helpers.lua View File

@@ -554,6 +554,15 @@ end

test_string_to_area()

function table.key_value_swap(t)
local ti = {}
for k,v in pairs(t) do
ti[v] = k
end
return ti
end


--------------------------------------------------------------------------------
function table.copy(t, seen)
local n = {}


+ 5
- 1
doc/lua_api.txt View File

@@ -2353,7 +2353,11 @@ Helper functions
* returns time with microsecond precision. May not return wall time.
* `table.copy(table)`: returns a table
* returns a deep copy of `table`
* `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
* `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

Translations


Loading…
Cancel
Save