问题描述
在perl中,特殊标记如__PACKAGE__
,__SUB__
,__FILE__
,__LINE__
存在并且可以从脚本中获得.
In perl special tokens like __PACKAGE__
, __SUB__
, __FILE__
, __LINE__
exists and available from script.
我想我可能会从XS
获得__PACKAGE__
的值作为HvNAME( PL_currstash )
.
但是如何访问其他人?
I may get value of __PACKAGE__
from XS
as HvNAME( PL_currstash )
, I suppose.
But how to access others?
是否有特殊的界面可以从XS
中访问所有这些人?像:CTX->package
,CTX->sub
等
Is there special interface to access all of them from XS
? Like: CTX->package
, CTX->sub
etc.
推荐答案
您可以在toke.c
中逐一查找它们的编译时值:
You can look them up one by one in toke.c
for the compile-time values:
-
__PACKAGE__
=>HvNAME(PL_curstash)
或PL_curstname
-
__FILE__
=>CopFILE(PL_curcop)
(在编译时) -
__LINE__
=>CopLINE(PL_curcop)
(在编译时) -
__SUB__
=>PL_compcv
__PACKAGE__
=>HvNAME(PL_curstash)
orPL_curstname
__FILE__
=>CopFILE(PL_curcop)
(at compile-time)__LINE__
=>CopLINE(PL_curcop)
(at compile-time)__SUB__
=>PL_compcv
如果在运行时需要它们,请查看上下文caller_cx
和当前子项(cv
)中可用的各种数据字段.没有像在parrot或perl6中那样传递上下文结构,而是一堆活动上下文块.
If you need them at run-time look at the various data fields available in the context caller_cx
and current sub (cv
). There's no context struct as in parrot or perl6 passed around, rather a stack of active context blocks.
这篇关于有没有办法从XS访问perl中的特殊令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!