Is there any tutorial on the internet about colons in lua or love2d and their functionality, what they do, and how they can be utilized?
Link me if you got one.
Thanks.
Le pregunta o noobs (nooby question)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: Le pregunta o noobs (nooby question)
A colon has one use, and one uselessness:
1. A colon can be used to separate the items in a table. (NOBODY does this though.)
2. A colon can be used in place of a white space character to mark the end of a line.
Whoops, that's a semicolon
A colon does this:
means the same as
When you define a function like
it's the same as defining it like this:
where the argument 'self' is literally available in the colon definition.
1. A colon can be used to separate the items in a table. (NOBODY does this though.)
2. A colon can be used in place of a white space character to mark the end of a line.
Whoops, that's a semicolon
A colon does this:
Code: Select all
table:function(...)
Code: Select all
table.function(table,...)
Code: Select all
function table:function(...)
end
Code: Select all
function table.function(self,...)
end
Last edited by xXxMoNkEyMaNxXx on Tue Jan 22, 2013 1:58 am, edited 1 time in total.
- ejmr
- Party member
- Posts: 302
- Joined: Fri Jun 01, 2012 7:45 am
- Location: South Carolina, U.S.A.
- Contact:
Re: Le pregunta o noobs (nooby question)
The colon in Lua is a short-cut for writing methods for classes. So these two function definitions are equivalent:
This page has some links that may help explain it as well:
http://lua-users.org/wiki/ObjectOrientedProgramming
Code: Select all
function class:method ()
return self
end
class.method = function (self)
return self
end
http://lua-users.org/wiki/ObjectOrientedProgramming
Who is online
Users browsing this forum: No registered users and 1 guest