lua-users home
lua-l archive

Re: local table constructor

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


Your proposed small change would also help make object functions use each other:
	local obj= { f1= function() ... end,
				 f2= function() obj.f1() end }
I've sometimes faced this dilemma, not sure how I dealt with it.
-ak
2.10.2004 kello 14:24, Milano Carvalho kirjoitti:
I would like to suggest a little change to table constructors related to local
variables. Let me explain...
The reference manual says that:
 " The statement
 local function f () ... end
 translates to
 local f; f = function () ... end "
I think that this meaning would be extended to table constructors as well:
 The statement
 local t = { ... }
 translates to
 local t; t = { ... }
This way a statement like
 local t = {f = function() print(t) end}; t.f()
would work as expected. Currently it prints nil (if previously it wasn't given a value to another variable also called 't'). It seems reasonable that 't' should be a table (that one which was just created) instead of nil or anything
else.
Differently the statement
 local t; t = {f = function() print(t) end} t.f()
works pretty well! As expected!
Is there some drawback of doing this change?
-- Milano Carvalho
_________________________________________________________________
MSN Messenger: converse com os seus amigos online. http://messenger.msn.com.br

AltStyle によって変換されたページ (->オリジナル) /