Skip to content

Instantly share code, notes, and snippets.

@mebens
Created October 25, 2012 00:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mebens/3949839 to your computer and use it in GitHub Desktop.
Save mebens/3949839 to your computer and use it in GitHub Desktop.
Reverse a table in Lua
function table.reverse(t)
local len = #t + 1
for i = 1, math.floor(#t / 2) do
t[i], t[len - i] = t[len - i], t[i]
end
return t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment