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 c
andif 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
continue
which is a contextual keyword; - Garry's Mod's
continue
which 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
LuaSyntaxOptions
preset and then create aLuaParseOptions
from it. If no preset is picked,LuaSyntaxOptions.All
is used by default; - (Optional) Create a
SourceText
from your code (using one of theSourceText.From
overloads); - Call
LuaSyntaxTree.ParseText
with yourSourceText
/string
, (optional)LuaParseOptions
, (optional)path
and (optional)CancellationToken
; - Do whatever you want with the returned
LuaSyntaxTree
.