lua-users home
lua-l archive

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



Deneb aka Alpha Cygnus wrote:
it would really be nice if one could type something like this:
x = {}
with x do
  a=3
  b=5
  c="this is x.c"
end

print(x.a+x.b) --> 8

I'd rather specify explicitly which members of a table that I want to access within a local scope.

I'd like "local sin, cos in math" to allow the unqualified use of the
names "sin" and "cos" within the local scope. In this scope, the other math functions would have to be fully qualified as "math.tan" and "math.pi"

This idea was proposed before, but it got dropped because some of the other ideas that came with it were "too complex", and the authors found a more general way to handle globals:
http://lua-users.org/lists/lua-l/2002-04/msg00098.html

But every time I type:

 local find = string.find
 local sub  = string.sub

I wish I could have typed:

 local find, sub in string

In your example, you could type:

x = {}
do
 local a,b,c in x
 a=3
 b=5
 c="this is x.c"
end

under the covers, this would be the same as:

x = {}
do
 local _temp = x
 _temp.a = 3
 _temp.b = 5
 _temp.c = "this is x.c"
end

One of these days, I'm going to write a patch for this.

- Peter Shook

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail