Can I check strings equality in lua?

Howard Sun picture Howard Sun · Dec 24, 2014 · Viewed 53.9k times · Source

Just a straight forward beginner question, I am coding Lua stuff for Garrys Mod, learning by reading wiki and other codings.

if (self.Owner:SteamID( ) == "STEAM_0:1:44037488" ) then

the above is the code I want to use, to check to see if the STEAM ID (which I believe is a string) is equal to my exact string.

Is this viable? Or is there another way I should do it?

Answer

lisu picture lisu · Dec 24, 2014

This should work exactly as you expect it to. In lua '==' for string will return true if contents of the strings are equal.

As it was pointed out in the comments, lua strings are interned, which means that any two strings that have the same value are actually the same string.