system io.pathnames fry ;
IN: alien.libraries
+ERROR: unknown-dlsym-platform ;
+<< {
+ { [ os windows? ] [ "alien.libraries.windows" ] }
+ { [ os unix? ] [ "alien.libraries.unix" ] }
+ [ unknown-dlsym-platform ]
+} cond use-vocab >>
+
: dlopen ( path -- dll ) native-string>alien (dlopen) ;
: dlsym ( name dll -- alien ) [ string>symbol ] dip (dlsym) ;
: dlsym-raw ( name dll -- alien ) [ string>symbol ] dip (dlsym-raw) ;
+: dlerror ( -- message/f ) (dlerror) ;
+
SYMBOL: libraries
libraries [ H{ } clone ] initialize
--- /dev/null
+USING: alien.c-types alien.syntax io.encodings.utf8 ;
+IN: alien.libraries.unix
+
+FUNCTION-ALIAS: (dlerror)
+ c-string[utf8] dlerror ( ) ;
--- /dev/null
+USING: windows.errors ;
+IN: alien.libraries.windows
+
+: (dlerror) ( -- message )
+ win32-error-string ;
: check-dlsym ( symbols dll -- )
dup dll-valid? [
dupd dlsym-valid?
- [ drop ] [ cfg get word>> no-such-symbol ] if
- ] [ dll-path cfg get word>> no-such-library drop ] if ;
+ [ drop ] [ dlerror cfg get word>> no-such-symbol ] if
+ ] [ dll-path "" cfg get word>> no-such-library drop ] if ;
: decorated-symbol ( params -- symbols )
[ function>> ] [ parameters>> [ stack-size ] map-sum number>string ] bi
: <linkage-error> ( error word -- linkage-error )
\ linkage-error <definition-error> ;
-: linkage-error ( error word class -- )
+: linkage-error ( name message word class -- )
'[ _ boa ] dip <linkage-error> dup asset>> linkage-errors get set-at ; inline
T{ error-type
{ fatal? f }
} define-error-type
-TUPLE: no-such-library name ;
+TUPLE: no-such-library name message ;
M: no-such-library summary drop "Library not found" ;
-: no-such-library ( name word -- ) \ no-such-library linkage-error ;
+: no-such-library ( name message word -- ) \ no-such-library linkage-error ;
-TUPLE: no-such-symbol name ;
+TUPLE: no-such-symbol name message ;
M: no-such-symbol summary drop "Symbol not found" ;
-: no-such-symbol ( name word -- ) \ no-such-symbol linkage-error ;
+: no-such-symbol ( name message word -- ) \ no-such-symbol linkage-error ;
-ERROR: not-compiled word error ;
\ No newline at end of file
+ERROR: not-compiled word error ;