{ my $static_var = 0; sub return_op { say "in return_op: $static_var"; return $static_var; } } #### int main(.......) { ...... // return value test { cout<<"### return value test"<call("return_op",true,false); pppStack re2 = interp->call("return_op",true,false); } ,,,,,, } #### class pppInterp { public: ......// a lot of methods here pppStack call(string subname, bool want_re, bool want_array); pppStack call(string subname, pppStack& args, bool want_re, bool want_array); protected: // the interpreter only has this one property static bool inited; PerlInterpreter* my_perl; } // // the method implementation // pppStack pppInterp::call(string subname, bool want_re, bool want_array) { pppStack empty; return call(subname,empty,want_re,want_array); } pppStack pppInterp::call(string subname, pppStack& args, bool want_re, bool want_array) { // enter sub SPAGAIN; ENTER; SAVETMPS; // push args PUSHMARK(SP); pppStack::iterator it; int arg_count = 0; for (it=args.begin(); it!=args.end(); it++) { SV* arg_copy = newSVsv((*it)->get_internal()); sv_2mortal(arg_copy); XPUSHs(arg_copy); arg_count++; } PUTBACK; // call sub I32 flags = G_EVAL; if (arg_count==0) flags |= G_NOARGS; if (!want_re) flags |= G_DISCARD; if (want_array) flags |= G_ARRAY; else flags |= G_SCALAR; int re_count = call_pv(subname.c_str(),flags); // check eval if (SvTRUE(ERRSV)) { if (want_array) POPs; throw(SvPV_nolen(ERRSV)); } // fetch args pppStack re; if (want_re) { SPAGAIN; int i; for (i=0; i## ### return value test in return_op: 0 SV = PVIV(0xffd228) at 0xfebda0 REFCNT = 1 FLAGS = (TEMP,IOK,POK,pIOK,pPOK) IV = 0 PV = 0x1013fd0 "0"\0 CUR = 1 LEN = 8 in return_op: 0 SV = PVIV(0xffd240) at 0xfebf80 REFCNT = 1 FLAGS = (TEMP,IOK,POK,pIOK,pPOK) IV = 0 PV = 0x10102b0 "0"\0 CUR = 1 LEN = 8