Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In your last line of code the my_state_t is really the "this" pointer. You're simulating OOP.


Yes!

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


This is miniature OOP and that puts you in "major catastrophe" territory according to some on this thread.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: