【发布时间】:2011-11-28 15:03:43
【问题描述】:
我正在使用 call_pv 从我的 C 程序中调用 perl 子例程。
我有两个问题:
C 程序如何找到该子例程在哪个 Perl 文件中定义?有什么地方可以定义 Perl 文件名吗?
如果 Perl 返回一个哈希引用作为输出,我如何在 C 中读取它?
这是我的 C 函数:
static int call_perl_fn(char* image)
{
dSP;
int count;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(image, 0))); //parameter to perl subroutine
PUTBACK;
count = call_pv("ImageInfo", G_SCALAR); //Invoking ImageInfo subroutine
SPAGAIN;
if (count != 1)
{
printf("ERROR in call_pv");
}
printf("VALUE:%s", (char*)(SvRV(POPp))); //How to read has reference output?
PUTBACK;
FREETMPS;
LEAVE;
return count;
}
【问题讨论】: