我有以下 Lua 元表类,我怎样才能向它添加一个析构函数,以便当某个条件到达时它会破坏创建的对象并将其值设置为 nil?
-------------------------------------------------
-- Arrow class
-------------------------------------------------
local arrow = {}
local arrow_mt = { __index = arrow } -- metatable
function arrow.new(x, y) -- constructor
local newArrow = {
position = { x = x, y = y }
}
return setmetatable( newArrow, arrow_mt )
end
function arrow:remove()
-- remove the object here
-- self = nil dosent work
end