[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: In defence of _G (Was: Fragile Recursion?)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 11 Apr 2012 08:04:12 +0200
>> _G.fact = fact
>
> In Lua 5.2 make that _ENV.fact = fact. It avoids the silly _G
> convention *and* saves yet another table lookup. :-)
>
Yes, _G should not be used when _ENV==_G.
But no, _G is not a silly convention.
1. It is a good idea to keep a reference to the original environment
somewhere.
2. It is a good idea for everybody to use the same name for that
reference.
3. It is a good idea to allow assignments to that name, so that
Lua programs that wish provide a different default global
environment (e.g. to disable some libraries) can do so.
4. _G is as good a choice for that name as any other.
Of course, you must bear in mind that _G is just _ENV._G.