lua-从函数外部获取函数的参数名称列表 [英] lua - get the list of parameter names of a function, from outside the function
问题描述
我正在为我开发的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.getlocal
).
Take a look at debug.getinfo
, but you probably need a parser for this task. I don't know of any way to fetch the parameters of a function from within Lua without actually running the function and inspecting its environment table (see debug.debug
and debug.getlocal
).
这篇关于lua-从函数外部获取函数的参数名称列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!