xml.lua - Added mod to parse hex strings as a number
Posted: Mon Feb 23, 2009 7:10 am
I added a mod to change parsed hex strings to a number. Handy if you want to put hexadecimal as a value.
For example:
Becomes 1024.
In XML.lua:
Here was the mod.
Added to the implicitCast function like so:
I have several uses for it so I think it's pretty useful to include it in the XML lua parser.
For example:
Code: Select all
<config name="mem_offset">0x0f00</config>
In XML.lua:
Here was the mod.
Code: Select all
-- convert hex string to number.
if( string.find(data, "^(0x%x+)$") ~= nil) then
--print ("data: ", data)
return tonumber(data:sub(3), 16);
end
Code: Select all
function implicitCast(data)
if( data == "true" ) then
return true; end;
if( data == "false" ) then
return false; end;
if( string.find(data, "[^%.?0-9+]") == nil ) then
return tonumber(data);
end
-- convert hex string to number.
if( string.find(data, "^(0x%x+)$") ~= nil) then
--print ("data: ", data)
return tonumber(data:sub(3), 16);
end
return data;
end