Thanks Inny, Bartbes and Robin
I will give it another go today (GMT+10:00)
I will stick with doing things the simple/hard way for now so that I learn why things are done as they are.
PS: Robin, I had to look up the meaning of Omniscient so I am obviously not a member of that group lol.
I don't quite grasp what Robin said about 'something' being evaluated once. It looks to me that 'something' is being passed by refference rather than being evaluated. It will gell eventualy.
The problem for me is not what self does. The problem was what self doesn't do. Coming from many other 'curly bracket' languages, 'self' has a completely different meaning in Lua.
My programming history is -
1) Pre historic languages. COBOL, Fortran, Pascal
2) Hardware. Asm for old CPU's like Z80, 6502. Asm for PIC, AVR, ARM. Arduino (Sketch)
3) PC. BASIC, RapidQ, Windows API
4) Web. HTML/XHTML, PHP, MySQL, CSS, Javascript, jQuery, AS2 and anything that is NOT Microsoft. Developer / Server Admin / Domain Admin
Now. LÖVE / Lua just for a bit of fun. Programming shouldn't always be a hard grind.
Next. VHDL for FPGA. xilinx Spartan 3E to get me started. Asm for STM32F103 (RET6)
instance/scope of self
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: instance/scope of self
Well, 'something' can be any expression, a good example would be strings, for instance, something like this:Rob.m wrote: I don't quite grasp what Robin said about 'something' being evaluated once. It looks to me that 'something' is being passed by refference rather than being evaluated. It will gell eventualy.
Code: Select all
("a" .. "b"):rep(15):match("ab")
Code: Select all
a = {}
a.counter = 0
function a:bake()
self.counter = self.counter + 1
print("Baked cake number:", self.counter)
return self
end
function a:cake()
print("Yaaay, cake")
end
a:bake():cake() -- prints "Baked cake number: 0\nYaaay, cake"
a:bake().cake(a:bake()) -- prints "Baked cake number: 0\nBaked cake number: 1\nYaaay, cake"
Who is online
Users browsing this forum: Semrush [Bot] and 6 guests