A long, long time ago I actually added += style operators to Lua as part of a patch to make its syntax more like C/Javascript. Also like C, it makes assignment into an expression so you can write a = (b += c) if for some reason you think that’s a good idea.
Here’s a diff against Lua 5.1.4. Obviously not to be considered production ready, or really tested at all - there’s thing or two I can see that I’d change if I did it again. The key bit for the += operator is testassign.
So adding operators to Lua certainly wouldn’t be beyond the ROBLOX developers, especially considering they’ve implemented things like __namecall. I have my doubts it would be a good idea to spend the effort to make a change like adding operators that makes ROBLOX Lua so incompatible with vanilla though.
Does this really matter when they’re small quality of life improvements? Its not like it takes 5 seconds to learn Obj +=1 can’t be used and instead you gotta use Obj = Obj + 1 outside of ROBLOX Lua. On top of this the community has always held ROBLOX’s implementation of Lua as its own kind of thing this is why people called it Rbx.Lua.
I mean its one thing to add new features like official classes but this is simply comparable to syntactic sugar. A short-hand way of doing something.
Lua was made to be modded and changed. Lua developers know this. I don’t see why its bad to deviate from it especially if you aren’t dramatically changing the language.
It’s more that if you wrote code originally for ROBLOX but that’s applicable elsewhere (it’s definitely possible in a large project to have bits that don’t touch ROBLOX API) you’d have to modify it to use it in regular Lua. The maker of GMod apparently felt similarly, though.
It is suggested to avoid using the custom operators if you wish to use your scripts outside of Garry’s Mod, as they are incompatible with standard Lua.
He still added custom operators though with simply giving that notice. I think this is perfectly acceptable. ROBLOX can do the same.
That has more to do with Roblox being a unique environment than with any implementation differences from vanilla lua, which are really only the components regarding files, like os and io.
In the first case, myFunction must be called twice. Perhaps it uses math.random, or modifies global state, or makes use of HTTPService. The second case could be defined to require only one call to myFunction.
In languages like C# in these instances, x is only evaluated once. This would also be the expected behavior because the whole point of syntax like += is take the value you get and perform arithmetic onto it without having to pointlessly declare the value again.
If your function can return multiple different results and you want different results then it seems to be the best to have it explicitly shown for better readability.
This is why a “+=” syntax could be useful beyond syntactic sugar. Lua makes very few compile-time assumptions. The “+=” operator could create a compile-time assurance that it is safe to use the reference from the left hand side expression without re-evaluation to get the right hand side value.
It only got interesting when more table references or where more function calls were duplicated.
An opcode version would likely be something similar to: “MODIFYTABLE” followed by “ADD”. There are already instructions that are followed by JMP or a non-instruction. This only adds a few instructions to support all arithmetic reductions.
There may be differences in error cases and error reporting in some cases.
Definition of compiler: a program that converts instructions into a machine-code or lower-level form so that they can be read and executed by a computer.
Lua source code is translated into Lua bytecode, a lower-level form in which the virtual machine interprets.
luac is a program explicitly defined as the “lua compiler” by lua themselves that can be used standalone
I don’t know what the heck y’all are talking about, but Lua should definitely not be abused in this fashion. Might as well write our own language explicitly for Roblox if we start modifying Lua’s core features and syntax.
Since when is adding syntactic sugar for a redundant coding pattern equivalent to writing your own language?
Thats not abuse.
Lua was intended to be modified.
I feel like people get on this out of hand slippery slope fallacy mindset.
Not everything is a slippery slope situation. I’m just saying that if we modify everything for the sake of convenience or to make it look pretty, we may as well just make our own language at some point.
This isn’t a necessary change, and so far the design philosophy for Roblox has been to not change things unless they’re necessary and/or in camelCase. It’s probably not gonna happen.
Not really. Lua is fine as is for the most part.
Give us moonscript as an alternative. Its a low effort lang, compiles to Lua.
They won’t update Lua because LuaJIT and porting efforts.