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

查看:58
本文介绍了如何使用Lua Metatables实现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.

任何人都可以对如何实现进行友好的解释吗?我正在为自己玩的游戏(不是《魔兽世界》)编写一些脚本,我想通过使用它来使代码更好.谢谢!

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中编写面向对象的感觉. 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 Metatables实现OO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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