直接上代码
-- 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的理由了