]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/libraries/libraries.factor
Factor source files should not be executable
[factor.git] / basis / alien / libraries / libraries.factor
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 ;
5 IN: alien.libraries
6
7 : dlopen ( path -- dll ) native-string>alien (dlopen) ;
8
9 : dlsym ( name dll -- alien ) [ string>symbol ] dip (dlsym) ;
10
11 SYMBOL: libraries
12
13 libraries [ H{ } clone ] initialize
14
15 TUPLE: library path abi dll ;
16
17 : library ( name -- library ) libraries get at ;
18
19 : <library> ( path abi -- library )
20     over dup [ dlopen ] when \ library boa ;
21
22 : load-library ( name -- dll )
23     library dup [ dll>> ] when ;
24
25 M: dll dispose dlclose ;
26
27 M: library dispose dll>> [ dispose ] when* ;
28
29 : remove-library ( name -- )
30     libraries get delete-at* [ dispose ] [ drop ] if ;
31
32 : add-library ( name path abi -- )
33     [ 2drop remove-library ]
34     [ <library> swap libraries get set-at ] 3bi ;