Syntax sugar for Lua

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
4vZEROv
Party member
Posts: 113
Joined: Wed Jan 02, 2019 8:44 pm

Syntax sugar for Lua

Post by 4vZEROv » 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 :

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
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.

User avatar
ivan
Party member
Posts: 1703
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Syntax sugar for Lua

Post by ivan » Tue Jan 12, 2021 4:51 pm

Hi. I appreciate the work you put in but I noticed that the lib is based around string.gsub.
It will not work correctly with something like:

Code: Select all

var = "var++"
print(var)
Just a heads up, and keep working at it!

User avatar
4vZEROv
Party member
Posts: 113
Joined: Wed Jan 02, 2019 8:44 pm

Re: Syntax sugar for Lua

Post by 4vZEROv » Tue Jan 12, 2021 5:37 pm

ivan wrote:
Tue Jan 12, 2021 4:51 pm
Hi. I appreciate the work you put in but I noticed that the lib is based around string.gsub.
It will not work correctly with something like:

Code: Select all

var = "var++"
print(var)
Just a heads up, and keep working at it!
Yeah, as I said you should use hex values as workaround

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests