View Single Post
06/06/14, 02:01 PM   #4
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Originally Posted by Tar000un View Post
I also saw with a :, instead the dot.
In Lua, using the colon ( : ) instead of the dot makes a variable "self" available in the function.

For example:
Lua Code:
  1. local foo = {}
  2. foo.val = 1
  3.  
  4. function foo:bar()
  5.     d(self.val) --Prints 1
  6. end

When you fully define the tables, it's not as critical, since you can simply use the table name instead:
Lua Code:
  1. function foo.bar()
  2.     d(foo.val) --Prints 1
  3. end

Where it's most useful is object-oriented programming style, where you have the same function with different objects and need self to differentiate between them.
  Reply With Quote