Garry's Mod Wiki

Concepts - self

What is self

self is just a quality of life variable added in Lua that represents whatever the function is called on. Lua automatically creates this variable when defining functions with the : symbol.

hopefully you know how variable assigning works and if you don't, read Beginner_Tutorial_Variables

Here is an example:

-- Using Lua Syntactical Sugar function myTable:anyFunction( arg1 ) PrintTable( self ) end -- Using Literal Definitions myTable.anyFunction = function( self , arg1 ) PrintTable( self ) end

The only difference between the ways are defined is if we let Lua define self for us, or if we want to define it ourselves