The Lua programming language, implemented in Rust.
The code is primarily grouped into three modules:
compiler
deals with parsing lua code and converting it into bytecode.lexer
converts Lua source code into tokens.parser
converts those tokens into bytecode.exp_desc
andtoken
are type definitions.
vm
is the largest module. It deals with actually evaluating lua code, and the Rust API.vm
itself holds the core functionality of the interpreter.frame
deals with evaluating bytecode.lua_val
defines the type for values in the VM.object
deals with garbage collection.table
implements Lua tables.
lua_std
is where any functions in the lua standard library are implemented.- Other modules:
error
defines theError
type used throughout the crate.instr
defines the VM's instruction set.lib
andmain
are the basic entrypoints for the library/interpreter.
The goals, in rough order of priority, are:
- Basic comparisons and equality
-
and
/or
expressions with proper short-circuiting - Basic strings
-
if
/else
/elseif
-
while
andrepeat ... until
loops - Local variables with proper scoping
- Numeric
for
loops - Multiple assignment
- Single-line comments
- Function calls
- Function definition
- Tables
- Garbage Collection
- Full table literals
- Error when line starts with left paren and parses as function call
- Multiple return values
-
break
andcontinue
- Interned strings
- Unparenthesized function calls
- Better error messages
- Closures
- Lua's
next
function - Generic
for
loops - Metatables
- Separate array part of tables for integer keys
- Lua's standard library
- A Rust API to parallel Lua's C API
- Coroutines
- Multi-line comments
- Use actual bytecode with variable-length instructions
- Separate
luac
executable
Like the real Lua, this project currently has zero dependencies.
Just run cargo run
in the root to launch the interpreter.
There are a few environment options which enable debug features.
These are all disabled by default.
To enable an option, just set it in the environment before compiling
(e.g. export LUA_DEBUG_VM=1; cargo build
).
For details on a debug option, look in the corresponding module.
The options are:
LUA_DEBUG_PARSER
LUA_DEBUG_VM
LUA_DEBUG_GC