lua-users home
lua-l archive

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


Thank you, Nick and Peter, for your help with this matter. Nick, your
summary of the VM code that Lua generates was very informative.

I think I'll go with the code that Peter suggested, which I have included
below in case somebody looks up this topic.

Thanks,
~Nick

> -- Use a 'do/end' block so that the local 'temp' does not pollute
> -- the name space.
> do
>   -- The local variable 'temp' is assigned a closure.
>   local function temp(self)
>     self.x = self.x + 1
>   end
>
>   -- Define the function 'create'. Every time it executes it
>   -- assigns a reference to the closure stored in 'temp'.
>   function create()
>     local e = {}
>     e.x = 0
>     e.update = temp
>     return e
>   end
> end