in reply to Re^6: inline in a perl module
in thread inline in a perl module
-----------------main.h-----------------------I'm constructing : Global array I'm constructing : in add I am inside wow Destruction : in add 9 + 16 = 25 Destruction : Global array
-----------------main.cpp-----------------------#ifndef _nir_test_main #define _nir_test_main #include <string> using namespace std; class MyClass { public: MyClass(const char*); ~MyClass(); int wow(); private : string _my_favorite_argument; }; #endif
------------------test.pl----------------------------#include <stdio.h> #include "main.h" //extern int funcOuter(int); MyClass::MyClass(const char * a_my_favorite_argument) { printf("I'm constructing : %s \n",a_my_favorite_argument); _my_favorite_argument.append(a_my_favorite_argument); } MyClass::~MyClass() { printf("Destruction : %s \n",_my_favorite_argument.c_str()); } int MyClass::wow() { printf ("I am inside wow \n"); return 12 / 3; } int func(const int&); int main (int argc, char* argv[]) { //calling to a function from another so //funcOuter(4); printf ("hello \n"); int x = 10; func(x); return 0; } int func (const int& x) { printf ("in func : %d \n",x); return 0; }
Thanks, Nir#!/usr/bin/perl -w use lib '/usr/lib/perl5/vendor_perl/5.8.0'; use lib '/users/nirf/perlTrials/cpanModulesInstallation/lib/perl5/site +_perl/5.8.0'; use lib '/users/nirf/perlTrials/cpanModulesInstallationInline/lib/perl +5/site_perl/5.8.5'; #use lib '/users/nirf/perlTrials/cpanModulesInstallationParseRecDescen +t/lib/perl5/site_perl/5.8.5'; #use Inline Config => LIBS => '-L/users/nirf/perlTrials/inlineExample' +, LIBS => '-lmain'; #use Inline Config => LIBS => '-L/users/nirf/perlTrials/inlineExample +-lmain'; use Inline CPP => Config => INC => '-l/users/nirf/perlTrials/inlineExa +mple'; use Inline CPP => Config => MYEXTLIB => '/users/nirf/perlTrials/inline +Example/libmain.so'; + use Inline CPP; + sub func { add(1,1); } print "9 + 16 = ", add(9, 16), "\n"; + __END__ __CPP__ + #include "main.h" char GlobalArr[13] = {'G','l','o','b','a','l',' ','a','r','r','a',' +y','\0',}; MyClass myGlobalInstance(GlobalArr) ; int add(int x, int y) { char arr[7]={'i','n',' ','a','d','d','\0'}; MyClass mc(arr); myGlobalInstance.wow(); return x + y; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: inline in a perl module
by syphilis (Archbishop) on May 20, 2008 at 09:12 UTC | |
by nirf1 (Novice) on May 20, 2008 at 11:53 UTC |