factor/library/alien/aliens.factor

47 lines
1.1 KiB
Factor
Raw Normal View History

2005-04-09 18:30:46 -04:00
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: alien
USING: hashtables io kernel kernel-internals lists math
namespaces parser ;
2005-04-09 18:30:46 -04:00
UNION: c-ptr byte-array alien displaced-alien ;
2005-04-09 18:30:46 -04:00
: NULL ( -- null )
#! C null value.
0 <alien> ;
M: alien hashcode ( obj -- n )
alien-address >fixnum ;
M: alien = ( obj obj -- ? )
over alien? [
alien-address swap alien-address =
] [
2drop f
] ifte ;
: library ( name -- object )
dup [ "libraries" get hash ] when ;
2005-05-05 03:12:37 -04:00
: load-library ( name -- dll )
2005-04-09 18:30:46 -04:00
#! Higher level wrapper around dlopen primitive.
library dup [
[
"dll" get dup [
drop "name" get dlopen dup "dll" set
] unless
] bind
] when ;
: add-library ( library name abi -- )
"libraries" get [
[ "abi" set "name" set ] make-hash swap set
2005-04-09 18:30:46 -04:00
] bind ;
: library-abi ( library -- abi )
library [ [ "abi" get ] bind ] [ "cdecl" ] ifte* ;
2005-08-24 10:19:09 -04:00
: DLL" skip-blank parse-string dlopen swons ; parsing
: ALIEN: scan-word <alien> swons ; parsing