A C# (G)Lua lexer, parser, code analysis, transformation and code generation toolkit. For getting started, see the tutorial.
This is (another) rewrite from scratch based on Roslyn and The Complete Syntax of Lua with a few extensions:
- Operators introduced in Garry's Mod Lua (glua):
&&forand;||foror;!=for~=;!fornot;
- Comment types introduced in Garry's Mod Lua (glua):
- C style single line comment:
// ...; - C style multi line comment:
/* */;
- C style single line comment:
- Characters accepted as part of identifiers by LuaJIT (emojis, non-rendering characters, or basically any byte above
127/0x7F); - Luau (Roblox Lua) syntax:
- Compound assignment:
+=,-=,*=,/=,^=,%=,..=; - If expressions:
if a then b else candif a then b elseif c then d else e; - Typed lua syntax.
- Compound assignment:
- FiveM's hash string syntax;
- Continue support. The following options are available:
- No continue at all;
- Luau's
continuewhich is a contextual keyword; - Garry's Mod's
continuewhich is a full fledged keyword.
TL;DR: This supports Lua 5.1, Lua 5.2, Lua 5.3, Lua 5.4, LuaJIT 2.0, LuaJIT 2.1, FiveM, GLua and Luau (Roblox Lua).
We have two NuGet packages:
| Package | Stable | Latest |
|---|---|---|
| Main | ||
| Experimental |
The best source for getting started is the tutorial.
- (Optional) Pick a
LuaSyntaxOptionspreset and then create aLuaParseOptionsfrom it. If no preset is picked,LuaSyntaxOptions.Allis used by default; - (Optional) Create a
SourceTextfrom your code (using one of theSourceText.Fromoverloads); - Call
LuaSyntaxTree.ParseTextwith yourSourceText/string, (optional)LuaParseOptions, (optional)pathand (optional)CancellationToken; - Do whatever you want with the returned
LuaSyntaxTree.