lua-users home
lua-l archive

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


On Jan 28, 2012 7:26 AM, "Matthew Wild" <mwild1@gmail.com> wrote:
>
> On 28 January 2012 06:29, HyperHacker <hyperhacker@gmail.com> wrote:
> > On Fri, Jan 27, 2012 at 06:39, Matthew Wild <mwild1@gmail.com> wrote:
> >> On 27 January 2012 11:21, HyperHacker <hyperhacker@gmail.com> wrote:
> >>> On Fri, Jan 27, 2012 at 04:20, Luiz Henrique de Figueiredo
> >>> <lhf@tecgraf.puc-rio.br> wrote:
> >>>>> to make this work, you need to wrap the lookup:
> >>>>
> >>>> Or do
> >>>>        params = {["1"]='file.c', ["2"]='file.o'}
> >>>>
> >>>
> >>> Well yes, but that isn't always feasible, e.g. with the {...} example.
> >>
> >> setmetatable({...}, { __index = function (t, k) return rawget(t,
> >> tonumber(k)); end })
> >>
> >> Regards,
> >> Matthew
> >>
> >
> > That's not really much simpler, and still assumes you can modify the table.

You don't have to modify the table. Create an empty one to serve as a proxy to the real table.

> Converting from a string to a number is a special case, specific to
> your current problem.

Oh, Lua already does more of it than some of us would care for. I write it off as one of Lua's youthful indiscretions--"she got a body piercing *where*? In the type system? Isn't that painful and potentially contagious?"