alien.libraries.finder: More robust finder code that doesn't return f to a

string slot and error out. Use it in yaml.ffi.
db4
Doug Coleman 2014-07-08 12:40:33 -05:00
parent 8afdafac05
commit 1e8655c5c0
2 changed files with 9 additions and 8 deletions

View File

@ -6,9 +6,13 @@ HOOK: find-library* os ( name -- path/f )
: find-library ( name -- path/library-not-found )
dup find-library* [ nip ] when* ;
! Try to find the library from a list, but if it's not found,
! try to open a library that is the first name in that list anyway
! or "library_not_found" as a last resort for better debugging.
: find-library-from-list ( seq -- path/f )
[ find-library* ] map [ ] find nip ;
dup [ find-library* ] map
[ ] find nip [ nip ] [ ?first "library_not_found" or ] if* ;
{
{ [ os macosx? ] [ "alien.libraries.finder.macosx" ] }

View File

@ -3,15 +3,12 @@
! adapted from "yaml.h" libYAML 0.1.4
! http://pyyaml.org/wiki/LibYAML
USING: alien alien.c-types alien.destructors alien.libraries
alien.syntax classes.struct combinators literals system ;
alien.syntax classes.struct combinators literals system
alien.libraries.finder ;
IN: yaml.ffi
<<
"libyaml" {
{ [ os windows? ] [ "libyaml.dll" ] }
{ [ os macosx? ] [ "libyaml.dylib" ] }
{ [ os unix? ] [ "libyaml.so" ] }
} cond cdecl add-library
"libyaml" { "yaml" "libyaml-0-2" } find-library-from-list cdecl add-library
>>
C-TYPE: FILE