xml.lua - Added mod to parse hex strings as a number

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

xml.lua - Added mod to parse hex strings as a number

#1 Post by zer0 » 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:

Code: Select all

<config name="mem_offset">0x0f00</config>
Becomes 1024.

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
Added to the implicitCast function like so:

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
I have several uses for it so I think it's pretty useful to include it in the XML lua parser.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: xml.lua - Added mod to parse hex strings as a number

#2 Post by Administrator » Mon Feb 23, 2009 2:25 pm

Good idea, I've just added this to MicroMacro 1.0, and it will appear in the next beta or full release. Thanks.

zer0
Posts: 213
Joined: Sat Feb 16, 2008 11:55 pm

Re: xml.lua - Added mod to parse hex strings as a number

#3 Post by zer0 » Tue Feb 24, 2009 6:48 am

Hehe, awesome thanks Elv. :D

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests