- 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 the this file open a ll 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 loops. See how all of the instructions is implemented. Skip the De Tails 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 your. Abstract interpretation is used to find object names for Tracebacks. Does bytecode verific ation, too.
- lparser.c, lcode.c : Recursive descent parser, targetting a register-based VM. Start from Chunk () and work your IT through. Read the EXP Ression 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.
These are the LUA source reading sequences recommended by Luajit authors.
Leo, now written, is just a toy. If we want to improve him further, I think we have no such ability at present. So, I also want to turn to Lua. Even if it was a reference to Lua's internal design, the final imitation was made.
In the past, I have been searching the internet for a blog about LUA source analysis. These blogs really make me learn a lot, but not enough, because for me, these points of knowledge did not form a complete system. String, closure, virtual machine, memory management, co-process, ... I have only one-sided understanding of the internal realization principle of these things. So this time, I'm going to make a complete analysis of Lua's source code, take notes, and then continue playing with my Leo.
Lua-decided to start analyzing Lua's source code