1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.strings assocs io.backend
4 kernel namespaces destructors ;
7 : dlopen ( path -- dll ) native-string>alien (dlopen) ;
9 : dlsym ( name dll -- alien ) [ string>symbol ] dip (dlsym) ;
13 libraries [ H{ } clone ] initialize
15 TUPLE: library path abi dll ;
17 : library ( name -- library ) libraries get at ;
19 : <library> ( path abi -- library )
20 over dup [ dlopen ] when \ library boa ;
22 : load-library ( name -- dll )
23 library dup [ dll>> ] when ;
25 M: dll dispose dlclose ;
27 M: library dispose dll>> [ dispose ] when* ;
29 : remove-library ( name -- )
30 libraries get delete-at* [ dispose ] [ drop ] if ;
32 : add-library ( name path abi -- )
33 [ 2drop remove-library ]
34 [ <library> swap libraries get set-at ] 3bi ;