Why people call local function at the begining of a file.

I’ll take an exemple. Faphack, at the begining of the file the’re is that:
[lua]
local math = math
local string = string
local debug = debug
local table = table
local pcall = pcall
local error = error
local ErrorNoHalt = ErrorNoHalt
local MsgN = MsgN
local Msg = Msg
local print = print
local surface = surface
local util = util
local type = type
local RunConsoleCommand = RunConsoleCommand
local CreateClientConVar = CreateClientConVar
[/lua]
Why?

it bypasses basic anti-cheats

It’s optimization. When you try to access a variable in Lua, it first looks from the local variables, then the global. When you make the variables local, it speeds up the lookup.

Something like that, I’ve never really investigated the Lua insides.

[editline]03:29PM[/editline]

This too. When you store a local copy of a function, any changes after that won’t apply to your local variable.

Ok, thanks!

It’s also used in modules, to make them accessible within it.

And this too, since by default modules can only access the local environment, unless you use package.seeall, which exposes the global environment to the module. (hint: don’t use it)

This and if you don’t make it local it will become a global which could fuck with other addons

Not exactly. What he meant is saving a local copy of a function.

I did this in FapHack for two reasons:

Locals are accessed faster than globals,
If someone overwrites the function, I still have the original copy.