静态类型 Lua
我正在寻找一个 Lua 前端编译器,它在编译时进行类型检查,但输出标准 Lua 5.1 字节码(仅具有运行时类型)。 我想要的是大量的静态、编译时语法分析和可选类型,以便比运行时更快地检测到微不足道的错误。 生成的字节码必须与使用标准 LoadString() 编译的现有 Lua 字节码很好地配合。
需要明确的是——任何差异只会发生在字节编译时。 在运行时,字节码不知道在编译阶段发生了任何不同/不寻常的事情。
我的想法听起来很像 ActionScript; 我什至不介意输出 Lua 字节码的 ActionScript 编译器!
有人听说过这样的努力吗? 我已经看到了一些使用 MetaLua 来做到这一点的参考,但老实说,我还不够聪明,无法清楚地了解他们的文档
I am looking for a Lua front-end compiler that is type-checked at compile time, but outputs standard Lua 5.1 byte-code (that has only run-time types). What I want is a decent amount of static, compile-time syntactic analysis and optional typing, to detect trivial errors sooner than run-time. The resulting byte-code would have to play nicely with existing Lua byte-code that was compiled with the standard LoadString().
To be clear -- any difference would only occur at byte-compilation time. At runtime, the byte code would have no idea that anything different/unusual happened to it during the compile phase.
What I have in mind sounds a lot like ActionScript; I wouldn't even mind an ActionScript compiler that outputs Lua byte code!
Has anyone heard of such an effort? I've seen some references to using MetaLua to do this, but honestly I am not bright enough to make heads of tails of their documentation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
大约在 2005 年夏天,我与一位非常聪明的本科生一起研究一些编译时问题Lua 的类型推断,可能需要注释的帮助。 事实证明这个问题非常难! (我的学生写了一篇简短的技术说明,但它并不是真正为了广泛传播而设计的。)
如果我想解决您提出的问题,那么它有两个限制:它允许重要的静态类型检查并且它与标准字节码编译的Lua代码进行互操作,
我会从头开始设计一种新语言来满足这两个约束。 这将是一项大量的工作,但比尝试将类型系统改造为 Lua 容易得多。
In the summer of 2005 or thereabouts, I worked with an incredibly smart undergraduate student on the problem of doing some compile-time type inference for Lua, possibly assisted by annotations. This problem turns out to be incredibly hard! (My student wrote a short technical note, but it's not really intended for general circulation.)
If I wanted to solve the problem you have posed, with the twin constraints that it allow significant static type checking and that it interoperate with standard bytecode-compiled Lua code,
I would design a new language from scratch to satisfy these two constraints. It would be a substantial amount of work but significantly easier than trying to retrofit a type system to Lua.
请参阅这篇 Metalua 博客文章。
不过,这看起来像是一个运行时解决方案。
无论如何,请随时在Metalua 邮件列表中提出您的问题。 如果你想扩展 Lua 语法,Metalua 是第一个要考虑的工具。
PS 请永远不要把Lua写成全大写!
Please see this Metalua blog post.
This is looks like a run-time solution though.
Anyway, feel free to ask your question in Metalua mailing list. If you want to extend Lua syntax, Metalua is the first tool to look at.
P.S. Please never write Lua as all-caps!
这个问题已经有六年了......但这里有一个新答案:http://terralang.org/
This question is six years old... but here's a new answer: http://terralang.org/
哪有这回事。 也许可以扩展 MetaLua 来做到这一点,但还没有人做到过,据我所知,没有计划这样做。 Lua 是一种动态语言,如果你想要一种静态类型语言,就使用一种。
您本质上正在寻找的是 Java 或 C# 之类的东西。 在这种情况下,您可以使用 Lua.NET 之类的项目来集成现有的 Lua 代码与 C#。 还有适用于 Java 的 Kahlua。
There is no such thing. It may be possible to extend MetaLua to do this but nobody has done it, and AFAIK, there are no plans to do so. Lua is meant to be a dynamic language, if you want a statically typed language, use one.
What you are essentially looking for is something like Java or C#. In that case, you could use a project like Lua.NET to integrate existing Lua code with C#. There is also Kahlua for Java.
PUC-Rio 刚刚在 Dyla'14 上发表了一篇新论文“Typed Lua:Lua 的可选类型系统”。 http://dl.acm.org/itation.cfm?id=2617553
它是关于“Typed Lua 的初始设计,Lua 脚本语言的可选类型扩展”。 它仍在进行中,并且类型系统仍然相对简单。 未提供类型推断/类型检查工具。
关于基于 Metalua 的类型系统,Tidal Lock:来自 Fabien 的 Lua 的可选静态类型检查和推理。 http://lua-users.org/lists/lua-l /2013-02/msg00403.html。
There is a new paper "Typed Lua: An Optional Type System for Lua" from PUC-Rio just published in Dyla'14. http://dl.acm.org/citation.cfm?id=2617553
It is about "initial design of Typed Lua, an optionally-typed extension of the Lua scripting language". It's still in progress, and the type system is still relatively simple. No type inference/type checking tool provided.
Regarding the metalua based typing system, Tidal Lock: optional static type checking and inference for Lua from Fabien. http://lua-users.org/lists/lua-l/2013-02/msg00403.html.
还有拉维
https://github.com/dibyendumajumdar/ravi
Ravi 编程语言是 Lua 5.3 的衍生语言,具有有限的功能可选的静态类型以及基于 LLVM 和 libgccjit 的 JIT 编译器
我真的很喜欢在 Terra 中编程(见上文)
There is also Ravi
https://github.com/dibyendumajumdar/ravi
Ravi Programming Language is a derivative of Lua 5.3 with limited optional static typing and LLVM and libgccjit based JIT compilers
I really enjoy programing in Terra (see above)
我推荐EmmyLua。
这是一个支持键入文档的 Intellij/VSCode 插件。 我发现整体记录方法非常友好。 另外由于其 IDE 支持,EmmyLua 还支持提示。
以下是 EmmyLua 文档的一个小片段:
有关更多文档参考,请检查 https://emmylua.github.io
I recommend EmmyLua.
This is an Intellij/VSCode plugin that supports typing documentation. I found the overall documenting approaching method to be very friendly. Also thanks to its IDE support, EmmyLua also support hinting.
Here is a little snippet for EmmyLua doc:
For more doc reference, check https://emmylua.github.io