lua-users home
lua-l archive

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


Unfortunately that's not the problem :(

I've changed the example a little bit:

local module = {}

function module:cb( plugin, tag, attribute, value )
  if ( attribute == "value" ) then
    plugin[ 1 ] = value
    plugin[ 2 ] = value  <-- Exception
  end
end

function module:LoadPlugins( path, dirs )
  local lom = require "lxp"
  local plugin = {}
  plugin[ 1 ] = "anything"  <-- Initializing a pseudo field
	
  local callbacks = {
    StartElement = function( parser, name, attributes )
      for _, attribute in pairs( attributes ) do
        module.cb( self, plugin, name, attribute, attributes[ attribute ] )
      end
    end,
    EndElement = function( parser, name ) end,
    CharacterData = false
  }
	
  local xml_file = "info.plist"
  local parser = lxp.new( callbacks )
  local file = assert( io.open( xml_file .. "", "r" ) )
		
  parser:parse( file:read( "*all" ) )
		
  file:close();
  collectgarbage()
  parser:parse()         -- Beendet das Dokument
  parser:close()         -- Schließt den Parser
end

It seems, that the new allocation of fields in the table generates the error. If I modify only the value plugin[ 1 ] in function cb, all works fine. If I try to create a new entry like plugin[ 2 ], the error occurs.

Best Regards
Micha



Javier Guerra schrieb:
On Mon, Apr 20, 2009 at 5:38 AM, Michael Bauroth
<Michael.Bauroth@falcom.de> wrote:
   for _, attribute in pairs( attributes ) do
     cb( name, attribute, attributes[ attribute ] )
   end

i think here's your problem, the attributes table uses the 'array' and
'map' parts of the table for different purposes, but using
pairs(attributes) you iterate over all of them.  change to ipairs() to
read the attribute names in order.