lua-users home
lua-l archive

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


On 25 April 2014 05:04, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2014-04-25 2:34 GMT+02:00 Hisham <h@hisham.hm>:
>> On 21 April 2014 18:23, Thijs Schreijer <thijs@thijsschreijer.nl> wrote:
>>>> -----Original Message-----
>>>> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
>>>> Behalf Of Hisham
>>>> Sent: maandag 21 april 2014 19:17
>>>> To: Lua mailing list
>>>> Subject: Request for clarification on reserved names
>>>>
>>>> The Lua 5.2 (and 5.3) manual(s) say:
>>>>
>>>>    Lua is a case-sensitive language: and is a reserved
>>>>    word, but And and AND are two different, valid names.
>>>>    As a convention, names starting with an underscore
>>>>    followed by uppercase letters (such as _VERSION)
>>>>    are reserved for variables used by Lua.
>>>>
>>>> Does that mean (a) all names, (b) global variables only or (c) all
>>>> variables?
>>>>
>>>> The text says "names" which strictly speaking would mean option "a"
>>>> but I doubt this applies to table fields, so my original
>>>> interpretation was "b", but then I remembered that _ENV is special
>>>> even if it's a local variable (and yes, I've had to patch Lua 5.1 code
>>>> out there which used "_ENV" as a regular variable). I've also seen
>>>> tutorials out there that inadvertedly suggest _M (ugh) as a table name
>>>> for declaring modules.
>>>
>>>
>>> See this thread;
>>> http://article.gmane.org/gmane.comp.lang.lua.general/95848
>>>
>>> Your comment on _ENV was not considered in the mentioned thread.
>>
>> Oh, I missed Roberto's reply in the thread from 2012:
>>
>>> It seems clear (to me, at least) that Lua does not interfere with what
>>> you do with your own tables. The Lua convention refers only to its
>>> own tables (the global environment and the registry).
>>
>> Should this convention be now extended to local variables then?

Because I've seen at least one example of real Lua 5.1 code out there
using _ENV as a local variable name. If "names" refered only to the
global env and the registry in the convention, then this name wasn't
"reserved for Lua" back then, but since it has been taken over in Lua
5.2 to have a special meaning (even as a local variable), it broke the
code.

I know that Lua makes no compatibility guarantees regarding future
versions, but it would be nice to have a clearer definition on
reserved namespaces to avoid clashes like this in the future. A less
vague definition of "names" in that paragraph of the manual would
avoid future headaches for all of us.

It would be completely fine to me if the Lua team would like to
reserve the right to take over _UPPER-style names in all variables
(global and local), but it would be nicer if they just said so.

-- Hisham