[Cascavel-pm] acessando bibliotecas em C/C++ sem usar XS

Alceu R. de Freitas Jr. glasswalk3r em yahoo.com.br
Segunda Janeiro 30 06:53:46 PST 2006


Eu levantei esse tópico em uma discussão com o Breno,
mas talvez isso seja de interesse de outros monges,
por isso vou divulgar:

"Inline

One of the things that has come over into Perl 5 from
Perl 6 development is the concept of the Native Call
Interface (NCI). This hasn't fully been developed yet,
but chromatic (yes, the editor of this very site) has
been working on it.

The idea is that, instead of having something like
Inline or XS that creates a "buffer" between Perl and
C libraries, you just call those libraries directly.
At the moment, you need to compile any XS module
against the library you're using. This is particularly
awkward for folk on cut-down operating systems that do
not ship a compiler, such as Palm OS or Windows.

The strength of NCI is that it doesn't require a
compiler; instead, it uses the operating system's
normal means of making calls into libraries. (Hence
"Native Call.") It uses Perl's DynaLoader to find
libraries, load them, and then find the address of
symbols inside of the library. Then it calls a generic
"thunk" function to turn the symbol's address into a
call. For instance:

my $lib = P5NCI::Library->new( library => 'nci_test',
package => 'NCI' );
$lib->install_function( 'double_int', 'ii' );

my $two = NCI::double_int( 1 );

These lines find the nci_test shared library and get
ready to put its functions into the NCI namespace. It
then installs the function double_int, which is of
signature int double_int(int) (hence ii). Once this is
done, you can call the function from Perl. It's not
much trickier than Inline, but without the
intermediate step of compilation.

NCI isn't quite there yet, and it only supports very
simple function signatures. However, because of its
portability, it's definitely the one to watch for
Perl-C interfaces in the future."

Fonte:
http://www.perl.com/lpt/a/2006/01/26/more_advanced_perl.html

[]'s


Alceu Rodrigues de Freitas Junior
--------------------------------------
glasswalk3r em yahoo.com.br
http://www.imortais.cjb.net
-----------------------------------------------------------------------
A well-used door needs no oil on its hinges.
A swift-flowing stream does not grow stagnant.
Neither sound nor thoughts can travel through a vacuum.
Software rots if not used.
These are great mysteries -- The Tao Of Programming, 5.1


	



	
		
_______________________________________________________ 
Yahoo! doce lar. Faça do Yahoo! sua homepage. 
http://br.yahoo.com/homepageset.html 



Mais detalhes sobre a lista de discussão Cascavel-pm