I’ve been learning and using Lua for years, and today I decided to go over the built-in functions. And there, I saw “raw” functions. Now I bet these impact performance in some way, but my questions are:
What is the difference between “rawequal()” and “==”?
You’ll typically want to use the raw___ functions inside of metamethods. They don’t have much use outside of that, and as for performance, I’ve never seen any complaints with using equal symbols, so I don’t know if it’s worth comparing the performance of.
Unless you’re working with metatables, it’s better practice to use == whenever you’re checking if two values are equal.
You shouldn’t worry about the performance, as the difference is minimal.
If your game is lagging, it’s not because of the use of ==.
To elaborate on what everyone else is saying, the raw functions are used inside metamethods to prevent infinite recursion. Say you have a metamethod that fires when table1 is compared to any other table. If we were to attempt to determine whether table1 was equal to another table inside the __eq metamethod that was fired for the first comparison, it would fire again…and again…and so on until you crash or get an error about maximum re-entry/c-stack. The raw functions do not fire this metamethod.