获取函数的 AST [英] Getting the AST of a function
问题描述
说我有一个函数:
function hi()
print('hi')
end
我希望能够将这个函数作为参数并对其进行分析,例如列出其中的所有函数调用,查看它引用的所有变量等.
I'd like to be able to take this function as an argument and perform analysis on it, such as listing all the function calls in it, seeing all the variables it references, etc.
请注意,我不是在谈论分析源代码;我没有函数的源文本,我只有函数对象,即这是在运行时完成的.
Note that I'm not talking about analysing source code; I don't have the source text of the function, I just have the function object, i.e. this is being done at runtime.
我认为您会这样做的方法是获取函数的 AST.但我不知道该怎么做.那么,我将如何获取函数的 AST(或者如果有更好的方法则对其进行分析)?
The way I think you'd go about doing this is to get the AST of the function. But I don't know how to do that. So how would I go about getting the AST of a function (or otherwise analysing it if there's a better way)?
推荐答案
你可能想试试我的 lbci,一个字节码检查器库.
You may want to try my lbci, a bytecode inspector library.
这篇关于获取函数的 AST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!