本文介绍了有没有办法从XS访问perl中的特殊令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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->packageCTX->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) or PL_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中的特殊令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:59