Le pregunta o noobs (nooby question)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Mogex
Prole
Posts: 15
Joined: Thu Dec 06, 2012 2:13 am

Le pregunta o noobs (nooby question)

Post by Mogex »

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.
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: Le pregunta o noobs (nooby question)

Post by xXxMoNkEyMaNxXx »

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 :crazy:

A colon does this:

Code: Select all

table:function(...)
means the same as

Code: Select all

table.function(table,...)
When you define a function like

Code: Select all

function table:function(...)
end
it's the same as defining it like this:

Code: Select all

function table.function(self,...)
end
where the argument 'self' is literally available in the colon definition.
Last edited by xXxMoNkEyMaNxXx on Tue Jan 22, 2013 1:58 am, edited 1 time in total.
User avatar
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)

Post by ejmr »

The colon in Lua is a short-cut for writing methods for classes. So these two function definitions are equivalent:

Code: Select all

function class:method ()
    return self
end

class.method = function (self)
    return self
end
This page has some links that may help explain it as well:

http://lua-users.org/wiki/ObjectOrientedProgramming
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 2 guests