Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Reverse A List In Lua

Code

local function reverse_list(source)
  local response = {}
  local counter = #source
  while counter > 0 do
    table.insert(response, source[counter])
    counter = counter - 1
  end
  return response
end

local data = { "alfa", "echo", "delta", "bravo" }
local reversed = reverse_list(data)

for _, value in ipairs(reversed) do
  print(value)
end

Results

bravo
delta
echo
alfa