lua-users home
lua-l archive

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


> Since the table data type is used so effectively to keep Lua simple and
> powerful, it made me wonder why use of tables wasn't extended as far as the
> global environment.  In other words why does a programmer implementing
> extensions have to treat the global environment as a special case?
> [...]

For sure this solution is quite elegant. But I am afraid that performance 
is a problem. For example, the following script 

  a = 0
  local i = 1
  while i<=1000000 do
    a = a+1
    i = i+1
  end

runs in 1.17s in my machine. If you change it to

  local a = {a=0}
  local i = 1
  while i<=1000000 do
    a.a = a.a+1
    i = i+1
  end

the time goes to 1.90s.


> I'm sure that I must be overlooking something...  what is it?

Another problem is compatibility for tag methods (your "roughly"). The way 
tag methods are selected for globals is quite different from the way for 
tables. 

But we will think about this change. It would certainly simplify things in 
Lua. 

-- Roberto