Sorry, I now understand why you wrapped it. I need a metatable on the factory type/table, not on the constructed type. Duh :) Thanks, - Claire, ---------------------------------------- > From: claire_lewis@xxxxxxxxxxx > To: luajit@xxxxxxxxxxxxx > Subject: RE: Overriding FFI ctype constructors? > Date: Fri, 8 Jun 2012 17:49:23 +1030 > > > > I don't know the true nature of your opaque type, but I would wrap it > > in someting. > > I'm not even sure that I would need to wrap it to do that? > > Couldn't one just do: > > ffi.cdef[[ > typedef struct _cl_platform_id * cl_platform_id; > ]] > > > CLPlatform_mt = { > __index = { > new = function(params) > return opencl.create_new_platform_id() -- could even just use this direct as > new > end, > } > } > > cl_platform_id = ffi.metatype("cl_platform_id", CLPlatform_mt) > obj = cl_platform_id.new(params) > > > So, I guess it depends on the syntax you're willing to deal with, and how > > much > > auxilary structures you're willing to add to your interfaces. > > I am already adding metatables to various opaque structs/typedefs, so it's > not a big addition to put in a new(), certainly. > > I'm not sure I need the additional structures, but I guess I was mostly after > a way to make it behave the same as other structs with regard to FFI syntax. > I suppose there's no reason I couldn't wrap them all to do it this way, but... > > Anyway, this is certainly much neater than what I had. > > Thanks, > - Claire