http://blog.csdn.net/cnjet/article/details/7023526
Online Lua 5.1 Source Code Browser
Recommended reading order:
- LMATHLIB.C, lstrlib.c:get familiar with the external C API. Don ' t bother with the pattern matcher though. Just the easy functions.
- Lapi.c:check how the API is implemented internally. Only skim this to get a feeling for the code. Cross-Reference to Lua.h and luaconf.h as needed.
- Lobject.h:tagged values and object representation. Skim through this first. You'll want to keep a window with this file open all the time.
- Lstate.h:state objects. Ditto.
- Lopcodes.h:bytecode instruction format and opcode definitions. Easy.
- Lvm.c:scroll down to Luav_execute, the main interpreter loop. See how all of the instructions is implemented. Skip the details for now. Reread later.
- Ldo.c:calls, stacks, exceptions, coroutines. Tough read.
- Lstring.c:string interning. Cute, huh?
- Ltable.c:hash tables and arrays. Tricky code.
- Ltm.c:metamethod handling, reread all of LVM.C now.
- Want to reread lapi.c now.
- Ldebug.c:surprise waiting for you. Abstract interpretation is used to the Find object names for Tracebacks. Does bytecode verification, too.
- LPARSER.C, Lcode.c:recursive descent parser, targetting a register-based VM. Start from chunk () and work your The through. Read the expression parser and the code generator parts last.
- Lgc.c:incremental garbage collector. Take your time.
- Read all the other files as you see references to them. Don ' t let the your stack get too deep though.
If you ' re-done before X-mas and understood all of it, you ' re good. The information density of the code is rather high.
Adapt from http://lua.iteye.com/blog/492260.
Ps:an optimized and extended LUA implementation, http://www.luajit.org.
Lua code reading (LUA source reading)