lua-users home
lua-l archive

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


I am still fiddling with Lua - ClearSilver HDF interface.  I wrote index
and newindex in C and for debugging purpose they output what is being
indexed, newindexed.

The Lua code puts in a loop database results in a HDF container:

	hdf.bset = {}
	for n = 1, res:ntuples() do
		hdf.bset[n] = {}
		hdf.bset[n].id = res:getvalue(n, 1)
		hdf.bset[n].name = res:getvalue(n, 2)
		hdf.bset[n].description = res:getvalue(n, 3)
	end

And as LHF pointed out, Lua wise the following snipped should be equivalent:

	hdf.bset = {}
	for n = 1, res:ntuples() do
		hdf.bset[n] = {
			id = res:getvalue(n, 1),
			name = res:getvalue(n, 2),
			description = res:getvalue(n, 3)
		}
	end

Hower, the C functions are called differently, in the first case it
looks like this:

lua: newindex 'bset'
lua: index 'bset', no value found, returning object
lua: newindex '1'
lua: index 'bset', no value found, returning object
lua: index '1', no value found, returning object
lua: newindex 'id' (2)
lua: index 'bset', no value found, returning object
lua: index '1', no value found, returning object
lua: newindex 'name' (gv-lf-zl)
lua: index 'bset', no value found, returning object
lua: index '1', no value found, returning object
lua: newindex 'description' (Lieferung auf Ziel.)
lua: index 'bset', no value found, returning object
lua: newindex '2'
lua: index 'bset', no value found, returning object
lua: index '2', no value found, returning object
lua: newindex 'id' (7)
lua: index 'bset', no value found, returning object
lua: index '2', no value found, returning object
lua: newindex 'name' (test)
lua: index 'bset', no value found, returning object
lua: index '2', no value found, returning object
lua: newindex 'description' (Test)
lua: index 'bset', no value found, returning object
lua: newindex '3'
lua: index 'bset', no value found, returning object
lua: index '3', no value found, returning object
lua: newindex 'id' (6)
lua: index 'bset', no value found, returning object
lua: index '3', no value found, returning object
lua: newindex 'name' (wh-vb)
lua: index 'bset', no value found, returning object
lua: index '3', no value found, returning object
lua: newindex 'description' (Verkauf von Handelsware gegen bar)

In the second case, with the nicer looking constructor, at lot less C
gets called:

lua: newindex 'bset'
lua: index 'bset', no value found, returning object
lua: newindex '1'
lua: index 'bset', no value found, returning object
lua: newindex '2'
lua: index 'bset', no value found, returning object
lua: newindex '3'

What am I missing here?  I can post the C code, if that helps.