22

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

Tadeusz A. Kadłubowski
  • 8,047
  • 1
  • 30
  • 37
Wilfred Springer
  • 10,869
  • 4
  • 55
  • 69

4 Answers4

54

The official definition is in lopcodes.h.

lhf
  • 70,581
  • 9
  • 108
  • 149
32

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. :-)

  • 1
    LuaForge was shutdown. So, your link is dead. Do you recall what project was involved? Perhaps it was migrated to github... – Judge Maygarden Feb 21 '12 at 05:30
  • The link now points to a Google Scholar search for that article. It returns hits on a number of different domains (including a direct link to the file on luaforge). –  Feb 22 '12 at 02:15
  • There is also a reference for Lua 5.3 bytecode here: https://github.com/dibyendumajumdar/ravi/blob/master/readthedocs/lua_bytecode_reference.rst – catwell Aug 05 '17 at 19:07
6

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.

Cogwheel
  • 22,781
  • 4
  • 49
  • 67
  • 1
    It is. Just like the _whole official Lua source code_. – jv110 Jun 21 '17 at 20:38
  • @jv110 You misunderstand. The Lua source code is merely a reference implementation of Lua, it is not "The" Lua. The only *specification* for Lua is the language itself, and the C API. Anyone can implement that specification using whatever underlying mechanics they want: VM, interpreter, FPGA/ASIC (physical chip). The creators of Lua have purposefully left it unspecified in order to make the language maximally flexible. – Cogwheel Aug 03 '17 at 14:55
  • 1
    You're missing the point. He clearly asked about the official bytecode, which is (by _far_) the most common implementation. It doesn't matter if other implementations use it or not. – jv110 Aug 03 '17 at 21:15
  • That's how you understand the intent of the question. As worded, this is a perfectly valid answer, if you interpret it a different way. It explains *why* he's having trouble searching for a specification. There isn't any. – Cogwheel Aug 04 '17 at 21:11
  • 1
    He asked where he can find it, not why he can't find it. That doesn't neither answer the question nor help him in any way. – jv110 Aug 05 '17 at 18:21
  • The other answers were already here and I referred to them at the end of mine. I didn't see any reason to say the same things as everyone else and just wanted to add some extra info to the conversation. I'm sorry that offends you. – Cogwheel Aug 10 '17 at 16:27
5

You can read The Implementation of Lua 5.0 online.

Shannon Severance
  • 18,025
  • 3
  • 46
  • 67
torus
  • 1,039
  • 2
  • 11
  • 26