lua-users home
lua-l archive

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


On Mon, Dec 6, 2010 at 3:58 PM, Dirk Laurie <dpl@sun.ac.za> wrote:
> But when something like s[i] can be defined in a few lines of pure
> Lua, as Michal Kottman showed, no C needed, then the fact that an
> idea comes from Pascal does not mean that one is not thinking in Lua.
> "Doing more with less" — that's the idea, isn't it?

I find myself torn on this one.  On the one hand, define shortcuts
that you will use frequently. On the other hand, indexing says
'table'. You are adding some magic to the usual mix and this can fool
casual code inspection.

There are two performance considerations also: intercepting the string
metatable's __index means that string methods are going to be a little
slower - maybe that's important?

The other thing is that s:sub(i,i) is not at all as cheap as s[i]
would suggest ;) Yes, sometimes you have to do it per-character, but
mostly there's a way using string patterns, and it will always be more
efficient.

steve d.