How do I implement OO with Lua Metatables?

前端 未结 2 775
囚心锁ツ
囚心锁ツ 2021-01-25 19:56

I\'ve never been able to fully wrap my mind about how Lua uses metatables to implement Object Orientation in its programming. I\'ve been reading over the online tutorial directo

相关标签:
2条回答
  • 2021-01-25 20:32

    Disclaimer: I'm the developer of MiddleClass

    I've developed a library for people like you. It's called MiddleClass.

    It conveniently hides the metatables so you can concentrate on object-oriented stuff. It's also reasonably commented out, should you want to take a look underneath.

    There's also a wiki page explaining how to use it.

    0 讨论(0)
  • 2021-01-25 20:36

    There are many ways to code up an OO feel in Lua. Lua goes for mechanism, not policy. The best possible source is the chapter in Roberto's book on Object-Oriented Programming. Definitely noob-friendly. Great book. The link is to the previous edition, which is free online. But you will want to buy the latest edition :-)

    0 讨论(0)
提交回复
热议问题