lua-users home
lua-l archive

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


Hi folks,

Sorry to pound with the group with n00b questions, but here's another one.

I'm parsing a text file, and wanted to declare a function to print the table I'm building. Code is below.
Here's the question:
I see I have to declare function before using. However, it appears that the function executes once as the system runs. I had to put in the statement below "if tab[1] then" to catch the first run with a nil. Shouldn't the function only been called when I call it below?


t = {}
index = 0

local printTable
function printTable(tab)
   if tab[1] then
      ...
   end
end

for line in io.lines("test.txt") do
   --build table here
   printTable(t)
end

TIA
Mike