kikito / middleclass

Object-orientation for Lua
https://github.com/kikito/middleclass
MIT License
1.77k stars 190 forks source link

Question regarding method inheritance and overide when there are parameters #60

Closed koyan closed 4 years ago

koyan commented 4 years ago

Hi there, In the documentation, in the quick example we can read:

function Person:speak()

and then

function AgedPerson:speak()
  Person.speak(self) -- prints "Hi, I am xx."

How does one go to do the same but with a method that has parameters?

(Aka, if the first function Person:speak() had a parameter itself) like

function Person:speak(salutation)

I tried

function AgedPerson:speak(salutaion)
  Person.speak(self, salutation) 

But I didn't get it right.

Is this possible? Thanks

qaisjp commented 4 years ago

Person.speak(self, salutation) should work. Can we see more code, e.g. how are you calling AgedPerson:speak?

What does "didn't get it right" mean?

koyan commented 4 years ago

Sorry, when I went to recreate the example it works, so I probably did something wrong the first time :-( Please ignore/delete this issue.

qaisjp commented 4 years ago

Your problem is here:

function AgedPerson:speak(***salutaion***)
  Person.speak(self, ***salutation***) 

Your parameter is salutaion and you're using salutation.

I actually noticed this typo, but my brain auto-corrected it.

koyan commented 4 years ago

Thanks. Apparently when I tried to recreate it I did not do the mistake. That should teach me to copy/paste more instead of typing :-P