lua-users home
lua-l archive

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


t is a local reference (within test()) to the empty array. That reference is assigned to the "my" property of the parameter y. The array then has two references.
When the function test() returns, the local reference is dropped, but the parameter y (whose value is a copy of x which is also a reference) still contains the empty array that was assigned to t.
So yes, x.my will be valid after test() returns, so you get x == {my: {}}.


Le lun. 18 mars 2019 à 05:08, Dinesh Gandhewar <dagandhewar@gmail.com> a écrit :
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?

Kindly note -- line.
Thanking you,