lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Apr 16, 2010 at 8:32 PM, Patrick Donnelly <batrick@batbytes.com> wrote:
> Here's a benchmark for various optimizations I've made. The best version so far:
>
> local hex = {};
> for i = 0, 255 do
>  hex[i] = string.format("%02X", i);
> end
>
> function string2hex5 (s)
>  return (string.gsub(s, ".", hex));
> end

This code has a pretty significant error in it (causing it to not do
anything). Here's the corrected code:

local hex = {};
for i = 0, 255 do
  hex[string.char(i)] = string.format("%02X", i);
end

function string2hex5 (s)
  return (string.gsub(s, ".", hex));
end

Sorry about that.

-- 
- Patrick Donnelly