How leonardoaramaki/lua-vm works
This repository is a small Lua 5.1 bytecode interpreter with a library API and a command-line runner. The main workflow accepts a Lua file, compiles it to bytecode, parses the chunk into function prototypes, and steps the VM through execution. The runtime also exposes global-variable and function-call APIs, plus print and a small math module. Relationships are based on the shown source; the VM excerpt is partial, so unsampled instruction behavior is not expanded.
Main entry points: lib.rs Lua API · proto.rs Function prototypes · value.rs Lua values · vm.rs Bytecode VM
Components 11
Entry points
- CLI runner
src/main.rs - Lua API
src/lib.rs
Bytecode loading
- Lua compiler
- Chunk parser
src/chunk.rs - Function prototypes
src/proto.rs
VM runtime
- Bytecode VM
src/vm.rs - Closures and globals
src/closure.rs - Lua values
src/value.rs - Print builtin
src/prelude.rs - Math builtins
src/math.rs
Other components
- Lua user
Connections 17
- Lua user → CLI runner: runs
src/main.rs - CLI runner → Lua API: creates and executes
src/main.rs - Lua API → Lua compiler: compiles file
src/lib.rs - Lua API → Chunk parser: loads bytecode
src/lib.rs - Lua API → Function prototypes: builds prototypes
src/lib.rs - Lua API → Bytecode VM: loads and steps
src/lib.rs - Chunk parser → Lua values: decodes constants
src/chunk.rs - Function prototypes → Chunk parser: converts function blocks
src/proto.rs - Function prototypes → Lua values: stores constants
src/proto.rs - Bytecode VM → Closures and globals: manages call frames
src/vm.rs - Bytecode VM → Function prototypes: fetches bytecode
src/vm.rs - Bytecode VM → Lua values: executes value operations
src/vm.rs - Closures and globals → Function prototypes: holds prototype
src/closure.rs - Closures and globals → Lua values: stores globals
src/closure.rs - Lua values → Function prototypes: represents Lua functions
src/value.rs - Lua API → Print builtin: registers print
src/lib.rs - Lua API → Math builtins: registers math
src/lib.rs