⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arrayret.i.old

📁 perl learn perl by examples
💻 OLD
字号:
%module ArrayRet

%{
char **
test (){
    static char * argv[] = {"abc", "def", "ghi", NULL};
    return argv;
}
%}

%typemap(perl5,out) char ** {   /* All functions returning char **  */
                                /* get this typemap                 */
    /* $source is of type char **
     * $target is of type RV (referring to an AV)
     */
    AV *ret_av = newAV();
    int i      = 0;
    char **p   = $source;
    /* First allocate a new AV, of the right size */
    while (*p++)
        ;            /* Incr. p while *p is non-null */ 

    av_extend(ret_av, p - $source);

    /* For each element in the array of strings, create a new
     * mortalscalar, and stuff it into the above array */
    for (i = 0, p = $source; *p; p++, i++) {
        av_store(ret_av, i, sv_2mortal( newSVpv(*p, 0)));
    }
    /* Finally, create a reference to the array; the "target"
       of this typemap */
    $target = newRV((SV*)ret_av);
    argvi++;
}

char **test();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -