lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


You nearly had it:

2008/8/4 Hans van der Meer <H.vanderMeer@uva.nl>
>
> >> if t then for k,v in pairs(t) do print(k,v) end end
>

function CallThisFromC(t)
  local count = 0
  if t then for k,v in pairs(t) do count = count + 1 end end
  return count
end

For the complicated way, add a count to lua_next
http://www.lua.org/manual/5.1/manual.html#lua_next

Matthew Burke is correct, though now table.foreach is deprecated:
http://www.lua.org/manual/5.1/manual.html#7.2

Vaughan