lua-users home
lua-l archive

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


>A = function(t) -- constructor A
>	t.getName = function(self) return self.name end
>	return t
>end
>
>list = {}
>for i=1,1000 do
>	tinsert(list, A{name=i})
>end
>
>In list I have 1000 A objects, each one has its own instance of
>getName()

Just a fine point: Yes, in 4.0 1000 closures will be created, but they will
all *share* the same function body. So, the memory used is actually not so
high in real scripts because then the function body is much larger than a
closure.  (What I have called "function body" is called "Proto" in the
implementation, and it contains the bytecode for the function, all strings
and numbers, the names of the locals and some additional debug information.)
--lhf