factor/library/alien/aliens.factor

41 lines
1.0 KiB
Factor
Raw Permalink 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 sequences ;
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
2005-09-24 15:21:17 -04:00
] if ;
2005-04-09 18:30:46 -04:00
2005-12-10 01:02:13 -05:00
: library ( name -- object ) "libraries" get hash ;
2005-04-09 18:30:46 -04:00
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 ;
2006-01-19 18:57:27 -05:00
: add-simple-library ( name file -- )
2006-01-31 14:31:31 -05:00
os "win32" = ".dll" ".so" ? append
os "win32" = "stdcall" "cdecl" ? add-library ;
2006-01-19 18:57:27 -05:00
2005-04-09 18:30:46 -04:00
: library-abi ( library -- abi )
2005-08-25 15:27:38 -04:00
library "abi" swap ?hash [ "cdecl" ] unless* ;