Lua可以在什么编程范式下使用?

发布于 2024-12-12 22:04:11 字数 126 浏览 3 评论 0原文

我已经做了一些关于 Lua 编程的研究,但我仍然对它可以在哪种范式下工作感到困惑。

在一些演练中,我发现 Lua 并不是为面向对象编程而设计的。但其他人也认为它也适用于 OOP。因此,我正在寻找它在哪种编程范例中效果最好。

I've done some research about Lua programming but I'm still confused about under which paradigm it can work.

In some walkthroughs, I've found that Lua is not made for Object-Oriented Programming. But they are other people that says it can work too for OOP. So, I'm looking in which programming paradigms it can work the best.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

带上头具痛哭 2024-12-19 22:04:11

Lua 是一种“做你想做的事”的编程语言。它不选择范式;它是一系列有用的功能,让您可以自由地使用您需要的任何范例。它没有函数式语言功能,但它具有作为第一类对象的功能和适当的词法范围。因此,如果您愿意,您可以在功能上使用它。它没有“类”或其他此类原型,但它确实具有封装数据的方法以及用于使用“this”对象调用函数的特殊语法。所以你可以用它来构建对象。

Lua 并不决定你用它做什么;而是决定你用它做什么。这取决于你。它提供了低级工具,使您可以轻松构建您想要的任何范例。

Lua is a "do what you want to" programming language. It doesn't pick paradigms; it is a bag of useful features that give you the freedom to use whatever paradigm that you need. It doesn't have functional language features, but it does feature functions as first-class objects and proper lexical scoping. So you can use it functionally if you so desire. It doesn't have "classes" or other such prototypes, but it does feature ways to encapsulate data and special syntax for calling a function with a "this" object. So you can use it to build objects.

Lua does not dictate what you do with it; that's up to you. It provides low-level tools that allow you to easily build whatever paradigm you wish.

情泪▽动烟 2024-12-19 22:04:11

Lua 是一种命令式语言;因此它对于函数式编程来说并不理想。

就其本身而言,Lua 是一种过程语言。然而,鉴于其数据结构的简单性(它只有一个:表),很容易在其顶部添加一个“层”并使其成为 面向对象语言。最基本的继承规则只需 10 行代码即可实现。不过,有几个库可以提供更精致的体验。我的库 middleclass 总共有 140 个 LOC。

使用 Lua 的另一个好方法是作为脚本语言。它很小,速度很快,只使用标准的 C 语言,而且它的标准库很小。另一方面,它不像java那样带有“内置电池”。

最后,我发现它作为一种数据表示语言非常有用;您可以使用与 JSON 非常相似的格式来表达原始数据。

总的来说,我觉得Lua感觉很接近javascript。

Lua is an imperative language; so it is not ideal for functional programming.

Left by itself, Lua is a procedural language. However, given the simplicity of its data structures (it just has one: the table) it's very easy to add a "layer" on top of it and make it an object oriented language. The most basic inheritance rule can be achieved in as little as 10 lines of code. There are several libraries out there that provide a more refined experience though. My library, middleclass, is 140 LOC in total.

Another great way of using Lua is as an scripting language. It's small, fast, uses only standard C stuff, and it's standard lib is tiny. On the other hand, it doesn't come with "batteries included" like java does.

Finally, I find it very useful as a data notation language; you can express raw data in a format very similar to JSON.

In general, I think that Lua feels very close to javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文