home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

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

October 2023
Code
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
3
═══ § ═══

Footnotes And References