3 ms·
In your last line of code the my_state_t is really the "this" pointer. You're simulating OOP.
by breadwinner 2y ago
In your last line of code the my_state_t is really the "this" pointer. You're simulating OOP.
- mrkeen 2y agoYes! Once you take away inheritance ("prefer composition"), polymorphism (better offerings elsewhere), encapsulation (not encapsulation!), message-passing (better offerings elsewhere), you're left with a small syntactic trick that really wasn't that hard to do in C. Even Lua gives you that [1]: > This use of a self parameter is a central point in any object-oriented language. Most OO languages have this mechanism partly hidden from the programmer, so that she does not have to declare this parameter (although she still can use the name self or this inside a method). Lua can also hide this parameter, using the colon operator. function Account.withdraw (self, v) self.balance = self.balance - v end function Account:withdraw (v) self.balance = self.balance - v end [1] https://www.lua.org/pil/16.html https://www.lua.org/pil/16.html
- breadwinner 2y agoThis is miniature OOP and that puts you in "major catastrophe" territory according to some on this thread.