gpt4 book ai didi

debugging - Squeak:在运行时获取方法的源代码

转载 作者:行者123 更新时间:2023-12-04 04:59:07 33 4
gpt4 key购买 nike

我正在编写一个小程序,它在 squeak 的运行时修改方法。
我看到在 squeak 中有一个方法叫做 getSource (在 CompiledMethod 类中定义),它返回已编译方法的源代码。

如果我的输入是与方法对应的符号,如何获取方法的源代码?

最佳答案

你应该知道方法定义在哪个类,然后你可以访问CompiledMethod通过,例如,

theClass >> methodSelectorSymbol


theClass compiledMethodAt: methodSelectorSymbol

theClass是具有方法的类和 methodSelectorSymbol是对应于方法的符号,即您的输入。
还有进一步的方法。
例如,
theClass lookupSelector: methodSelectorSymbol

不仅搜索 theClass但也在它的父类(super class)中。

但是,所有方法都要求您提供一个类作为起点。

关于debugging - Squeak:在运行时获取方法的源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16356549/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com