Created
August 22, 2015 17:53
-
-
Save paulohrpinheiro/2fb2a98b8ca11ebe960b to your computer and use it in GitHub Desktop.
Exemplo completo de chamadas naticas em Perl6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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