Convert a c++ vector to a lisp vector using CFFI:MEM-AREF

Discussion of Common Lisp

Convert a c++ vector to a lisp vector using CFFI:MEM-AREF

Postby joeish80829 » Thu Apr 24, 2014 10:26 pm

I have these C bindings for the C++ vector which I have wrapped in CFFI. I know how to create vectors with std_carrayTovector and convert the data back to a int pointer with std_vectorToCArray so that I can retrieve data from it in Lisp using the CFFI function MEM-AREF. I have correct defcfuns written for the below . My question is how to I convert the output of my defcfun for std_vectorToCArray at the bottom of the page, into a Lisp vector eg #(1 2 3) and make it a 0(1) operation/all data copied at the same time.

Code: Select all
vector_int* std_carrayTovector(int* a, size_t len) {
    vector<int>* v = new vector<int>;
    for(size_t i = 0; i < len; i++)
        v->push_back(a[i]);
    return v;
}

int* std_vectorToCArray(vector_int* s) {
    return s->data();
}


(defcfun ("std_vectori_to_carray" %vector-int-to-c-array) :pointer
  (s (:pointer vector-int)))
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Return to Common Lisp

Who is online

Users browsing this forum: pjstirling and 2 guests