prometheus-lua / Prometheus

Lua Obfuscator written in pure Lua
https://levno-710.gitbook.io/prometheus/
GNU Affero General Public License v3.0
205 stars 61 forks source link

Suggestion - Luau compatibility - Add Ternary Operators #114

Open SpinnySpiwal opened 1 year ago

SpinnySpiwal commented 1 year ago

I Suggest adding Ternary Operators support for the following reasons:

For example, Ternary operators in Luau:

local CurrentHour = tonumber(os.date("%H"))
local Name = "SpinnySpiwal"
local TimeWelcome = if CurrentHour <= 6 and CurrentHour <= 12 then
    "Morning, " .. Name elseif CurrentHour >= 12 and CurrentHour <= 19 then
    "Afternoon, " .. Name elseif CurrentHour >= 19 then
    "Evening, " .. Name else "Error - Unknown Case"
print(TimeWelcome)

However, The above code snippet is much more compact compared to it's Lua 5.1 alternative:

local CurrentHour = tonumber(os.date("%H"))
local Name = "SpinnySpiwal"
local TimeWelcome
if CurrentHour >= 6 and CurrentHour <= 12 then
    TimeWelcome = "Morning, " .. Name
elseif CurrentHour >= 12 and CurrentHour <= 19 then
    TimeWelcome = "Afternoon, " .. Name
elseif CurrentHour >= 19 then
    TimeWelcome = "Evening, " .. Name
end
print(TimeWelcome)

Thank you for taking the time to read through my suggestion.

Brohammer5 commented 1 year ago

Agreed. I think this is a good feature. It allows Prometheus to obfuscate more LuaU code.

levno-710 commented 1 year ago

Implementing this would require to rewrite some of the code.

The following files would definitely need to be modified: visitast.lua compiler.lua parser.lua

There may be more.

I currently don't have time to work on this, but I would accept a pull request if somebody wanted to work on this.