Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How does rawequal work in Lua and what are it’s uses?

Asked by 5 years ago

In the Lua reference manual it describes rawequal as:

Checks whether v1 is equal to v2, without invoking the __eq metamethod. Returns a boolean.

What does this mean? When would someone use it?

print (rawequal (3, 3)))

Thanks.

1 answer

Log in to vote
0
Answered by 5 years ago

_eq is a metamethod which checks if two integers are equal. Not really sure what the use would be, because you could still get the game's metatable and change the _eq function to be something something completely different, ex:

function func()
    return false
end
local a = {}
a.a = "a"
setmetatable(a,{__eq = func})

Haven't tested it, but if you ran that script in an environment that let you use the setmetatable function, and you tried to compare "a" with anything, it would return false for everything, even if you tried to do print(a==a). It's a pretty interesting concept. With the rawequal function, however, it would be much easier. You'd just need to get the global environment, and change the function to another function:

getgenv ().rawequal = function() return false end

much smaller.

Ad

Answer this question