Re: Luajit interpreter question

  • From: Mike Pall <mike-1409@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 3 Sep 2014 20:23:01 +0200

lex pops wrote:
> What are metamethod continuations?

It's an implementation-choice for metamethods which allows a fully
resumable VM so you can yield across a metamethod call. This means
the complete state is contained in the Lua stack, there's no
implicit state in the C stack.

The simpler implementation choice (e.g. what Lua 5.1 does) is to
recursively invoke the interpreter on the metamethod. But then you
can't yield from a metamethod, since the C stack is 'in the way'.

Metamethods in LuaJIT 2.x implicitly do a function call. Apart
from constructing the new frame for the call it also leaves a
continuation there to differentiate it from a regular call.

When the call returns, the continuation is invoked to perform the
second half of the metmethod behavior. E.g. storing the result at
a location which depends on the invoking bytecode. Or branching,
depending on the truthiness of the result.

--Mike

Other related posts: