Colon or Period?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Colon or Period?

Post by KawaGeo »

In the functions.txt file, many have colon and others, period. For example,

Code: Select all

Image Image.load( filename )
nil Image:save( filename )
I am somewhat confused between them. Can anyone explain the difference?

It is hard to remember which to use colon or period without understanding why.

Thanks.
Geo Massar
Retired Engineer
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Colon or Period?

Post by Shine »

Dots are used for kind of static functions, without an object, and colons are used, when calling a function on an object. E.g. i=Image.load("test.png") creates an object and i:save("image.tga") saves it and is a short form for Image.save(i, "image.tga").
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Reply in a nutshell, indeed. :)

Thanks.
Geo Massar
Retired Engineer
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

You can find the glory details in the Lua manual ( http://www.lua.org/manual/5.0/ ) and your dot and colon question at http://lua-users.org/wiki/SimpleLuaClasses . Lua Player uses something like the simple class model for Image, Music etc. internally, so it is not a pure Lua question, which is the reason why I didn't locked this thread :-)
Post Reply