Skip to content

Instantly share code, notes, and snippets.

@paulohrpinheiro
Created August 22, 2015 17:53
Show Gist options
  • Save paulohrpinheiro/2fb2a98b8ca11ebe960b to your computer and use it in GitHub Desktop.
Save paulohrpinheiro/2fb2a98b8ca11ebe960b to your computer and use it in GitHub Desktop.
Exemplo completo de chamadas naticas em Perl6.
use NativeCall;
constant $LIBNAME = 'libsqlite3';
sub sqlite3_open (Str, Array[OpaquePointer]) returns Int is native($LIBNAME) { * }
sub sqlite3_exec (OpaquePointer, Str, OpaquePointer, OpaquePointer,OpaquePointer) returns Int is native($LIBNAME) { * }
sub sqlite3_errmsg (OpaquePointer) returns Str is native($LIBNAME) { * }
sub sqlite3_close (OpaquePointer) returns Int is native($LIBNAME) { * }
my @handler := CArray[OpaquePointer].new;
@handler[0] = OpaquePointer;
say sqlite3_open(@*ARGS[0], @handler);
say sqlite3_exec(@handler[0], "CREATE TABLE foo (bar NUMBER);", OpaquePointer, OpaquePointer, OpaquePointer);
say sqlite3_errmsg(@handler[0]);
say sqlite3_close(@handler[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment