factor/library/alien/aliens.factor

42 lines
1.0 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: arrays hashtables io kernel 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
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 )
2005-08-25 15:27:38 -04:00
library "abi" swap ?hash [ "cdecl" ] unless* ;
2005-08-24 10:19:09 -04:00
: DLL" skip-blank parse-string dlopen swons ; parsing
: ALIEN: scan-word <alien> swons ; parsing