Does LuaJIT support __gc for tables?

不羁岁月 提交于 2019-12-23 07:43:51

问题


Lua 5.2 (in contrast to 5.1) supports __gc for tables.

Has LuaJIT borrowed this nice feature?

(I did a google search, and examined LuaJIT's Change History but couldn't figure out the answer.)


回答1:


Just try it:

-- 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.



来源:https://stackoverflow.com/questions/19488814/does-luajit-support-gc-for-tables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!