本文介绍了lua - 从函数外部获取函数的参数名称列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在为我开发的 Lua 库生成一些(非 html)文档.我将手动生成文档,但如果可能的话,我希望能够实现某种自动化(即为每个函数生成骨架,以便我可以填写它们)

I'm generating some (non-html) documentation for a Lua library that I developed. I will generate the documentation by hand, but I'd appreciate some kind of automation if possible (i.e. generating skeletons for each function so I can fill them in)

我想知道是否有办法让 lua 从函数外部知道函数所采用的参数的名称.

I'd like to know if there's a way for lua to know the names of the parameters that a function takes, from outside it.

例如,有没有办法在 Lua 中做到这一点?

For example, is there a way to do this in Lua?

function foo(x,y)
  ... -- any code here
end

print( something ... foo ... something)
-- expected output: "x", "y"

非常感谢.

推荐答案

看一看 debug.getinfo,但您可能需要一个解析器来完成此任务.我不知道有什么方法可以从 Lua 中获取函数的参数而不实际运行该函数并检查其环境表(请参阅 debug.debugdebug.getlocal).

这篇关于lua - 从函数外部获取函数的参数名称列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:47