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.
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.
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
As Greg pointed out already, the name you are looking for is self
.
However, be aware that Lua is not an OOP language any more than it is a purely procedural or functional language. It simply provides all the low level mechanisms to implement an OOP design. One of the design principles has been expressed as to "provide mechanism, not policy". Because of that, there is no way to guarantee that the environment you are running in even uses inheritance, or that you could find a parent for any given object.
It would be a good idea to review the sections of the Lua manual, Programming in Lua, and the Wiki that relate to OOP features: