Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Get The Number Of Items In A Lua Table

This is from a 2010 answer. TODO is look up to see if there's a different way now

lua
local function table_length(source)
  local count = 0
  for _ in pairs(source) do 
    count = count + 1 
  end
  return count
end


local example = { 
  alfa = "apple", 
  bravo = "bean", 
  charlie = "cherry"
}

print(table_length(example))
results start

Footnotes And References