Optional C-style elements in Lua

In the interest of personal preferences, I think it would be cool if we could optionally use C-styled operators in Lua, by making it so Roblox does some string manipulation to the source of the script before pushing it to the LuaVM.

This table shows some examples of what could be added, and how they would be changed in order to make sure the LuaVM can interprete them correctly:

Operator Replaced with
&& and
|| or
!= ~=
!a not a
b = ++a b = a + 1
a = b
b = a++ b = a
a = a + 1
a += 5 a = a + 5
a -= 5 a = a - 5
a *= 5 a = a * 5
a /= 5 a = a / 5
// Comment -- Comment
/* Comment */ --[[ Comment ]]--

I’m not sure how tricky it would be to interpret the ++/-- operators, given the logical order of instructions, but I think it’s doable in principle. Block comments might also be tricky, though they could probably just be cut out of the string entirely

Having this feature would allow developers to have more preferences in the way they write their code, and in some scenarios, it would make things cleaner. While some may not agree with using C-syntax, is there any harm in having the option be there if you can still use the regular syntax if you’d like? I personally wouldn’t mind, and in some cases, it would make things easier for me to write.

25 Likes

I don’t think many people are in favor of branching further away from vanilla Lua. As a programmer I know a bunch of languages and I’m fine using different operators for each one so I don’t see why Lua should be different.

I wouldn’t be in favor of trying to bend Lua so I can pretend I’m writing C.

31 Likes

Stuff like += makes everyone’s life easier tho and probably wouldnt be hard to add.

12 Likes

I think that if you want extra operators like this you’re better off using something like MoonScript, or some other Lua superscript that is intended to compile to Lua.

6 Likes

If you’re wanting those operators plus some extra goodies, I’d check out MoonScript! Not only does it have a similar structure to Lua, it compiles directly into Lua itself. The project hasn’t seen many updates lately, but it works well enough that I’ve been using it in my personal projects + what not with no issues I haven’t been able to fix.

1 Like

I think this would be confusing for new users if it were part of stock Roblox. Imagine accidentally typing a C operator instead of valid Lua syntax and the editor not underlining it with error/warning. And if made optional, I don’t think that many people would be using it, because when you use them it means you can’t as easily share your code with other developers (because they might not have the setting toggled), and you can’t use your Lua code outside of Roblox without doing these translations first yourself, among other reasons such as readability of code.

This would work better as a plugin that either compiles the C operators out of the code after writing it, or a plugin that automatically does these translations every time you change lines in a script (so you hit enter and it would translate the line you just wrote into valid syntax). If they give us more control over the script editor in terms of events / where to set the cursor / etc, then making plugins like that would be possible.

4 Likes

Being able to select Lua or MoonScript on a per-project basis would be nice. Arbitrarily messing with Lua isn’t the way to go.

2 Likes

I get the point what @AbstractAlex mentioned.

On the other hand, I do think it’d be really convenient having those. Besides that, if someone is scripting, I’m almost 100% sure he or she knows what to do, meaning it shouldn’t be to hard learning those new oprators. If someone just started scripting, he or she has to learn everything still anyway, meaning that whether it’s this or that doesn’t matter in my opinion.

I’m not sure about the internal problems code-related (e.g performance issues, etc.) but it does seem like a good idea to me outside those problems.

Let’s not.

9 Likes

Has moonscript support for syncing studio script to/from filesystem.

3 Likes

Programmers are already use to adjusting to different languages, I don’t understand what this helps with?

I like the idea of writing moonscript, and compiling that to Lua and copy and pasting that into studio if you want to do that tho

@Lilly_S Can you close this? It’s apparent that no one wants this to be added.

1 Like

Or we could just get C# support. I’ll die on this hill.

8 Likes

I asked about this at RDC.
An admin told me that if they do go forward with trying to, it would be a massive undertaking that would take around 2 years to do, though I wouldn’t take it as concrete fact.

1 Like

Wouldn’t it be quicker and more efficient to get C++ because that’s what Roblox is written in? C++ support would be awesome

Nope that is not how that works.

I won’t list off every issue with this but you’re proposing compiling people’s code alongside the roblox sourcecode which would mean having to download a new client for every game you join (on top of a security nightmare)

The advantages of languages like C#, Java, and scripting languages is that they run in their own virtual machine and wouldn’t need to be compiled and distributed with the rest of the client.

4 Likes
1 Like

There is a handful of things C did wrong. This is one of them.

7 Likes