The Problem
As a Roblox developer, it is currently impossible to quickly change how my scripts are formatted and/or run specific operations without overly relying on function calls (which can be expensive at times and not produce the result I want).
The Examples
By this I mean the usage of things such as:
local function Operate(A, B)
return A + B;
end;
Where I would use Operate
as a function if I wanted a portion of my code to be synced and rely on the same operator. This wouldn’t be such an issue if say I just need to do something quick like add to a player’s stat, but it becomes more impacting performance-wise when attempting to make expensive calls and equations which I might change from time to time, but want to be synced with the same operator.
If this isn’t a good example then maybe something like quick script operations could be better.
Say I wanted to do x = x + y
multiple times with different variables around and don’t want to write this.That.Something.OtherThing.Value = this.That.Something.OtherThing.Value + y
over and over again and it being a single line means using locals wouldn’t help out much, or maybe when you just want to inline or predefine a bunch of numbers without taking up more LOADK or MOVE opcodes. (Such as by doing This + 5 > 10
vs This + localVariable5
)
The Proposal
The solution I propose is Lua preprocessors (like the macros and such we have in C, C++, etc) which there was syntax highlighting in for quite a while but no actual usage. I’m aware of more threads about pre-processors but they all seem to just ask “what happened to them?” rather than “can we have them?”
These could be implemented with the $
symbol or something like that.
For example:
$define plusEqual (a, b)(a.Something.Value = a.Something.Value + b)
plusEqual(ReplicatedStorage.Stuff, 5)
And $define
wouldn’t need to be the only preprocessor, as maybe $ifndef
and such can be used for disabling debug code to not be compiled when releasing a new update for your game. The idea is to keep code clean, efficient, and be able to debug with ease.
Final Thoughts
See here for a C++ explanation.
I see no issue with this as we wouldn’t be changing Lua’s opcodes, bytecode format or overall functionality and it would be more of a word-replacement prior to compile time. Any thoughts on this subject?