如何重写 luabind 类 __finalize 方法?
如何重写 luabind 类 __finalize 方法?
试图以这种方式做到这一点:
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')
但lua仍然只调用原始的终结器。然而它确实适用于 __init 方法:
local original_init_function = A.__init
A.__init = function(...)
if original_init_function then
original_init_function(unpack(arg))
end
end
我也尝试覆盖 getmetatable(A).__finilize。也没有帮助。
我怎样才能覆盖它?提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是一个猜测,但最终确定只是转到 __gc 吗?
否则,请尝试迭代元表以尝试找出 luabind 正在做什么:
for k , v in getmetatable(myobject) do print(k,v) end
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