直接上程式碼
-- test.lua do local x = setmetatable({},{ __gc = function() print("works") end }) end collectgarbage("collect") collectgarbage("collect")
執行結果
$ lua51 -v Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio $ lua51 test.lua $ lua52 -v Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio $ lua52 test.lua works $ luajit -v LuaJIT 2.0.2 -- Copyright (C) 2005-2013 Mike Pall. http://luajit.org/ $ luajit test.lua $
結論:
lua 5.1、luajit不支援
lua5.2完美支援
終於找到一個升級為lua5.2的理由了