“–” normally starts a comment. This change could lead to confusing syntax errors. For example: “‘by’ is not expected.”
Huh? It has everything to do with how ROBLOX changed the language from simple additions like Vector2 to things like workspace.
Its everything that makes Roblox’s implementation of Lua different than vanilla.
Ditching ++ and – is fine since +1 or -1 you don’t really save any time unlike *= /= += -=
+= 1 serves ++ purpose fine
There could be some benefits here.
x[myFunction()] = x[myFunction()] + 1
Could have a different meaning from:
x[myFunction()] += 1
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.
That case is definitely where things get complicated
x[myFunction()] += 1
might result in
local v0 = myFunction()
x[v0] = x[v0] + 1
Although this might be safer, considering functions might cause x to change
local a = x
local v0 = myFunction()
a[v0] = a[v0] + 1
This case is a bit simpler
script.Folder.Module[myFunction()].SomeValue.Value += 1
might result in
local a = script.Folder.Module[myFunction()].SomeValue
a.Value = a.Value + 1
This is the simplest case
a.Value += 1
would result in
a.Value = a.Value + 1
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.
I ran luac earlier:
local x = {}
-- 1 [1] NEWTABLE 0 0 0
x["test"] = 1
-- 2 [2] SETTABLE 0 -1 -2 ; "test" 1
x["test"] = x["test"] + 1
-- 3 [3] GETTABLE 1 0 -1 ; "test"
-- 4 [3] ADD 1 1 -2 ; - 1
-- 5 [3] SETTABLE 0 -1 1 ; "test" -
-- 6 [3] RETURN 0 1
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
https://www.lua.org/manual/5.1/luac.html
Source code contains a lexer, parser, and a code gen https://www.lua.org/source/5.1/:
Lua 5.1.5 source code - llex.c
Lua 5.1.5 source code - lparser.c
Lua 5.1.5 source code - lcode.c
Compare it to Java
java → javac → java bytecode → java vm (let’s pretend we’re not using a JiT compiler)
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.
It’s been a while since I’ve done anything with bytecode, but yes, we actually wouldn’t need new OP codes. It’s basically the same as just writing it out without the new operators, except for that local variable ADD trick you mentioned.
All things considered, the time you’ll save by writing x+=1 instead of x=x+1 is nothing compared to the time you’ll save by not getting into an argument about it.
me_irl
Fun fact: that wouldn’t change your money
local money = game.ReplicatedStorage.All.PlayerStats[tostring(player.TeamColor)].Money
money.Value = money.Value + 5
fix’d
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.