[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Table generation issue
- From: Romulo Bahiense <romulo@...>
- Date: Mon, 20 Nov 2006 23:49:31 -0200
I believe the problem is not table allocation, but index access and
length calculation ('#' operator).
Try this one:
function createFieldDataEntriesForOneDataGenerator( dataGenerator )
local data = dataGenerator()
local iSubTable = 0
local iSubTableBlock = 0
local subTable = {}
local subTableBlock = {}
local subTableType
for i, element in ipairs(data) do
local a, b, c = element[ 1 ], element[ 2 ], element[ 3 ]
if a == "<type>" then
subTableType = b
elseif a == "</type>" then
-- do nothing
elseif a == "<block>" then
subTableBlock = {Number=b,Dup=c}
elseif a == "</block>" then
iSubTable = iSubTable + 1
subTable[iSubTable] = subTableBlock
else
if trim(b) ~= "" then
iSubTableBlock = iSubTableBlock + 1
subTableBlock[ iSubTableBlock ] = {a,b}
end
end
end
return subTable, subTableType
end
Note that, in this code, 'data[i]' is the same as 'element', because
ipairs return key and value.
--rb