本文介绍了LuaJIT是否支持表的__gc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Lua 5.2(与5.1相反)为表支持__gc.
Lua 5.2 (in contrast to 5.1) supports __gc for tables.
LuaJIT借用了这个不错的功能吗?
Has LuaJIT borrowed this nice feature?
(我在Google上进行了搜索,并检查了LuaJIT的更改历史记录,但找不到答案. )
(I did a google search, and examined LuaJIT's Change History but couldn't figure out the answer.)
推荐答案
只需尝试一下:
-- 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
$
所以简短的答案是否".
So the short answer is no.
这篇关于LuaJIT是否支持表的__gc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!