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

Mikael mikael.rcv at gmail.com
Fri Aug 16 03:54:41 EDT 2013


Perhaps make a c-define-type for std::vector<VideoMode>* that you return
the return value of .getFullscreenModes() as, and then make a -length and
-ref procedure for this type.

Remember that for c-define-type :s that do not have a release procedure
specified, there is *no* deallocation (such as free() etc.) invoked at
their scheme-world GC.



2013/8/16 Chris Mueller <ruunsmail at gmail.com>

> 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
>
>
>
>
>
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20130816/40486b82/attachment.htm>


More information about the Gambit-list mailing list