Created
April 30, 2019 16:00
-
-
Save wsgac/cb6bbe0bcc1d7f1dd2a118fdc0d1e4f3 to your computer and use it in GitHub Desktop.
First attempts at FFI for Gerbil expeditor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; -*- scheme -*- | |
| (import :std/foreign) | |
| (export get-screen-size) | |
| (begin-ffi (get-screen-size) | |
| (c-declare "#include <sys/ioctl.h>") | |
| (c-declare "#include <stdio.h>") | |
| (c-declare "#include <unistd.h>") | |
| (define-c-lambda get-screen-size () scheme-object "get_screen_size") | |
| (c-declare #<<END-C | |
| ___SCMOBJ get_screen_size() { | |
| struct winsize w; | |
| ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); | |
| return ___make_pair(___PSTATE, ___FIX(w.ws_row), ___FIX(w.ws_col)); | |
| } | |
| END-C | |
| ) | |
| (defstruct gerbil-point (x y z)) | |
| (c-define-type point (struct "point")) | |
| (c-declare #<<END-C | |
| struct point{ | |
| int x; | |
| int y; | |
| int z; | |
| } | |
| point make_point() { | |
| point p; | |
| p.x = 1; | |
| p.y = 2; | |
| p.z = 3; | |
| return p; | |
| } | |
| END-C | |
| ) | |
| (define-c-lambda make_point () point | |
| "make_point") | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment