2017-06-12 4 views
1

ECLで共有ライブラリを読み込み、受け取ったC関数をインポートしてcl_objectecl_def_c_function()で定義されているかのように)を呼び出してREPL (* .lispファイルをコンパイルせずに)?例えば埋め込み可能なCommon Lisp(ECL):拡張関数を使用して共有ライブラリをロードする

は:

// file 'extensions.c' compiled to 'extensions.so' 

cl_object 
    do_something 
     (cl_object arg) 
{ 
    cl_object 
     result = ...; 

    return result; 
} 

; in ECL REPL 
(uffi:load-foreign-library #p".../extensions.so") 
... ; importing stuff 
(format t "got: ~a~%" (do-something "text")) 

私は(UFFI経由)ECL cl_objectでそのC関数の契約ではなく、通常のポインタ(void*)を伝える方法はありませんいたよう。

答えて

0

あなたはPythonのように簡単にはできないようです。 私がこれまでに見つかった唯一の解決策:

#include <stdio.h> 
#include <ecl/ecl.h> 

static 
cl_object 
    make_pair 
     (cl_object arg) 
{ 
    return cl_cons(arg, arg); 
} 

void 
    init_extlib 
     (void) 
{ 
    ecl_def_c_function(
     ecl_read_from_cstring("make-pair"), 
     make_pair, 
     1 
    ); 
} 

extlib.cはそれをコンパイルします。

clang `ecl-config --cflags` extlib.c -shared -fPIC -o extlib.so `ecl-config --libs` 

負荷extlib.lisp

(uffi:load-foreign-library "~/extlib.so") 
(uffi:def-function ("init_extlib" init-extlib) 
        () 
        :returning :void) 
(init-extlib) 

コムそれを重ね:

ecl -compile load-extlib.lisp -o load-extlib.fas 

ロード&テストそれ:

ecl -load load-extlib.fas 
> (make-pair "blah") 

("blah" . "blah") 
関連する問題