42001865 |
1 | (asdf:oos 'asdf:load-op :uffi) |
560af5c5 |
2 | |
42001865 |
3 | (defpackage #:sharedlib |
4 | (:use #:common-lisp #:uffi) |
5 | (:export #:load-shared-library)) |
6 | |
7 | (in-package #:sharedlib) |
8 | |
9 | |
10 | (defparameter *library-paths* '("/usr/lib/")) |
11 | |
12 | |
13 | |
14 | (defun load-shared-library (name &key init prototype initargs) |
15 | (format t ";;; Loading shared library ~A~%" name) |
16 | (let ((pathname (find-foreign-library name *library-paths*))) |
17 | (if pathname |
18 | (unless (load-foreign-library pathname) |
19 | (error "Couldn't load shared library: ~A" pathname)) |
20 | (error "Shared library not found: ~A" name))) |
560af5c5 |
21 | (when init |
22 | (apply |
23 | #'alien:alien-funcall |
24 | (alien::%heap-alien |
25 | (alien::make-heap-alien-info |
26 | :type (alien::parse-alien-type (or prototype `(function c-call:void))) |
27 | :sap-form (system:foreign-symbol-address init))) |
28 | initargs))) |