2006-02-11 02:30:18 -05:00
|
|
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2005-04-09 18:30:46 -04:00
|
|
|
IN: alien
|
2006-02-11 02:30:18 -05:00
|
|
|
USING: arrays hashtables io kernel lists math namespaces parser
|
|
|
|
|
sequences ;
|
|
|
|
|
|
|
|
|
|
! USAGE:
|
|
|
|
|
!
|
|
|
|
|
! Command line parameters given to the runtime specify libraries
|
|
|
|
|
! to load.
|
|
|
|
|
!
|
|
|
|
|
! -libraries:<foo>:name=<soname> -- define a library <foo>, to be
|
|
|
|
|
! loaded from the <soname> DLL.
|
|
|
|
|
!
|
|
|
|
|
! -libraries:<foo>:abi=stdcall -- define a library using the
|
|
|
|
|
! stdcall ABI. This ABI is usually used on Win32. Any other abi
|
|
|
|
|
! parameter, or a missing abi parameter indicates the cdecl ABI
|
|
|
|
|
! should be used, which is common on Unix.
|
2005-04-09 18:30:46 -04:00
|
|
|
|
2006-03-09 01:44:17 -05:00
|
|
|
: <alien> ( address -- alien )
|
|
|
|
|
dup zero? [ drop f ] [ f <displaced-alien> ] if ; inline
|
2005-07-17 14:48:55 -04:00
|
|
|
|
2006-02-19 20:53:18 -05:00
|
|
|
UNION: c-ptr byte-array alien ;
|
2005-04-09 18:30:46 -04:00
|
|
|
|
|
|
|
|
M: alien = ( obj obj -- ? )
|
2006-02-11 02:30:18 -05:00
|
|
|
over alien? [ [ alien-address ] 2apply = ] [ 2drop f ] if ;
|
|
|
|
|
|
|
|
|
|
global [ "libraries" nest drop ] bind
|
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 [
|
2005-08-22 02:06:32 -04:00
|
|
|
[ "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* ;
|