[gambit-list] FFI Converting std::vector to scheme-vector (best practice)

Chris Mueller ruunsmail at gmail.com
Thu Aug 15 19:21:31 EDT 2013


Hi,

i'm currently coding a gambit binding for sfml and could need some 
adivces for a specific ffi problem from you.

Assume we have a class VideoMode with the following constructor:

class VideoMode {
public:
   VideoMode(int width, int height, int bbp);
   # ...
}


I have defined an interface to scheme with:

;; Release hook is ignored for this example
(c-define-type VideoMode* (pointer "VideoMode"))

;; Scheme's construction wrapper for VideoMode
(define video-mode
   (c-lambda (int int int) VideoMode* "___result_voidstar = new 
VideoMode(___arg1, ___arg2, ___arg3);"))


Now assume a function that retrieves all supporting video-modes in C++:

std::vector<VideoMode> getFullscreenModes();


I would like to write now a scheme-function (with c-lambda) that 
iterators through all elements from this std::vector
and constructs/returns a scheme-vector with foreign-objects of type 
(pointer "VideoMode").

How does the c-lambda code look like for this small issue? (Or how would 
you cope this problem alternatively?)


Chris








More information about the Gambit-list mailing list