<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">This works :)<br>
<br>
<tt> </tt><tt>38 (define (get-fullscreen-modes)</tt><tt><br>
</tt><tt> 39 (define get-fullscreen-modes*</tt><tt><br>
</tt><tt> 40 (c-lambda () sfml:Vector<VideoMode>*</tt><tt><br>
</tt><tt> 41 "___result_voidstar = new
std::vector<sf::VideoMode>(sf::VideoMode::getFullscreenModes());"))</tt><tt><br>
</tt><tt> 42 (define vector-video-mode-length</tt><tt><br>
</tt><tt> 43 (c-lambda (sfml:Vector<VideoMode>*) size_t</tt><tt><br>
</tt><tt> 44 "___result = ___arg1->size();"))</tt><tt><br>
</tt><tt> 45 (define vector-video-mode-ref</tt><tt><br>
</tt><tt> 46 (c-lambda (sfml:Vector<VideoMode>* size_t)
sfml:VideoMode*</tt><tt><br>
</tt><tt> 47 "___result_voidstar = new
sf::VideoMode(___arg1->at(___arg2));"))</tt><tt><br>
</tt><tt> 48 </tt><tt><br>
</tt><tt> 49 (let* ((modes (get-fullscreen-modes*))</tt><tt><br>
</tt><tt> 50 (size (vector-video-mode-length modes))</tt><tt><br>
</tt><tt> 51 (result (make-vector size)))</tt><tt><br>
</tt><tt> 52 (let loop ((i 0))</tt><tt><br>
</tt><tt> 53 (cond </tt><tt><br>
</tt><tt> 54 ((< i size)</tt><tt><br>
</tt><tt> 55 (vector-set! result i
(vector-video-mode-ref modes i))</tt><tt><br>
</tt><tt> 56 (loop (+ i 1)))</tt><tt><br>
</tt><tt> 57 (else </tt><tt><br>
</tt><tt> 58 result)))))</tt><tt><br>
</tt><tt><br>
</tt><br>
Is it also possible to accomplish the same directly from a
c-lambda that returns a scheme-object?<br>
<br>
<br>
Am 16.08.2013 09:54, schrieb Mikael:<br>
</div>
<blockquote
cite="mid:CACbx-M93U+DUayjNh8FJ3t6M_tAZLMt_UxhAyev8Gp78Cxbifw@mail.gmail.com"
type="cite">
<div dir="ltr">Perhaps make a c-define-type for <span
style="font-family:arial,sans-serif;font-size:13px">std::vector<VideoMode>*
that you return the return value of .</span><span
style="font-family:arial,sans-serif;font-size:13px">getFullscreenModes()
as, and then make a -length and -ref procedure for this type.</span>
<div>
<span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px">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.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">2013/8/16 Chris Mueller <span
dir="ltr"><<a moz-do-not-send="true"
href="mailto:ruunsmail@gmail.com" target="_blank">ruunsmail@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
i'm currently coding a gambit binding for sfml and could
need some<br>
adivces for a specific ffi problem from you.<br>
<br>
Assume we have a class VideoMode with the following
constructor:<br>
<br>
class VideoMode {<br>
public:<br>
VideoMode(int width, int height, int bbp);<br>
# ...<br>
}<br>
<br>
<br>
I have defined an interface to scheme with:<br>
<br>
;; Release hook is ignored for this example<br>
(c-define-type VideoMode* (pointer "VideoMode"))<br>
<br>
;; Scheme's construction wrapper for VideoMode<br>
(define video-mode<br>
(c-lambda (int int int) VideoMode* "___result_voidstar =
new<br>
VideoMode(___arg1, ___arg2, ___arg3);"))<br>
<br>
<br>
Now assume a function that retrieves all supporting
video-modes in C++:<br>
<br>
std::vector<VideoMode> getFullscreenModes();<br>
<br>
<br>
I would like to write now a scheme-function (with c-lambda)
that<br>
iterators through all elements from this std::vector<br>
and constructs/returns a scheme-vector with foreign-objects
of type<br>
(pointer "VideoMode").<br>
<br>
How does the c-lambda code look like for this small issue?
(Or how would<br>
you cope this problem alternatively?)<br>
<br>
<br>
Chris<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Gambit-list mailing list<br>
<a moz-do-not-send="true"
href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a moz-do-not-send="true"
href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list"
target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>