Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:57:24+00:00 2026-06-16T17:57:24+00:00

I’ve been playing around with the fantastic cffi recently but I am having issues

  • 0

I’ve been playing around with the fantastic cffi recently but I am having issues working out if something should be possible using the build in mechanisms.

I want to create a foreign array of vectors and have the foreign type translations set up such that this is possible.

> (defparameter a (foreign-alloc 'vec3 :count 10))
A
> (setf (mem-aref  a 'vec3 4) (convert-to-foreign #(1.0 2.0 3.0) 'vec3))
#(1.0 2.0 3.0)
> (convert-from-foreign (mem-aref b 'vec3 4) 'vec3)
#(1.0 2.0 3.0

So far I have the following which allows the creating and getting of the foreign vec3 but not the retrieval.

(defcstruct %vec3
  (components :float :count 3))

(define-foreign-type vec3-type ()
  ()
  (:actual-type %vec3)
  (:simple-parser vec3))

(defmethod translate-from-foreign (value (type vec3-type))
  (make-array 
   3 
   :element-type 'single-float
   :initial-contents (list (mem-aref value :float 0)
               (mem-aref value :float 1)
               (mem-aref value :float 2))))

The issue is that, while I can easily set up a function to act as a setter for the vec3, I would love there to be some in built way of doing this that I’m just not seeing. I have read the cffi manual and have seen the translate-to-foreign method and also the expand-to-foreign-dyn, but I haven’t found a way to use the to essentially expand to something like the following:

(let ((tmp (mem-aref a '%vec3 4)))
  (setf (mem-aref tmp :float 0) (aref lisp-value 0))
  (setf (mem-aref tmp :float 1) (aref lisp-value 1))
  (setf (mem-aref tmp :float 2) (aref lisp-value 2)))

So that no extra memory is allocated and the values get set directly.

Well that’s my little daydream, does anyone know if it can be made to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:57:25+00:00Added an answer on June 16, 2026 at 5:57 pm

    Had a read of the CFFI source code and it seems that this is not supported through the built in mechanisms. There is code there for handling array-types but it is not exposed or exported so is clearly not for use. There is also a proposed block memory interface but this has not been written yet.

    So no dice this time, but CFFI is fantastic so I’ll just make it in a different way.

    p.s. There is also WAAF-CFFI that is worth looking into but I don’t have specifics on this yet

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm interested in microtypography issues on the web. I want a tool to fix:
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.