[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Should tiny utilities be prepackaged?
- From: "Pierre Chapuis" <catwell@...>
- Date: Wed, 2 Mar 2016 11:06:11 +0100
> What I would find interesting is a more scientific approach of choosing
> functions for a utility library: Scan publicly available Lua code from
> different authors, collect domain-independent functions that are used
> more than once, and take the top 30 (or so).
I agree, although I am not entirely sure that publicly available
Lua code is really representative of all Lua code.
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;
- a function that writes a string to a file by path;
- one or several "enum" functions that do things like:
-- returns { "foo" = 0, "bar" = 1, [0] = "foo", [1] = "bar" }
enum(0, "foo", "bar")
- to_hex / from_hex;
- a function to check if a variable is a positive integer within
some bounds;
- a map(a_function, a_sequence) function and a similar one for non-sequence
tables;
- printf(...) and die(...), which prints an error message to stderr
and exits.
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.