How does an object reference itself in Lua?

Slim picture Slim · Jul 1, 2009 · Viewed 14.4k times · Source

C# has this and VB has ME. What is the Lua equivalent?

I am trying to reference the parent of the script class in Roblox.

Answer

Greg Hewgill picture Greg Hewgill · Jul 1, 2009

From the Lua documentation section 2.5.9, the self reference is usually self:

The colon syntax is used for defining methods, that is, functions that have an implicit extra parameter self. Thus, the statement

function t.a.b.c:f (params) body end

is syntactic sugar for

t.a.b.c.f = function (self, params) body end