r/lua • u/Cultural_Net_4377 • Jul 10 '26
Project I hated writing Lua so I made a language that compiles to it
Two reasons I started this: Lua's syntax and tables genuinely annoy me, and I wanted to build something that actually felt complex to work on.
The result is Lazarus - a statically typed language that compiles to a single self-contained .lua file. No runtime dependencies, which is the point if you're targeting ComputerCraft or any embedded Lua environment where you just drop a file and run it.
import std.print
some_str = "Hello World!"
constructor() {
print(.some_str) //.some_str is same as self.some_str
}Types are checked at compile time and completely erased. the Lua output has no type info at runtime.
So far the biggest goal I did is self hosting the compiler, which I think shows well that the language can be used.
https://github.com/NightmarePog/Lazarus
Now you may ask, why not just use lua?
For small projects, lua is definitely better, it's minimal, small, fast, does the job one, but when you do big projects where single bug could crash big app. for that Lazarus is there.
it has generic typing, static typing, macros, no null (instead Option<T> is used), lowering boilerplate (no local for every variable you declare)
PS: any feedback is welcomed
6
u/adbs1219 Jul 10 '26
Real doubt: what are the advantages over using Teal, Luau or TypeScriptToLua?
3
u/Alaska-Kid Jul 10 '26
Lulzarus
3
u/Old_County5271 Jul 10 '26
https://www.lazarus-ide.org/
1
u/suhcoR Jul 10 '26
Cool. You could also have used something like https://github.com/rochus-keller/luon/. What are you using the language for?
1
u/xoner2 Jul 11 '26
That's cool. Static typing is important for corporations, where multiple programmers work on a single code base.
Since there is a compilation stage might as well emit optimized byte code eh?
1
u/Liltful Jul 10 '26
Looks interesting! What versions of Lua can you target?
1
u/kcx01 Jul 10 '26
Kudos to you for getting it done! As long as it works for you and improves your experience.
I think for regular people, it's a lot of overhead. They would not just need to learn your language but how your language interops with standard Lua. I would imagine that the APIs would be written for Lua. So a user would need to know how to translate that to laz
I also think, while not perfect, some of the things that you're solving can be done within the Lua development environment.
For example, I use lua_ls for typing. It's not statically typed, but I get editor warnings if I try to assign a variable to a type that wasn't defined by my annotations.
I looked at some of the examples and am somewhat confused. The functions class for example doesn't actually expose any of the methods to the instance.
I think ultimately you're trading flexibility for complexity, and in general, I'd recommend learning and using Lua directly. (But you're also on a Lua sub reddit and opinions will be biased towards lua.)
0
u/AustinVelonaut Jul 10 '26
In
ExprFolderClass.laz, you might also consider adding folding of binary operators with identity constants, e.g.0 + x = x,x * 0 = 0,1 * x = x, etc. I have found that they occur about as often as the folding of two constants, due to inlining, etc.