hi!
a few days ago i was pointed to P5NCI::Library to interact with C-libraries. i had a closer look at it and it's really useful and great! but by playing around with it, a few problems came up. it seems that load_function does not accept a void-signature. i put up a test-library that takes various arguments. amongst them 'void'. here is the .c-code for the test-library:
#include <stdio.h>
#include <string.h>
char *hello(void)
{
static char result[]={"hello world"};
return result;
}
char *bye(char *str)
{
static char prefix[]={"good bye"};
static char result[32];
strcpy(result,prefix);
strcat(result,str);
return result;
}
char *return_char(int chr)
{
static char result[1];
sprintf(result, "%c", chr);
return result;
}
int square(int x)
{
x = (x * x);
return x;
}
int do_nothing(void)
{
return 1;
}
and here is a little test-script using P5NCI::Library to interact with my test-library:
#!/usr/bin/perl
use P5NCI::Library;
my $lib = P5NCI::Library->new( library => 'hello_world', package => 'T
+EST' );
my $test = $lib->install_function( 'hello', 'tv' );
my $hello = TEST::hello();
print "for hello() i got: $hello\n";
undef $test;
my $test = $lib->install_function( 'return_char', 'ti' );
my $return_char = TEST::return_char( 65 );
print "for return_char(65) i got: $return_char\n";
undef $test;
my $test = $lib->install_function( 'square', 'ii' );
my $square = TEST::square( 3 );
print "for square(3) i got: $square\n";
undef $test;
my $test = $lib->install_function( 'bye', 'tt' );
my $bye = TEST::bye( "thanks for all the passwords" );
print "for bye(test) i got: $bye\n";
undef $test;
my $test = $lib->install_function( 'do_nothing', 'vi' );
my $do_nothing = TEST::do_nothing();
print "for do_nothing() i got: $do_nothing\n";
undef $test;
the functions 'return_char', 'square', and 'bye' work just perfect, but 'hello' and 'do_nothing' do not. both have a void input-signature.
am i doing something wrong, or is P5NCI having troubles with these kind of functions? TIA for any hint.
br, nos
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.