lua-users home
lua-l archive

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


> The proposal of Sebastien Lai, to which I doesn't agree like
> presented, is interesting however.
> Until Lua 4.0, all library functions were global variables.
> On Lua 5.0, most of them were moved into specific tables.
> On Lua 5.1, the module system blessed the concept of a module as a
> table.
> And in Lua 5.2, unpack moves into table.unpack. Several global
> functions (loadstring, loadfile, setfenv, getfenv, module, newproxy)
> are suppressed.
> 
> So there is a global trend toward removing global variables. There is
> a trade-of to be done between modularity and ease of use.
> We could for example move functions next, pairs, ipairs, rawget and
> rawset into table.
> That would make sense, but grow the average Lua code size because they
> are frequently used (well, really?)
> 
> The three global variables Sebastien mentions (_G, _VERSION and arg)
> are three special cases with no correlation between them.
> That is why I found the proposal useless. _G is mostly replaced by the
> upvalue _ENV in Lua 5.2. t
> The arg table is on my point of view a legacy construct that should be
> replaced with the "..." syntax.
> So creating a sys table only for the remaining _VERSION isn't needed...

I agree with you.

So the idea would become:
- *_G* replaced by *_ENV* (remove *_G* in Lua 5.2?)
- *arg* replaced by *...* (AFAIK, removed in Lua 5.2?)

And, to get further, is there any other global vars to move in a specific global table?
- *_VERSION* replaced by *debug.version*? or by *debug._VERSION*? or not ...
- *raw[get/set]* => *table.raw[get/set]*? (are those functions specific to tables? Or does it works for userdata too?)
  (but it would be weird to have *raw[get/set]* in *table* table and *raw[len/equal]* as global vars)
- but in your example *next*, *pairs*, *ipairs* works for a table as for a userdata (AFAIK), so moving it to *table* would be irrelevant?!
- other existing global vars doesn't seems to fit in any existing global table?
- would it be relevant to put other global vars in a global *lua* or whatever table? (it seems to be ugly :S)