[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ipairs and extending numeric for loop
- From: M Joonas Pihlaja <jpihlaja@...>
- Date: Wed, 26 May 2010 11:19:14 +0300 (EEST)
On Mon, 24 May 2010, James Graves wrote:
> This is what I've got in my "utilities.lua" file which I use with all
> my own projects:
[snip implementation of ipairs]
Thanks for posting this. Clearly it's not a lot of code to carry
around if you miss ipairs, and your version even has __ipairs support
to boot.
> Questions:
>
> Should I be using rawget(a, i) instead of a[i]?
I like the a[i] table access since it means your ipairs is more
flexible than the 5.1 one and can use it on suitable userdata even.
Using a[i] from Lua is also much faster than calling rawget() for
normal tables. Having said that, the 5.1 ipairs() does use rawget(),
so I guess it depends on how closely you want to emulate it.
> Since I want ipairs() to be universally accessible, is there any
> practical difference to declaring the function as it is now, versus
> inserting it explicitly in the _G table?
I think it's fine as it is. There's only a practical difference if
someone's messed with your environment or removed _G from it.
Joonas