Re: ffi.getmetatable

  • From: Ronan Collobert <ronan@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 26 Nov 2014 11:51:07 -0800

Good point.

I have a case here (and from what I have read on the mailing list I am not 
alone), where I need to integrate FFI types into some other type checking 
system.
A classical way of doing type checking in Lua is looking at the metatable 
attributed to one object (or checking some field (like __typename) in the 
metatable of this object). Right now, it is impossible. There are workarounds. 
Like using tonumber(ffi.typeof()), and keeping some additional table which 
tells if the object is part of the type system or not, but that is quite ugly, 
where a simple ffi.getmetatype() could do the job.

From what I have read in previous post, you do not encourage playing with the 
type system. I totally understand that, but I am maintaining a large library, 
which includes many different modules, and which does not rely solely on FFI. I 
do have to merge two different worlds (classical Lua and FFI), unfortunately.

More generally when one hides something in the metatable (a global property of 
the “class” of a given object), right now one cannot retrieve it easily. Once 
in while, the case occurs, someone complains to me, and one has to play with 
the tonumber(ffi.typeof())+additional table trick.

Ronan.


> On Nov 26, 2014, at 9:31 AM, Mike Pall <mike-1411@xxxxxxxxxx> wrote:
> 
> Ronan Collobert wrote:
>> At this time there is no (easy) way with luajit+ffi to get the metatable of 
>> a cdata/ctype.
> 
> IMHO this is a classic instance of: http://xyproblem.info
> Why would you want to get the metatable of a cdata object?
> 
> --Mike
> 

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Other related posts: