Page 1 of 1

Syntax sugar for Lua

Posted: Tue Jan 12, 2021 4:37 pm
by 4vZEROv
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.

Re: Syntax sugar for Lua

Posted: Tue Jan 12, 2021 4:51 pm
by ivan
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!

Re: Syntax sugar for Lua

Posted: Tue Jan 12, 2021 5:37 pm
by 4vZEROv
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