How to override luabind class __finalize method?
How to override luabind class __finalize method?
Trying to do this in such way:
class A
function A:__init()
end
function A:__finalize()
end
local original_finalize_function = A.__finalize
A.__finalize = function(...)
-- some custom logic
if original_finalize_function 开发者_如何学编程then
original_finalize_function(unpack(arg))
end
end
local a = A
a = nil
collectgarbage('collect')
But lua still calls only original finalizer. It does work for __init method however:
local original_init_function = A.__init
A.__init = function(...)
if original_init_function then
original_init_function(unpack(arg))
end
end
Also I've tried to override getmetatable(A).__finilize. Doesn't help too.
How can I override it? Thanks in advance.
Just a guess, but does finalize just go to __gc
?
Otherwise try iterating over the metatable to try and find out what luabind is doing: for k , v in getmetatable(myobject) do print(k,v) end
精彩评论