Re: Best code for: C++ class -> C binding -> FFI

  • From: Rasmus Riiner <rasmus.riiner@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 10 Mar 2015 19:40:00 +0200

Thank you very much for answering, Mike, and apologies for the delayed response. It seems like __new answers all my prayers. :D Any nitpicks with this changed code? If not feel free to just not respond. :]



Class = ffi.metatype('aClass', {

   __new = function(self, _copy)
      if ffi.istype('aClass', _copy) then
         return C.aClass_copy(_copy)
      end
      return C.aClass_create()
   end,
   __gc = C.aClass_destroy,

   -- Equality checking etc are outside of __index
   __eq() = function(a, b) end,

   __index = {
      copy = C.aClass_copy,
      getNumber = C.aClass_getNumber,
      setNumber = C.aClass_setNumber,
   }
})


Man, thunderbird really did a number on the whitespace last time...

Other related posts: