Lua's bytecode specification [closed]

2019-02-03 06:27发布

问题:

Can anyone tell me where to find Lua's bytecode specification? I've been searching for 15 minutes, and I can't find anything.

回答1:

Maybe A No-Frills Introduction to Lua 5.1 VM Instructions contains what you're looking for?

There is also a table of the Lua 5.0 instruction set (Figure 5) in:

Ierusalimschy, R.; Figueiredo, L. H.; Celes, W. (2005), "The implementation of Lua 5.0", J. of Universal Comp. Sci. 11 (7): 1159-1176

You can find the full text with a search on Google Scholar and I believe it's on lua.org as well. This reference is used by the Lua page on Wikipedia, which is always a good place to look for such things. :-)



回答2:

The official definition is in lopcodes.h.



回答3:

The only specifications for Lua are the language, standard libraries, and the C API. The creators of Lua intentionally left the VM unspecified for a couple main reasons:

  • Lua can be fully implemented with any underlying architecture (VM, interpreter, compiler, etc.)
  • The official Lua distribution doesn't have to worry about maintaining VM compatibility between versions

This means, for example, that you generally shouldn't use the Lua VM as a target for a compiler. If you'd like to know how the official Lua distribution's VM works as an example for your own curiosity, see the other answers.



回答4:

You can read The Implementation of Lua 5.0 online.