Page 1 of 1

[10 May 2008] Using the colon instead of the period as link in function call

Posted: Sat Jun 13, 2020 5:31 pm
by TheMartian
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 10 May 2008 18:00:37 -0000

Hi

While reading on page 22, column 2 in Amiga Future issue 72 about the latest 3.1 update for Hollywood I noticed that I could now use a colon instead of a period as link in a function call.

Can I ask some one to provide a small piece of code demonstrating how this is supposed to work. I have not seen (or missed it anyway) any references to this in the online manual.

Currently I use this approach to minimize typing and speed up the code...

Code: Select all

ItemList = {}
ItemList[0] = {}

Function Doh()
  local il = ItemList[0]
  il.name$ = "Some name"
  il.color = some_color
/* etc. */
EndFunction
and so on.... which works quite well. But perhaps that colon thing can be used to do something similar in a more 'elegant' way :-)

Thanks

Jesper

[11 May 2008] Re: Using the colon instead of the period as link in function call

Posted: Sat Jun 13, 2020 5:31 pm
by airsoftsoftwair
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 11 May 2008 12:23:48 +0200
Hi

While reading on page 22, column 2 in Amiga Future issue 72 about the latest 3.1 update for Hollywood I noticed that I could now use a colon instead of a period as link in a function call.

Can I ask some one to provide a small piece of code demonstrating how this is supposed to work. I have not seen (or missed it anyway) any references to this in the online manual.

Currently I use this approach to minimize typing and speed up the code...

Code: Select all

ItemList = {}
ItemList[0] = {}

Function Doh()
 local il = ItemList[0]
 il.name$ = "Some name"
 il.color = some_color
/* etc. */
EndFunction
and so on.... which works quite well. But perhaps that colon thing can be used to do something similar in a more 'elegant' way :-)
I think you misunderstood the function of the colon. The colon is used to call methods with an invisible "self" parameter. This behaviour is currently undocumented in the Hollywood guide, but you can read up on it here: http://www.lua.org/pil/16.html

[11 May 2008] Re: Using the colon instead of the period as link in function call

Posted: Sat Jun 13, 2020 5:31 pm
by TheMartian
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 11 May 2008 20:10:09 -0000

Ahh. Thanks. I get it...

As an example this does the trick:

Code: Select all

ItemList = {}
  ItemList.myNumber = 2
  ItemList.double_doh = Function(self,n) self.myNumber = 
self.myNumber*2 Return(self.myNumber) EndFunction

nprint(ItemList:double_doh(10))
Doing it this way the 'self' can be replaced by any identifier it seems. I tried 'cheese' instead of 'self', and it still worked :-)

regards Jesper