Question

I am trying to parse the XML file with LuaXML

function customURLtoSteam64(web, sid)
local xml = require("luaXml")
local xfile = xml.load("http://steamcommunity.com/id/GreenMarineValve?xml=1") --line189
local xscene = xfile:find("steamID64[1]") 
return render_front(web, xscene)
end

But I get this error:

.\index.lua:189: attempt to index local 'xml' (a boolean value)
stack traceback:
.\index.lua:189: in function <.\index.lua:186>
(tail call): ?
(tail call): ?.\index.lua:189: attempt to index local 'xml' (a boolean value)
stack traceback:
c:\Lua\LuaRocks/share/lua/5.1/coxpcall.lua:24: in function 
(tail call): ?
(tail call): ?
c:\Lua\LuaRocks/share/lua/5.1/orbit.lua:540: in function 
(tail call): ?
(tail call): ?

I did not understand what is wrong, how can I correctly do that?

Was it helpful?

Solution

The require idiom you have used is the one recommended for Lua 5.2. Although the idiom also works for Lua 5.1, most (but not all) libraries for Lua 5.1 usually defined globals and did not return the value they define via require. In the absence of a return value from a luaopen_xxx function, require returns true, hence the error message you've seen.

So, just use simply require("luaXml"), don't assign it to a local.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top