Chinaunix首页 | 论坛 | 博客
  • 博客访问: 510761
  • 博文数量: 130
  • 博客积分: 10060
  • 博客等级: 上将
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-21 12:35
文章分类

全部博文(130)

文章存档

2011年(2)

2010年(9)

2009年(41)

2008年(78)

我的朋友

分类:

2009-04-29 00:05:29

1  Introduction 序言

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

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.

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

Output from ChunkSpy (URL: ), a Lua 5 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 Lua 5 itself.

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 “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”指的是“Lua5”)或其指令,而是简单、易于消化的Lua虚拟机指令集的新手指南-不会有特技或吐烟圈等高难度动作。

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内部的专家。所以欢迎反馈。如果你发现任何错误,或者要捐献任何东西,请给我发电邮(至khman AT users.sf.netmkh AT pl.jaring.my)以便我可以修正它。谢谢

阅读(700) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~