Lua VM 指令:导言

1 Introduction

1 导言

This is a no-frills introduction to the instruction set of the Lua 5.1 virtual machine. Compared to Perl or Python, the compactness of Lua makes it relatively easier for someone to peek under the hood and understand its internals. I think that one cannot completely grok a scripting language, or any complex system for that matter, without slitting the animal open and examining the entrails, organs and other yucky stuff that isn’t normally seen. So this document is supposed to help with the “peek under the hood” bit.

这是一本Lua 5.1虚拟机指令集的基本介绍。相对于PerlPythonLua的简洁性使得相当容易了解它的工作原理[1]和理解它的内部实现。我觉得,如果不解剖动物和检查它的内脏、组织和其它一些通常情况下看不到的东西,是无法完全体验一门脚本语言的。希望本文对“内部探秘”能提供些许帮助。

This introductory guide covers Lua 5.1 only. Please see the older document for the guide to Lua 5.0.2 virtual machine instructions. This is intentional; the internals of Lua is not fixed or standardized in any way, so users must not expect compatibility from one version of Lua to another as far as internals are concerned.

这篇介绍性的指南仅仅涵盖了Lua 5.1。请参考以前的关于Lua5.0.2虚拟机指令集指南的文档。这是有必要的;无论如何,Lua的内部结构不是固定或者标准化的,因此只要牵扯到Lua的内部结构,用户没必要期望Lua版本之间的兼容性。

Output from ChunkSpy (URL: http://luaforge.net/projects/chunkspy/),a Lua5 binary chunk disassembler which I wrote while studying Lua internals, was used to generate the examples shown in this document. The brief disassembly mode of ChunkSpy is very similar to the output of the listing mode of luac, so you do not need to learn a new listing syntax. ChunkSpy can be downloaded from LuaForge (URL: http://luaforge.net/); it is licensed under the same type of MIT-style license as Lua 5 itself.

ChunkSpy (URL: http://luaforge.net/projects/chunkspy/)Lua字节块反编译器,它是我学习Lua内部结构时候写的,它的输出用作产生本文档的例子。ChunkSpy简要的反编译模式和luac列表模式的输出十分相似,故你完全没必要学习新的列表语法。ChunkSpy可以从LuaForge(URL: http://luaforge.net/)下载;它的许可证和Lua5本身的MIT风格的许可证属于同一类型。

ChunkSpy has an interactive mode: you can enter a source chunk and get an immediate disassembly. This allows you to use this document as a tutorial by entering the examples into ChunkSpy and seeing the results yourself. The interactive mode is also very useful when you are exploring the behaviour of the Lua code generator on many short code snippets.

ChunkSpy有交互模式:你可以输入一段源代码块,会立即得到反汇编码。这使得你可以用这篇文章作为教程,输入例子到ChunkSpy中,查看返回结果。当你浏览Lua代码产生器编译非常短的代码片段的行为时,交互模式同样很有用。

This is a quick introduction, so it isn’t intended to be a comprehensive or expert treatment of the Lua virtual machine (from this point on, “Lua” refers to “Lua 5” unless otherwise stated) or its instructions. It is intended to be a simple, easy-to-digest beginner’s guide to the Lua virtual machine instruction set – it won’t do cartwheels or blow smoke rings.

本文只是一个快速的介绍,因此并不试图全面或者专业的解析Lua虚拟机(这里Lua如无特别说明指的是Lua 5)或者它的指令。本问旨在成为一本针对初学者的简单的,易消化的关于Lua虚拟机指令集的指南——并不打算“刨根问底”[2]

The objective of this introduction is to cover all the Lua virtual machine instructions and the structure of Lua 5 binary chunks with a minimum of fuss. Then, if you want more detail, you can use luac or ChunkSpy to study non-trivial chunks of code, or you can dive into the Lua source code itself for the real thing.

本文的目标是涵盖所有的Lua虚拟机指令和Lua5字节块的结构。如果你想要了解更多的细节,你可以用luacChunkSpy学习复杂的代码块,或者你可以深入到Lua源代码中得到更多的东西。

This is currently a draft, and I am not a Lua internals expert. So feedback is welcome. If you find any errors, or if you have anything to contribute please send me an e-mail (to khman AT users.sf.net or mkh AT pl.jaring.my) so that I can correct it. Thanks.

本文只是草稿,我也不是Lua内部结构的专家。因此欢迎反馈意见。如果你发现任何错误,或你有任何要发布的东西,请发e-mail给我,我好纠正,谢谢。

 

  

 

 

原文地址

http://luaforge.net/docman/view.php/83/98/ANoFrillsIntroToLua51VMInstructions.pdf

 

[1].Topic: how to translate 'A Peek under the Hood'?

http://www.cjsdn.net/post/print?bid=39&id=156010

 

[2].刨根问底

http://www.zdic.net/cy/ch/ZdicE5Zdic88ZdicA815437.htm

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值