Lua sugar syntax double dots :

Using the sugar syntax : on Lua will allow us to access to the self table instance and for consecuent all methods and variables inside that specific class.

From Lua documentation we can read the following:

In the methods, we use a "self" parameter to get the instance to operate on. This is so common that Lua offers the : syntax sugar that calls a function entry from a table and inserts the table itself before the first arg.

And some code to illustrate the idea with an example:

Previous approach

That was how our code looks at the beginning:


local response = self.generateResponse(self, token)  


function clientCredentials.generateResponse(self, token)  
    return self.generateGeneralResponse(self, token)

As you can see we where passing the self object on each method call to be able to access others methods params in current instance

New approach

That's how our code should looks like from the beginning:


local response = self:generateResponse(token)  


function clientCredentials:generateResponse(token)  
    return self:generateGeneralResponse(token)

Note: Notice that we are using class inherance between clientCredentials and grantType, but that will be explained in another post