You are not logged in.

#1 2007-03-05 12:27:48

harlekin
Member
From: Germany
Registered: 2006-07-13
Posts: 408

Embed Perl into C++

Good day.
I am about to write a small IRC bot which shall be controlled by Perl scripts. I am thinking of a scripting interface I know from irssi but all documentation about how to embed Perl are related to C. If I try to do the same thing in C++ my application fails to compile when I include anything else than EXTERN.h and perl.h; for instance iostream.

I read something about libperl++ which seem to be what I need but I don't know where I can get further information. And google seem to be as unaware as me. Except that I want to pull in dependencies as little as possible. It would be great if I just need Perl.

My questions are:
How can I embed Perl into C++?
Can I use the way I would do it in C? (If not, why?)

And I would be even more thankful if you can give me some kind of documentation or how to to get started.

Thanks. (:
harlekin


Hail to the thief!

Offline

#2 2007-03-05 17:48:05

Stalwart
Member
From: Latvia, Riga
Registered: 2005-10-18
Posts: 445
Website

Re: Embed Perl into C++


IRC: Stalwart @ FreeNode
Skype ID: thestalwart
WeeChat-devel nightly packages for i686

Offline

#3 2007-03-05 18:23:26

harlekin
Member
From: Germany
Registered: 2006-07-13
Posts: 408

Re: Embed Perl into C++

Thanks. But I am writing this bot in order to learn; not to do something that nobody has done before or that will create a new experience of irc'ing.

If your post was anything else than "Stop it. Somebody has already done it. And this maybe even better.", I apologize and kindly ask where I find the information I asked for. Cannot see anything Perl relating.

But anyway. It was worth reading this code. Looks pretty clean.

Last edited by harlekin (2007-03-05 18:39:51)


Hail to the thief!

Offline

#4 2007-03-06 04:03:21

magnum_opus
Member
Registered: 2005-01-26
Posts: 132

Re: Embed Perl into C++

no the thing is ii works off a simple text file, so anything that is capable of reading and writing to a file can use it.
meaning you can just write the bot entirely in perl and just use perl's standard file i/o functions instead of having to figure out how to interface it with whatever.

Offline

#5 2007-03-06 05:07:14

harlekin
Member
From: Germany
Registered: 2006-07-13
Posts: 408

Re: Embed Perl into C++

That's fine. Definitely.

But my question is, as even summarized in my first post, how to embed Perl into C++. What I was trying to do was just to provide some background information.

Last edited by harlekin (2007-03-06 05:40:42)


Hail to the thief!

Offline

#6 2007-03-06 14:43:37

junglepeanut
Member
From: California
Registered: 2007-01-24
Posts: 145
Website

Re: Embed Perl into C++

I clearly do not know what you are doing, and read your post about google not having the answer. But to try and wet my tongue I did a simple search and many links came up the first link was about EP and the second is how to add perl to c++. I did not search any farther just posting my google results.

http://www.google.com/search?hl=en&clie … tnG=Search

Offline

#7 2007-03-06 14:49:07

Stalwart
Member
From: Latvia, Riga
Registered: 2005-10-18
Posts: 445
Website

Re: Embed Perl into C++

harlekin wrote:

Thanks. But I am writing this bot in order to learn; not to do something that nobody has done before or that will create a new experience of irc'ing.

If your post was anything else than "Stop it. Somebody has already done it. And this maybe even better.", I apologize and kindly ask where I find the information I asked for. Cannot see anything Perl relating.

But anyway. It was worth reading this code. Looks pretty clean.

No offence, i just offered you a way to write bot in lang you like and don't mess with low-level stuff. IRC protocol is quite boring - a while ago i wrote sample bot in python


IRC: Stalwart @ FreeNode
Skype ID: thestalwart
WeeChat-devel nightly packages for i686

Offline

#8 2007-03-06 15:56:25

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Embed Perl into C++

I know nothing about embedding perl.  I do, however, know C++ fairly well.  If you could provide complier errors, I could help you figure out what is wrong.

Offline

#9 2007-03-10 13:18:03

harlekin
Member
From: Germany
Registered: 2006-07-13
Posts: 408

Re: Embed Perl into C++

Sorry that I answer so late. I had much to do the last one and will have the next two or three weeks.

phrakture: I finally was able to compile the first test program from man perlemb:

#include <EXTERN.h>
#include <perl.h>

int main(int argc, char* argv[]) {
        PerlInterpreter *my_perl;
        my_perl = perl_alloc();
        perl_construct(my_perl);
        perl_parse(my_perl, NULL, argc, argv, (char**) NULL);
        perl_run(my_perl);
        perl_destruct(my_perl);
        perl_free(my_perl);
        return 0;
}

Using this Makefile:

FLAGS=-I/usr/lib/perl5/current/x86_64-linux-thread-multi/CORE -L/usr/lib/perl5/current/x86_64-linux-thread-multi/CORE -lperl -lm -lc -lpthread -lcrypt -ldb -ldl -lnsl -lgdbm -L/usr/local/lib

perlemb: perlemb.cpp
    g++ -o perlemb perlemb.cpp $(FLAGS)

But I don't know why it seems that I cannot include other libraries. For example, if I include iostream:

#include <EXTERN.h>
#include <perl.h>
#include <iostream>

/* the rest of the code doesn't change */

I am not able to compile the program. If I type in `make`, I'll get the following errors:
Following errors \o/

Do you have any suggestions?

junglepeanut: Thanks. I'll check this out too. But as I want to keep the dependencies low, I'll try first to do it with standard libraries. (:

Last edited by harlekin (2007-03-11 11:47:53)


Hail to the thief!

Offline

#10 2007-03-12 07:58:43

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Embed Perl into C++

Looks like those errors are do to craptacular perl C macros (but I don't know the exact errors, as I can't translate that).... try adding iostream *before* the perl headers

Offline

#11 2007-03-12 12:48:45

harlekin
Member
From: Germany
Registered: 2006-07-13
Posts: 408

Re: Embed Perl into C++

Thank you! That actually did the trick! (=

Sorry, I didn't recognize that the error output was in German.


Hail to the thief!

Offline

Board footer

Powered by FluxBB