Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
jnthn's patches to get the first bit of working mysql client code
  • Loading branch information
Martin Berends committed Mar 3, 2010
1 parent a8c5996 commit 176db61
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
36 changes: 30 additions & 6 deletions examples/connect.p6
Expand Up @@ -2,17 +2,41 @@

use NativeCall;

sub my_init( CPointer $mysql_client)
is native('mysqlclient')
class CPointer { ... }
# hack compensating for too-late import of CPointer from NativeCall.pm

sub mysql_init( CPointer $mysql_client)
returns CPointer
{ ... }
is native('libmysqlclient')
{ say "wtf" }

sub mysql_real_connect( CPointer $mysql_client, Str $host, Str $user,
Str $password, Str $database, Int $port, Str $socket, Int $flag )
returns CPointer
is native('libmysqlclient')
{ ... }

my $client = my_init( 0 );
my $client = mysql_real_connect( $client, 'localhost', 'testuser',
'testpass', 'mysql', 0, 0, 0 );
sub mysql_error( CPointer $mysql_client)
returns Str
is native('libmysqlclient')
{ say "wtf" }

sub mysql_query( CPointer $mysql_client, Str $dbname )
returns Int
is native('libmysqlclient')
{ say "wtf" }

say "ok startup";
my $client = mysql_init( pir::null__P() );
say "inited";

mysql_real_connect( pir::descalarref__PP($client), 'localhost', 'testuser',
'testpass', 'mysql', 0, pir::null__P(), 0 );

say "called connect";

mysql_query( pir::descalarref__PP($client), 'create database zavolaj' );

say mysql_error($client);

say "called error";
8 changes: 4 additions & 4 deletions lib/NativeCall.pm
Expand Up @@ -2,11 +2,11 @@ class CPointer { }

our sub map-type-to-sig-char(Mu $type) {
given $type {
when Int { 'l' }
when Int { 'i' }
when Str { 't' }
when Num { 'd' }
when Rat { 'd' }
when CPointer { 'P' }
when CPointer { 'p' }
default { die "Can not handle type " ~ $_.perl ~ " in an 'is native' signature." }
}
}
Expand All @@ -23,11 +23,11 @@ our sub perl6-sig-to-backend-sig(Routine $r) {
our multi trait_mod:<is>(Routine $r, $libname, :$native!) {
my $entry-point = $r.name();
my $call-sig = perl6-sig-to-backend-sig($r);
pir::setattribute__vPsP($r, '$!do', -> |$c {
pir::setattribute__vPsP($r, '$!do', pir::clone__PP(-> |$c {
(pir::dlfunc__PPss(
pir::loadlib__Ps($libname),
$entry-point,
$call-sig
)).(|$c)
});
}));
}

0 comments on commit 176db61

Please sign in to comment.