Lua 中有没有一种流行的方法来记录变量和函数参数的类型?
我正在寻找一种方法来记录 Lua 中的类型变量和函数参数。有办法吗?还有类似 LINT 的工具来检查这些类型吗?
I'm finding a way to note types variables and function arguments in Lua. Is there a way? And any LINT-like tool to check those types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不喜欢变量名称的编码类型。我更喜欢给变量提供足够明确的名称,这样它们的意图就很清楚。
如果我需要更多,我会在需要时使用类型检查函数:
函数
checkType
可以这样实现:这具有在执行时正确引发错误的优点。如果您有测试,您自己的测试将执行 LINT 操作,如果类型不符合预期,则测试会失败。
I don't like encoding types on variable names. I prefer giving the variables explicit enough names so their intent is clear.
If I needed more than that, I use a typechecking function when needed:
The function
checkType
can be implemented like this:This has the advantage of properly raising an error on execution. If you have tests, your own tests will do the LINT-stuff and fail if a type is unexpected.