Syntax sugar for Lua
Posted: Tue Jan 12, 2021 4:37 pm
I made a small Lua preprocessor that provide some sugar syntax for lua.
The code is here :
https://github.com/4v0v/m0nk3y
Stuff it allow to do :
There are some "bugs" :
Every '@' in your program will be replaced by 'self' even if it's in string
Same as '!' => not
So use the hex values if you want to use those symbols (\x21 \x40) in strings.
The code is here :
https://github.com/4v0v/m0nk3y
Stuff it allow to do :
Code: Select all
-- var = var + 1
var++
-- var = var + 5, there is also -=, *=, /=, ^=, %=, ..=
var += 5
-- if cond then elseif cond2 then end
if cond then elif cond2 then end
-- self.x = self:get_x()
@.x = @:get_x()
-- if cond1 and cond2 or not cond3 then
if cond1 && cond2 || !cond3 then
-- funtion(p1, p2) end
fn(p1, p2) end
-- for it = 1, 100 do print(it) end
for 100 do print(it) end
-- for key, it in pairs(table) do
-- print(key, it)
-- end
for tbl do print(key, it) end
for v in tbl do print(key, v) end
for k, v in tbl do print(k, v) end
-- for key, it in ipairs(tbl) do
-- print(key, it)
-- end
ifor tbl do print(key, it) end
ifor v in tbl do print(key, v) end
ifor k, v in tbl do print(k, v) end
Every '@' in your program will be replaced by 'self' even if it's in string
Same as '!' => not
So use the hex values if you want to use those symbols (\x21 \x40) in strings.