Qeustion about _G and _R

Hi, I’ve been coding Lua for like 4-5 months but _G and some other things have confused me. I was recently browsing the anti-cheat thread and saw something about anti-cheats and cheats doing things like:

local _G = table.Copy(_G)
local _R = debug.getregistry()

What exactly do those things do? Obviously _G is some kind of table, but what is it used for? Also, what is debug.getregistry? What does that do? If anyone could enlighten me here or give a link to something that would be awesome. Thanks!

_G is global variables, someone else can probably explain debug.getregistry() better

_G is the Lua global table anything that’s globally available in Lua is in that table.

_R is the Lua registry, it no longer exists prior to GM13. The Lua registry can be retrieved, now, with debug.getregistry().

The Lua registry contains functions that are used on meta-tables, for example Entity.SetHealth is in the Lua registry under debug.getregistry().Entity.SetHealth.

If it helps, _G._G == _G

Ok so I can view the functions inside these tables using PrintTable?


ok yeah you can, thanks guys! However, one question. Why do anti-cheats/cheats make local copies of these tables?

For cheats, it’s to avoid anti-cheats detouring the functions they use, the same goes for ACs but in reverse. Anti-cheats create locals to avoid cheats detouring functions.

For example, if the server had an anti-cheat loaded that detoured the function print like this :
_G.print = function() end;

And if I loaded first, doing this :
local g = table.Copy( _G );

I could do this :

Without the server breaking it.

Oh I get it now. Thanks oubliette!