41 lines
1.0 KiB
Factor
41 lines
1.0 KiB
Factor
! 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 ;
|
|
|
|
UNION: c-ptr byte-array alien displaced-alien ;
|
|
|
|
M: alien hashcode ( obj -- n )
|
|
alien-address >fixnum ;
|
|
|
|
M: alien = ( obj obj -- ? )
|
|
over alien? [
|
|
alien-address swap alien-address =
|
|
] [
|
|
2drop f
|
|
] if ;
|
|
|
|
: library ( name -- object ) "libraries" get hash ;
|
|
|
|
: load-library ( name -- dll )
|
|
#! 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
|
|
] bind ;
|
|
|
|
: add-simple-library ( name file -- )
|
|
os "win32" = ".dll" ".so" ? append
|
|
os "win32" = "stdcall" "cdecl" ? add-library ;
|
|
|
|
: library-abi ( library -- abi )
|
|
library "abi" swap ?hash [ "cdecl" ] unless* ;
|