lua-users home
lua-l archive

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


On Sun, Feb 21, 2010 at 11:46 AM, spir <denis.spir@free.fr> wrote:
> * fields keeps all sections, items filters empty ones out. (2)
> * fields unpacks its return values, items returns an array. (3)
> * Both should allow as argument a set of separators. (4)
> * Neither trims sections by default; there may be an optional "trim" flag (5).
> * Both may have ' ' as single default separator.
>

I think we all have invented such functions before - it is almost a
rule, 'any non-trivial Lua application or library shall need to
reinvent string splitting' ;)

It's certainly hard to do these two things in one function; this seems
to be a reasonable separation.

However, I would go for always returning an array, and use unpack to get values:

x,y,z = unpack {1,2,3}

(Lua likes this kind of thing to be explicit, which is why x,y,z = t
does not work as a Python person would expect; causes a lot of
ambiguity)

> Is it worth be added to Lua's builtins?
Generally, if something can be cleanly implemented in Lua, then there
is no need to make it into C;  as for builtins, remember that the Lua
core has a 'core budget' which makes its designers very reluctant to
add new builtins.

steve d.