I've been using the mod XML Parser as u know, I ran into a parser error, which had me stumped for a bit, so I decided to add error handling for the parse() call in the open function, here it is:
I've saved this for now, but won't be able to test it. Kind of surprised that I never thought of adding that in while I was writing the function. Well, thanks for the addition. I might change it a bit so that the error message follows the same format as other error messages, but it will definitely be added.
It was only because I had modified the XML and broken it, that's why I added it.
It gave me a chance to look at the code a bit, so I'm more than happy to help. Over the holiday season, I might start taking a look at the Micromacro source, and familiarising myself with the code base.
I'm actually trying to finalize the changes for 0.99 right now. I've already begun re-writing the whole thing for 1.0. So far, things are going well. Unless I come across some problems, the code for 1.0 should be much cleaner and easier to maintain. As things are now, it's a mess.
Yeah I understand, ZS Shaiya is up to about 3500 lines of code now, and there is quite a bit of cleaning up, error handling and optimisation to do (it's all a learning experience for me).
Hey I found that I need to parse XML data and convert a value or an attribute from a string to a number or boolean data type.
There is both an implicit version, and an explicit one.
You may find it useful, maybe a way to incorporate it into the XML mod, I dunno, anyway here they are.
-- explicit string conversion to another basic data type.
-- currently only number and boolean types supported.
-- @param data The data you want to convert.
-- @param data_type The basic data type you want to change it too.
-- @return The converted data
function stringConvert(data, data_type)
converts = {}
converts["boolean"] = function()
if (data == "true") then
return true
elseif (data == "false") then
return false
else
return nil
end
end
converts["number"] = function()
print("data: " .. data)
local l_res = string.find(data, "[^%.?0-9+]")
if (l_res == nil) then
print("number")
return tonumber(data)
else
print("not number")
return nil
end
end
print("data: " .. data)
print("data_type: " .. data_type)
return converts[data_type]()
end
-- implicit string conversion to another basic data type.
-- currently only number and boolean types supported.
-- @param data The data you want to convert.
-- @return The converted data.
function string_convert(data)
print("data: " .. data)
if (data == "true") then
return true
elseif (data == "false") then
return false
elseif(string.find(data, "[^%.?0-9+]") == nil) then
return tonumber(data)
else
return data
end
end