Prometheus icon indicating copy to clipboard operation
Prometheus copied to clipboard

Suggestion - Luau compatibility - Add Ternary Operators

Open SpinnySpiwal opened this issue 2 years ago • 2 comments

I Suggest adding Ternary Operators support for the following reasons:

  • It allows more compact, and efficient code.
  • Code Styling becomes simpler
  • Faster parsing and obfuscation time, since it is compact.

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.

SpinnySpiwal avatar Jan 29 '23 21:01 SpinnySpiwal

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

Brohammer5 avatar Feb 02 '23 19:02 Brohammer5

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.

levno-710 avatar Feb 11 '23 21:02 levno-710