lua-users home
lua-l archive

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


Ha! I was just waiting for functions like that. Funny. That must be
how the "collective mind" works.

Not that it's so much work to use io.open (it's only three lines after
all) - but it's kinda nice to have a one-line solution for file I/O.

Can't see anything wrong with the way you wrote the module either -
looks great to me.

Stefan

On Fri, Nov 4, 2011 at 2:29 AM, David Manura <dm.lua@math2.org> wrote:
> file_slurp [1] provides simple functions to read/write entire files
> from/to a string.
>
> SYNOPSIS
>
>  -- Example to convert tabs to spaces in a file.
>  local FS = require 'file_slurp'
>  local s = FS.readfile 'foo.txt'
>  s = s:gsub('\t', '    ')
>  FS.writefile('foo.txt', s)
>  -- Also supports ascii/binary, error policies, and pipes:
>  s = FS.readfile('ls -la', 'p')