Is there a way to access special tokens in perl from XS?

前端 未结 3 963
一个人的身影
一个人的身影 2021-01-04 10:25

In perl special tokens like __PACKAGE__, __SUB__, __FILE__, __LINE__ exists and available from script.

I may get

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 11:09

    The C equivalent to __FILE__ is __FILE__.

    The C equivalent to __LINE__ is __LINE__.

    The C99 equivalent to __SUB__ is __func__. There wasn't anything standard before.

    There's no C equivalent to __PACKAGE__ because C doesn't have namespaces.

    That said, I don't think you want information about the current line of execution; I think you want information about the XS sub's caller. That means you're actually asking for the XS equivalent of caller.

    The XS equivalent of caller is caller_cx. Looking at Perl_cx_dump in scope.c should give an idea how to use the returned PERL_CONTEXT structure.

提交回复
热议问题