为了获得当前的上下文,我找到了caller_cx函数perlapi.但是没有结构描述.在perl源代码中perl.h我只能找到这个typedef:
typedef struct context PERL_CONTEXT;
Run Code Online (Sandbox Code Playgroud)
是否有示例如何使用此结构返回caller_cx来从XS查找当前包?
该context结构被定义cop.h为通过@Dada在评论中提到:
struct context {
union {
struct block cx_blk;
struct subst cx_subst;
} cx_u;
};
Run Code Online (Sandbox Code Playgroud)
也block结构中所定义cop.h.
通过检查(第1850行)中Perl caller函数的C实现pp_ctl.c,我认为您可以使用以下代码获取包名:
const PERL_CONTEXT *cx = caller_cx(0, NULL);
char *pack_name = HvNAME((HV*)CopSTASH(cx->blk_oldcop));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
149 次 |
| 最近记录: |