r/lua • u/negativedimension • May 30 '25
Langfix: Pure-Lua fix for some things in the language, especially missing in LuaJIT
https://github.com/thenumbernine/langfix-luaI see there's a number of supersets of Lua going around, so I thought I'd advertise my option.
This adds familiar language features missing from Lua, including:
- arithmetic-combination operators (i.e.
+=etc) - short-hand lambdas: single-expression
|x| x^2or multiple-statements|x| do return x^2 end - safe-navigation:
a?.b?['c']?:d() - non-nil assertion:
a!.b!['c']!:d() - nil-coalescing:
a = b ?? cand ternary:a = b ? c : d - bit-operators for LuaJIT.
It is based on a pure-Lua parser, therefore you can use it as a drop-in to Lua anywhere, without any compiled components.
Tested and verified with Lua 5.4 and LuaJIT 2.1. I am half-suspicious you could even drop it into Pluto or Luau or any of these other Lua-superset competitors.
26
Upvotes
5
u/Motor_Let_6190 May 30 '25
Any plans on doing it as a Lua C module, using the C API (not FFI) so it stays Lua wide compatible?
3
u/smellycheese08 May 30 '25
Wow this is awesome! Also, for the tenary operator problem, you could use , instead of : which could make more sense. Or you could go the luau way and have syntax like
x = if y then z else 03
u/no_brains101 May 30 '25
do you offer a compileString sort of function that spits out lua or do I have to use the shim?
2
u/[deleted] May 30 '25
please enforce a newline or () on each ? : to prevent an unreadable mess.
2
u/Owen-Here Jun 05 '25
Lua+=