Lua 5.1 虚拟机指令简明手册

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

A No-Frills Introduction to Lua5.1VM Instructions

Lua5.1虚拟机指令简明手册

作者Kein-Hong Man,esq.

版本0.1,20060313

Contents目录

1Introduction序言2

2Lua Instruction Basics Lua指令基础3

3Really Simple Chunks十分简单的程序块5

4Lua Binary Chunks Lua二进制程序快7

5Instruction Notation指令记法15

6Loading Constants加载常量16

7Upvalues and Globals Upvalue和全局变量20

8Table Instructions表指令22

9Arithmetic and String Instructions算术和字符串指令23

10Jumps and Calls跳转和调用28

11Relational and Logic Instructions关系和逻辑指令35

12Loop Instructions循环指令42

13Table Creation表创建48

14Closures and Closing创建和结束闭包52

15Comparing Lua5.0.2and Lua5.1比较Lua5.0.2和Lua5.156

16Digging Deeper深入探究57

17Acknowledgements致谢57

18ChangeLog&ToDos变更纪录&待做的57

“A No-Frills Introduction to Lua 5.1VM Instructions”is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License 2.0.You are free to copy, distribute and display the work,and make derivative works as long as you give the original author credit,you do not use this work for commercial purposes,and if you alter,transform, or build upon this work,you distribute the resulting work only under a license identical to

-1-

this one.See the following URLs for more information:

“Lua5.1虚拟机指令简明手册”遵循Creative Commons Attribution-NonCommercial-ShareAlike许可2.0。只要你给出原作者署名,不把本作品用作商业目的,即可自由拷贝、分发和展示本作品,以及制作衍生品,并且如果你修改、改变或拓展本作品,你只能遵循该同样的许可发布衍生品。更多信息见下面的URL:

/licenses/by-nc-sa/2.0/

/licenses/by-nc-sa/2.0/legalcode

-2-

1Introduction序言

This is a no-frills introduction to the instruction set of the Lua5.1virtual pared 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.

这是Lua5.1虚拟机指令集的简明介绍。与Perl或Python相比,Lua相当简洁,人们可以深入内部一探究竟。对于脚本语言或任何复杂系统,如不能了解其内部机制算不上真正掌握了。希望本文对该目的有些微帮助。

This introductory guide covers Lua5.1only.Please see the older document for the guide to Lua5.0.2virtual 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.

本文只涉及Lua5.1版,Lua5.0.2版虚拟机指令请看本指南的旧版。这么做是有意为之;Lua内部并非稳定不变或具有任何形式的标准化,所以千万不要认为Lua内部在版本之间是兼容的。

Output from ChunkSpy(URL:/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:/);it is licensed under the same type of MIT-style license as Lua5itself.

ChunkSpy(地址:/projects/chunkspy/)是我学习Lua内部时写的Lua5二进制块反汇编器,本文中的例子就是由它生成的。ChunkSpy的概要反汇编模式极似luac的清单模式的输出,不需你再学习新的清单语法。ChunkSpy可在LuaForge(地址:/)处下载,它遵循与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“Lua5”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.

-3-

相关文档
最新文档