Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion - Luau compatibility - Add Ternary Operators #114

Open
SpinnySpiwal opened this issue Jan 29, 2023 · 2 comments
Open

Suggestion - Luau compatibility - Add Ternary Operators #114

SpinnySpiwal opened this issue Jan 29, 2023 · 2 comments

Comments

@SpinnySpiwal
Copy link
Contributor

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.

@Brohammer5
Copy link
Contributor

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

@levno-710
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants