如何使用 Lua 元表实现 OO? [英] How do I implement OO with Lua Metatables?

查看:22
本文介绍了如何使用 Lua 元表实现 OO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直无法完全理解 Lua 如何在其编程中使用元表来实现面向对象.我一直在阅读在线教程目录试图理解,但是作者是在考虑到有经验的程序员的情况下编写的,我不是.有了抽象的想法和对新手不友好的变量和解释,进行起来有点困难.这是 Lua 网站上面向对象页面的链接.

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 directory trying to understand, however the author wrote it with experienced programmers in mind, in which I am not. With abstract ideas and not-noob-friendly variables and explanations, going's been a little tough. Here is a link to the Object Orientation page on Lua's website.

任何人都可以就如何实现它给出一个新手友好的解释吗?我正在为我玩的游戏(不是 WoW)编写一些脚本,我想通过使用它来改进我的代码.谢谢!

Can anyone give a noob-friendly explanation of how to implement it? I'm doing some scripting for a game I play (not WoW), and I'd like to make my code better by using it. Thank you!

推荐答案

有很多方法可以在 Lua 中编写 OO 感觉.Lua 追求机制,而不是政策.最好的来源是 Roberto 书中关于面向对象编程的章节.绝对是菜鸟友好的.很棒的书.该链接指向以前的版本,可在线免费下载.但是你会想要购买最新版本:-)

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 :-)

这篇关于如何使用 Lua 元表实现 OO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆