lua-users home
lua-l archive

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


Eric, thank you for your reply.
But your gsub approach is slower than concatenation.

this is I wrote:

  function bytetostring (bytes)
    local buf = strrep(' ', getn(bytes))
    local index = {n = 0}
    local rep = function (c)
                  %index.n = %index.n + 1
                  return strchar(%bytes[%index.n])
                end
    return gsub(buf, '(.)', rep)
  end


On Sat, Mar 16, 2002 at 09:47:21AM -0800, Eric Tetz wrote:
> You can do something like this:
> 
>   function bytestostring (bytes)
>     local buf = strrep(' ', getn(bytes))
>     local i = 0
>     return (gsub (buf, '(.)', 
>         function(c)
>           i = i + 1
>           return strchar(bytes[i])
>         end))
>   end
>  
> Not exactly pretty, but it's a lot faster than string concatenation.

-- 
SATO Seichi