Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does an object reference itself in Lua?

Tags:

oop

lua

roblox

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.

like image 546
Slim Avatar asked Jul 01 '09 01:07

Slim


1 Answers

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
like image 145
Greg Hewgill Avatar answered Sep 28 '22 20:09

Greg Hewgill