0

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.

kFk
  • 409
  • 6
  • 13

1 Answers1

1

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

daurnimator
  • 4,091
  • 18
  • 34
  • Don't know. __finalize is called before __gc. I've tried to override it, but got a crash. From lua reference: "__gc ... (can be set from the C side only)." *Metatable for class:* __index, __newindex, __luabind_classrep(true), __gc, __call. *Metatable for object (class intstance):* 1, __eq, __mul, __pow, __index, __call, __unm, __concat, __len, __newindex, __lt, __div, __tostring, __luabind_class(true), __gc, __le, __sub, __add – kFk Jun 21 '10 at 08:59