github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/lua/gc.lua (about)

     1  g = {}
     2  setmetatable(g, {__gc = function() print"gone" end})
     3  
     4  g2 = {}
     5  setmetatable(g2, {__gc = function() print"gone 2" end})
     6  
     7  meta = {__gc = function(t) print(t.gc) end}
     8  
     9  do
    10      local x = {gc = "local x"}
    11      setmetatable(x, meta)
    12      local y = {gc = "local y"}
    13      setmetatable(y, meta)
    14      local z = {gc = "local z"}
    15      setmetatable(z, meta)
    16      -- local t = {x, y}
    17  end
    18  
    19  -- When the runtime is closed, __gc metamethods should be called in reverse
    20  -- order.
    21  --> =local z
    22  --> =local y
    23  --> =local x
    24  --> =gone 2
    25  --> =gone