lua-users home
lua-l archive

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


> On Mar 17, 2019, at 9:00 PM, Dinesh Gandhewar <dagandhewar@gmail.com> wrote:
> 
> function test(y)
>   local t = {} --here t is local to funcion test
>   y.my = t
> end 
> 
> x = {}
> test(x) --here whether x.my is still valid?
> 

This isn’t a closure issue .. it’s just that tables are passed by reference. So your test() function is modifying the table in the global “x”, and so yes, after the call there will be a table in x.my that contains a table. This is nothing to do with capturing the “t” variable in test(), its just that the reference to the table in t is COPIED to y.my (when y references the same table as x).

—Tim