lua-users home
lua-l archive

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


Pierre Chapuis <catwell@archlinux.us> wrote:
> I don't know about you but here are some of the kinds of things
> I have in my own "utils" section in most of my Lua projects:
> 
> - a function that reads a whole file to a string by path;

This sounds like a popular Perl module, slurp. (I'd be curious to see the
code for this.)

> I don't think those should be in the Lua standard library though, and
> they take so little code in pure Lua that they do not really make sense
> in a separate module.

I think the "so little code" argument cuts both ways. If they take *so
little* code and *so many* Lua programmers have to write them, then it does
begin to make sense to include them in the standard library. In particular,
I really think the standard library should include a printf function.

In any case, here are the things I use pretty constantly but don't think
are worth sharing formally:


+ printf() : just what you think it is and 
+ writef() : like printf() but write the string to a specified filehandle
+ exists() : test if a file exists
+ clone() and same() : deep-copy a table and test the equality of two tables
+ info(), warn(), quit(), die() : print message to stdout or stderr, exit
  with success or failure and print a message to stdout or stderr; all the
  functions can print a formatted string and all of them give you a final
  newline for free (kind of like baby's first logger)

I also often use collection helpers like map(), reduce(), etc., but for
those I made a more formal module[1] because I wanted all the functions twice:
once for list-like tables and once for hash-like tables.

The only thing in this group I would seriously suggest as a Lua built-in is
printf.

Best, Peter

[1] https://bitbucket.org/telemachus/tableutils

-- 
We have not been faced with the need to satisfy someone else's
requirements, and for this freedom we are grateful.
    Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System