可以 C++简化 Lua VM 实现?
对于那些浏览过 Lua C VM 实现的人来说,使用 C++ 会显着简化实现吗?
For those that have glanced through the Lua C VM implementation, would the use of C++ significantly simplify the implementation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
多年来,天才级工程师为该虚拟机付出了心血,使其尽可能简单,同时保持极高的可移植性(任何 ANSI C 编译器)和高性能(看看脚本语言的任何比较衡量标准)。除了这种努力之外,我看不出 C++ 还能如何简化任何事情。事实上,对于 C++,我担心该语言模糊重要的属性,例如成本模型。
For years, genius-level engineers have sweated blood over that VM to make it as simple as possible while remaining extremely portable (any ANSI C compiler) and highly performant (look at any comparative measure of scripting languages). Next to that kind of effort, I don't see how C++ can simplify anything. In fact, with C++ I'd worry about the language obscuring important properties like the cost model.
Lua 旨在成为一种嵌入式语言。因此,VM 的“实现”分为两个不同的部分:VM 源代码的创建以及将该代码集成到要部署的工件中。我怀疑你的问题是为了集中在第一部分。太糟糕了。第二部分,即集成,会发生很多次,并且通常在 C 中比在 C++ 中容易得多。
Lua is intended to be an embedded language. So the "implementation" of the VM comes in two distinct pieces: the creation of the VM source code, and the integration of that code in the artifact to be deployed. I suspect your question is intended to focus on the first part. Too bad. The second part, the integration, happens many times over, and is generally much easier in C than in C++.
C 能做的任何事情,C++ 都能做得更好。我一直认为 Lua 源代码非常难以阅读 - 在 64 位上给出了一些警告,尽管看起来还不错。
问题在于,整个用户数据的事情,对于暴露新类型来说确实不太好。我会考虑重新设计而不是重新实现。
Anything C can do, C++ can do better. I always thought that the Lua source was pretty damn hard to read - gave some warnings on 64bit, although it seemed to be OK.
The trouble is that the whole userdata thing, it's really not very good for exposing new types to. I'd look at a redesign rather than a reimplementation.