1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-02-21 19:20:07 +02:00

added table.keys function

This commit is contained in:
grilledham 2019-05-13 11:07:11 +01:00
parent 82874823ce
commit f6bf121057

View File

@ -106,6 +106,20 @@ function table.set(t, index, element)
error('Index out of bounds', 2)
end
--- Returns an array of keys for a table.
--@param tbl <table>
function table.keys(tbl)
local n = 1
local keys = {}
for k in pairs(tbl) do
keys[n] = k
n = n + 1
end
return keys
end
--- Chooses a random entry from a table
-- because this uses math.random, it cannot be used outside of events
-- @param t <table>