Code Comments
Programming Forum and web based access to our favorite programming groups.In order to avoid namespace pollution, I would like to do the following in C: SV* sv; char* cmd = "FileHandle->new(q(foo.c));"; sv = eval_pv(cmd, TRUE); Now, sv points to a class instance. Is there a way to call methods of the class from w/in C? Preferably, with arguments? TIA
Post Follow-up to this messageHello, elbob@mailinator.com wrote: > In order to avoid namespace pollution, I would like to do the following > in C: > > SV* sv; > char* cmd = "FileHandle->new(q(foo.c));"; > sv = eval_pv(cmd, TRUE); > > Now, sv points to a class instance. Is there a way to call methods of > the class from w/in C? Preferably, with arguments? Found in the book "Extending and Embedding Perl", page 265 (http://www.manning.com/jenness): char* tidy_string (char* input) { SV* result; setSVpv(DEFSV, input, 0); result = eval_pv("use Text::Autoformat; autoformat($_)", FALSE); if (SvTRUE(ERRSV)) return NULL; else return SvPV_nolen(result); } I hope this help. But have you tried to ask the question in the perl.xs group? regards, Reinhard
Post Follow-up to this messageAlso sprach elbob@mailinator.com: > In order to avoid namespace pollution, I would like to do the following > in C: > > SV* sv; > char* cmd = "FileHandle->new(q(foo.c));"; > sv = eval_pv(cmd, TRUE); > > Now, sv points to a class instance. Is there a way to call methods of > the class from w/in C? Preferably, with arguments? You can use call_method() for that. You first have to push 'sv' onto the stack followed by all arguments the method should receive. See perlcall.pod for details. Tassilo -- use bigint; $n=7142335034377028016139702633033737113 9054411854220053437565440; $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
Post Follow-up to this messageI was trying comp.lang.perl.xs. I *knew* I had seen that group before. Mucho gracias! I also got on the Safari group, so now I can access books like that. Can't get 'em where I am. El Bob
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.