What is the purpose of "self"?

I was recently coding a module, and I noticed a keyword called self. I saw some of my friends use self as a variable when they coded a module. They also used it in functions. what is the purpose of self?

I was looking through the developer forum and the developer hub, but I didn’t find any solutions.

[/details]
any help is appreciated

self refers to the implicit variable returned when you define a function using method syntax:

local t = {}

function t:method()
  print(self) -- self here is t
end

It derives from the calling syntax t:method() where t will get passed as self. Its effectively a different way of calling t.method(t)

Here though, self is just being used as a regular old variable, nothing special about it. idk why linters even lint self when its nothing special outside of methods

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.