XS question, calling anonymous function from C

  • Thread starter Tassilo v. Parseval
  • Start date
T

Tassilo v. Parseval

Also sprach (e-mail address removed):
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
 
E

elbob

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
 
R

Reinhard Pagitsch

Hello,

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
 
E

elbob

I 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top