lua-users home
lua-l archive

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


considering its a constant its quite a performance blotch to put a string constant in the compiled file to parse it into binary at startup. if I'd wanted to work with strings as numbers at runtime I'd go with TCL.

On Mon, Dec 1, 2014 at 7:56 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> sometimes i've done things like this:
>
> function b(s)
>     local o = 0
>     for d in s:gmatch('[01]') do
>         o = o * 2 + tonumber(d)
>     end
>     return o
> end

function b (s)
  return tonumber(string.gsub(s, "_", ""), 2)
end

-- Roberto