More operators!

As a roblox developer, currently it is IMPOSSIBLE to make your code look attractive!

When doing an operation on a variable and using that variable in the operation, it makes sense to only have to type the variable on the left side, but NOOOOO, WE CANT DO THAT IN THIS ROBLOX LUA!

Other languages have operators such as:
x+=5 – adds 5 to x
x*=5 – multiplies x by 5
x-=5 – subtracts 5 from x
x/=5 – divides x by 5

This would turn code like:
game.ReplicatedStorage.All.PlayerStats[tostrong(player.TeamColor)].Money.Value = game.ReplicatedStorage.All.PlayerStats[tostrong(player.TeamColor)].Money.Value + 5

Into:
game.ReplicatedStorage.All.PlayerStats[tostrong(player.TeamColor)].Money.Value += 5

Sure you could just set that object as a variable, BUT UR CREATING ANOTHER VARIABLE AND THATS INNEFFICIENT!!!
ARGH THE DILEMMA: BEAUTIFUL CODE OR EFFICIENT CODE! THIS IS AN ISSUE WE DEVELOPERS FACE EVERY FRAME ROBLOX!!

Furthermore these hot operators should be added too:
++x – increases x by 1 and returns the increased value
x++ – increases x by 1 and returns the original value
–x – decreases x by 1 and returns the decreased value
x-- – decreases x by 1 and returns the original value

This would turn:
game.ReplicatedStorage.All.PlayerStats[tostrong(player.TeamColor)].Kills.Value = game.ReplicatedStorage.All.PlayerStats[tostrong(player.TeamColor)].Kills.Value + 1

Into:
++game.ReplicatedStorage.All.PlayerStats[tostrong(player.TeamColor)].Kills.Value

AS YOU GUYS CAN SEE THE PERFORMANCE GAINS ARE HUGE (BECAUSE ROBLOX CAN PORT THESE OPERATIONS TO C++ WHICH IS WAY MORE EFFICIENT)! THIS NEEDS TO BE ADDED ASAP!!

16 Likes

but… that’s not Lua anymore…

17 Likes

Roblox needs to break free of barriers and transcend itself to show its true brilliance!

Plus code will look ultra clean and be like 0.000001 seconds more efficient LOL

3 Likes

Eh, assigning to a variable looks better tbh, but sure.

In bytecode it would probably do the same as just assigning a variable and doing var.field = var.field + whatever. For C++ instances, they could add “native” support, but that would be tricky, annoying and wouldn’t have that much effect.

1 Like

are you ok

29 Likes

Behave yourself as a professional on the developer forums… And I think your capslock is stuck…

Back to topic :
As @einsteinK mentioned, this is not Lua anymore and would be weird…

9 Likes

Well roblox can implement it in the way C++ implements it (pretty sure that’s more efficient)

Even if it isn’t, then it’s still a lot simpler and makes code cleaner and easier to read.

1 Like
local money = game.ReplicatedStorage.All.PlayerStats[tostring(player.TeamColor)].Money.Value
money = money + 5

It’s more efficient because C++ gets compiled and optimized by the compiler and it has direct access to memory. Not to mention, the checks for checking whether it’s a C++ instance to take the more efficient approach will slow everything down, including the efficient and non-efficient path.

Can’t really argue against the “makes code cleaner and easier to read”, but then again, it’s a big deviation from Lua. Technical aspects aside, that’s not something that’s easily done (from a mental perspective, but also a technical one)

3 Likes

it’s literally two things, dial down the spokesperson attitude

I don’t think I’m insulting anyone, I’m just adding a bit of humor to the post so it’s easier and funnier to read.

Also what does it matter if it isn’t lua? Is that in some way unorthodox?

Plus I’m pretty sure roblox is already vastly different than lua…

2 Likes

Well, there have been some changes sure… But the foundations of both are still the same.

I don’t remember Roblox having changed anything syntax-wise?

2 Likes

Okay fine I’ll stop, but I’d rather have one than two, wouldn’t you?

It’s not changing syntax, it’s a new feature/syntax, and roblox has added tons of new features such as new classes.

But… it’s new syntax…

New classes don’t change syntax

1 Like

Edited my post, key word is new, more features is better in my opinion because you have more options.

Also sorry for jumping on and off

I’m not 100% sure it’s more efficient either, but it wouldn’t be too hard to implement would it? I know I’m C++ it’s very easy to make your own custom operators.

Roblox would be making a new language. It’s unnecessary.

3 Likes

I think you mean it’s easy to overload operators, not create new ones. Also, Lua doesn’t really work like that anyway:

static void Arith (lua_State *L, StkId ra, const TValue *rb,
                   const TValue *rc, TMS op) {
  TValue tempb, tempc;
  const TValue *b, *c;
  if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
      (c = luaV_tonumber(rc, &tempc)) != NULL) {
    lua_Number nb = nvalue(b), nc = nvalue(c);
    switch (op) {
      case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
      case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
      case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
      case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
      case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
      case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
      case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
      default: lua_assert(0); break;
    }
  }
  else if (!call_binTM(L, rb, rc, ra, op))
    luaG_aritherror(L, rb, rc);
}

#define arith_op(op,tm) { \
        TValue *rb = RKB(i); \
        TValue *rc = RKC(i); \
        if (ttisnumber(rb) && ttisnumber(rc)) { \
          lua_Number nb = nvalue(rb), nc = nvalue(rc); \
          setnvalue(ra, op(nb, nc)); \
        } \
        else \
          Protect(Arith(L, ra, rb, rc, tm)); \
      }

https://www.lua.org/source/5.1/lvm.c.html#arith_op

2 Likes