lua-users home
lua-l archive

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


Running the following in the Lua interpretter:

function tryThis()
  myVar = newproxy()
  print(myVar)
  local mt = getmetatable(myVar) or {}
  debug.setmetatable(myVar, mt);
  mt.__gc = function()
    print("!!! cleanup")
  end
end

function yup()
  setfenv(tryThis, setmetatable({}, { __index = _G }))
  tryThis()
  setfenv(tryThis, {})
  collectgarbage()
end

yup();

The following is output:
batrick@waterdeep:~$ lua test.lua
userdata: 0x806f9ec
!!! cleanup

I believe your problem is that you are expecting the environment to be
collected when a local variable has a reference to it =)

Cheers,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant