Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

accessing functions of embedded perl class

by opensourcer (Monk)
on Feb 02, 2005 at 06:06 UTC ( [id://427159]=perlquestion: print w/replies, xml ) Need Help??

opensourcer has asked for the wisdom of the Perl Monks concerning the following question:

Monks/Sanits, i have class say smallp.cpp and i have build into smallp.exe.
now the smallp.cpp is no longer available

/* ####################################### */ // 04-01-2005 v.01 // copyright opensourcer 2005 // open_sourcer@yahoo.com /* ####################################### */ #include "iostream.h" #include "EXTERN.h" #include "perl.h" #include "disovery.h" /*contains two functions called divide (arg1, ag +r2) and minus (arg1 and agr2) */ class emb_perl { private: PerlInterpreter *my_perl;//pointer to P interpreter public: emb_perl(){} //default constructor ~emb_perl(){} //default distructor //function void P_Perl(int argc, char **argv, char **env) { int *args [] = { NULL}; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, argc, argv, (char **)NULL); perl_run(my_perl); //perl_eval_va("add",2,3, NULL); perl_destruct(my_perl); perl_free(my_perl); } // fuction to add two number :D int add () { return (2+3); } void main (int argc, char **argv, char **env) { emb_perl SmallP; discover D; // instance of class discovery.h SmallP.P_Perl(argc,argv,env); } /* The End*/
when i write a perl code i want to use the functions add, minus and devide or at least add function in perl code
#- start code - pcode.pl #!/usr/bin/perl -w $return = add (1,2); print $return; #- end of perl file -

i'll be compiling the code like this (smallp pcode.pl) instead of (perl pcode.pl)

remeber i don't have smallp.cpp i have it build into exe

Plz excuse if me if my english is wrong

Thanks a lot
opensourcer
"I really don't live on earth, it's just my reflection" "open source is not only technology, but it's a world out there - opensourcer"

Replies are listed 'Best First'.
Re: accessing functions of embedded perl class
by Corion (Patriarch) on Feb 02, 2005 at 07:36 UTC

    After your smallp.exe has been compiled, all information about the function add has been lost. So you will not be able to reach the function from Perl code. If you can recompile smallp.exe again, or have access to the source code of smallp.exe, then you can use that, and see how Inline::C does its magic. But without the source code you will not be able to do it.

Re: accessing functions of embedded perl class
by robot_tourist (Hermit) on Feb 02, 2005 at 11:27 UTC

    Don't apologise for your English.

    ++Corion. It may be possible to disassemble the binary, but you would have to be getting a lot back for your effort, and be fluent in assembler. If smallp.cpp really is small, then it may be easier to rewrite. It might be better the second time. And you could do it in Perl.

    How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
    Robot Tourist, by Ten Benson

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://427159]
Approved by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-23 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found