Re: no custom metamethods for cdata

  • From: Evan Wies <evan@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 27 Mar 2014 16:03:40 -0400


On 03/27/2014 01:37 PM, Ronan Collobert wrote:
Ah, right -- you would need to use pcall for that.  I mocked up an improved 
version here:

https://gist.github.com/neomantra/9281334

LuaJIT compiles pcall, so it's probably performant.
— No, it is not performant.

I encountered the same issue described in this thread, and I am looking for a 
solution (but speed is really critical in my case).
pcall() is compiled by luaJIT, but in what you show you create a closure (which 
is NYI http://wiki.luajit.org/NYI).
Even if you defined the closure beforehand, you still have the problem that 
getting _serialize would be only compiled if you used rawset()… but that is not 
possible here, of course. Arg.

Ronan.


Thanks for pointing that out. I updated the gist with a loop so that the running it with -jv is useful and makes that issue clear.

So it appears that the trace aborted here (I use LuaJIT 2.1):
http://repo.or.cz/w/luajit-2.0.git/blob/refs/heads/v2.1:/src/lj_crecord.c#l722

If it is an __index operation and there is no metatable, can't it be specialized to return nil rather than aborting?

I tried to implement that myself but do not have the JIT-fu yet.

-Evan


Other related posts: