Re: ffi.getmetatable

  • From: Karel Tuma <kat@xxxxxx>
  • To: luajit <luajit@xxxxxxxxxxxxx>
  • Date: Thu, 27 Nov 2014 21:42:25 +0100

Excerpts from Ronan Collobert's message of 2014-11-27 21:30:17 +0100:
> > Dubious use cases aside, what about:
> > assert(ffi.miscmap[-tonumber(ffi.metatype("struct {int 
> > x;}",{test=333}))].test==333)
> > Single line change, and JIT tracer friendly:
> > https://github.com/katlogic/ljx/commit/af7f5e8726a1d1608a711344a8742cb3873fae1f
> It does the job too — but in the end, giving access to miscmap is a 
> workaround to get to a CType metatable, 

Yes. The alternative would be to write trace recorder (otherwise argumenting 
performance is pretty moot).
Honestly, that would be too much of code bloat for corner case usage like this.

> given miscmap contains mostly CType metatables.

Only ctid->metatype and cdata->gcfinalizer AFAIK. Should cover all future 
exotic abuse of miscmap
- think of the horrors you can produce by writing in there :)

Other related posts: