]> gitweb.factorcode.org Git - factor.git/commitdiff
alien.libraries.finder: Add a word to find the first matching function from a list.
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 13 Feb 2022 22:04:15 +0000 (16:04 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 13 Feb 2022 22:04:15 +0000 (16:04 -0600)
basis/alien/libraries/finder/finder.factor

index 8c26d23973de66db1794ece71a59034f9cccade2..a2762fc700b1a10a022e1be885e7311079506cb0 100644 (file)
@@ -1,5 +1,5 @@
-USING: accessors alien.libraries kernel sequences system vocabs
-;
+USING: accessors alien.libraries assocs kernel namespaces
+sequences system vocabs ;
 IN: alien.libraries.finder
 
 HOOK: find-library* os ( name -- path/f )
@@ -14,6 +14,16 @@ HOOK: find-library* os ( name -- path/f )
         [ find-library ] [ update-library ] bi*
     ] if ;
 
+
+ERROR: library-missing library ;
+
+: find-first-function ( names library -- function/f )
+    libraries get ?at [
+        dll>> '[ _ dlsym ] map-find nip
+    ] [
+        library-missing
+    ] if ;
+
 ! 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.