manoelcampos / xml2lua

XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
MIT License
287 stars 73 forks source link

Not working on Lua 5.3 #7

Closed elihugarret closed 6 years ago

elihugarret commented 6 years ago

Hi! I noticed that this module does not work on Lua 5.3:

lua5.3: /usr/local/share/lua/5.1/xml2lua.lua:99: attempt to call a nil value (global 'module')
stack traceback:
        /usr/local/share/lua/5.1/xml2lua.lua:99: in main chunk
        [C]: in function 'require'
        test.lua:1: in main chunk
        [C]: in ?

The "module" function is not supported on Lua 5.3. I want to help, I'll send you a pull request these days fixing this and making it compatible with the last version of Lua.

manoelcampos commented 6 years ago

Thanks. I'm looking forward to your PR.

evnix commented 6 years ago

Yes please!! Lua 5.3 doesn't seem to have any other alternate XML parser for now :(

manoelcampos commented 6 years ago

I'll take a look at it by the end of the week.

manoelcampos commented 6 years ago

Hello @evnix and @elihugarret

I've fixed the issue. Now it works with Lua 5.1 to 5.3. I appreciate if you could give some feedback.

evnix commented 6 years ago

I found this,

lua -l set_paths x.lua lua: lua_modules/share/lua/5.3/xml2lua.lua:123: attempt to call a nil value (field 'new') stack traceback: lua_modules/share/lua/5.3/xml2lua.lua:123: in function 'xml2lua.parser' x.lua:8: in main chunk [C]: in ?

where x.lua is copied from example1.lua

manoelcampos commented 6 years ago

Is x.lua an exact copy of example1.lua? Could you show the code here? What is your exact Lua version? I'm using 5.3.4.

evnix commented 6 years ago
testNet:examples silva$ lua -v
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
testNet:examples silva$ cat x.lua
local xml2lua = require("xml2lua")
--Uses a handler that converts the XML to a Lua table
local handler = require("xmlhandler.tree")

local xml = xml2lua.loadFile("people.xml")

--Instantiates the XML parser
local parser = xml2lua.parser(handler)
parser:parse(xml)

--Manually prints the table (since the XML structure for this example is previously known)
for k, p in pairs(handler.root.people.person) do
  print("Name:", p.name, "City:", p.city, "Type:", p._attr.type)
end
testNet:examples silva$ cat people.xml 
<?xml version="1.0" encoding="UTF-8"?>
<people>
  <person type="P">
    <![CDATA[
    Just a CDATA tag that may contain anything, including XML code,
    such as <tag>message</tag>.
    Its content is extracted but not processed.
    ]]>  

    <!-- Just an example comment that will be ignored by the tree handler and processed by the other ones. -->

    <name>Manoel</name>
    <city>Palmas-TO</city>
  </person>
  <person type="P">
    <name>Breno</name>
    <city>Palmas-TO</city>
  </person>
  <person type="J">
    <name>University of Brasília</name>
    <city>Brasília-DF</city>
  </person>  
</people>
testNet:examples silva$ cat set_paths.lua 
-- set_paths.lua
local version = _VERSION:match("%d+%.%d+")
package.path = 'lua_modules/share/lua/' .. version .. '/?.lua;lua_modules/share/lua/' .. version .. '/?/init.lua;' .. package.path
package.cpath = 'lua_modules/lib/lua/' .. version .. '/?.so;' .. package.cpath
testNet:examples silva$ lua -l set_paths  x.lua 
lua: lua_modules/share/lua/5.3/xml2lua.lua:123: attempt to call a nil value (field 'new')
stack traceback:
    lua_modules/share/lua/5.3/xml2lua.lua:123: in function 'xml2lua.parser'
    x.lua:8: in main chunk
    [C]: in ?
manoelcampos commented 6 years ago

The issue was when downloading using luarocks. I fixed the rock file. Use luarocks to download the new 1.1-1 version.

evnix commented 6 years ago

Yes it worked perfectly now. Thanks a lot :)