Changeset 12547 in project


Ignore:
Timestamp:
11/17/08 15:20:23 (12 years ago)
Author:
svnwiki
Message:

Changes applied for AndreKuehne? (83.135.7.47) through svnwiki:

join code boxes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/easyffi

    r11289 r12547  
    2525 #include <math.h>
    2626 ")
    27 
     27 
    2828 (define sin (foreign-lambda double "sin" double))
    2929
     
    3535 extern double sin(double);
    3636 <#
    37 
     37 
    3838 (print (sin 3.14))
    3939
     
    5656
    5757 ; file: test-foo.scm
    58 
     58 
    5959 (require-extension tinyclos)
    6060 
     
    8383 
    8484 (require-extension tinyclos)
    85 
     85 
    8686 ; Include into generated code, but don't parse:
    8787 #>
     
    8989 #include <qpushbutton.h>
    9090 <#
    91 
     91 
    9292 ; Parse but don't embed: we only want wrappers for a few classes:
    9393 #>?
     
    9898   void show();
    9999 };
    100 
     100 
    101101 class QApplication
    102102 {
     
    107107   void exec();
    108108 };
    109 
     109 
    110110 class QPushButton : public QWidget
    111111 {
     
    115115 }
    116116 <#
    117 
     117 
    118118 (define a (apply make <QApplication> (receive (argc+argv))))
    119119 (define hello (make <QPushButton> "hello world!" #f))
     
    263263 #include <math.h>
    264264 #endif
    265 
     265 
    266266 double modf(double x, ___out double *iptr);
    267267 <#
    268 
     268 
    269269 (let-values ([(frac int) (modf 33.44)])
    270270   ...)
     
    276276 #>!
    277277 (require-extension srfi-4)
    278 
     278 
    279279 double sumarray(double *arr, ___length(arr) int len)
    280280 {
    281281   double sum = 0;
    282 
     282 
    283283   while(len--) sum += *(arr++);
    284 
     284 
    285285   return sum;
    286286 }
    287287 <#
    288 
     288 
    289289 (print (sumarray (f64vector 33 44 55.66)))
    290290
     
    305305 #>!
    306306 struct My_struct { int x; ___mutable float y; };
    307 
     307 
    308308 typedef struct My_struct My_struct;
    309 
     309 
    310310 My_struct *make_struct(int x, float y)
    311311 {
     
    371371 #>!
    372372 ___declare(exception_handler, "catch(...) { return 0; }")
    373 
     373 
    374374 class Foo {
    375375  public:
     
    377377 };
    378378 <#
    379 
     379 
    380380 (define f1 (make <Foo>))
    381381 (print (bar f1 #f))
     
    458458
    459459 ___declare(substitute, "^SDL_;sdl:")
    460 
     460 
    461461 extern void SDL_Quit();
    462462
     
    471471
    472472 (require-for-syntax 'srfi-13)
    473 
     473 
    474474 #>!
    475475 ___declare(transform, "([A-Z]+)_(.*);(lambda (x) (string-append (cadr x) \"-\" (string-downcase (caddr x))))")
    476 
     476 
    477477 void FOO_Bar(int x) { return x * 2; }
    478478 <#
    479 
     479 
    480480 (print (FOO-bar 33))
    481481
     
    492492 ; - Note: this is rather kludgy and is only meant to demonstrate the `type'
    493493 ;         pseudo-declaration
    494 
     494 
    495495 (require-extension srfi-4)
    496 
     496 
    497497 (define mbstowcs (foreign-lambda int "mbstowcs" nonnull-u32vector c-string int))
    498 
     498 
    499499 (define (str->ustr str)
    500500   (let* ([len (string-length str)]
     
    502502     (mbstowcs us str len)
    503503     us) )
    504 
     504 
    505505 #>!
    506506 ___declare(type, "unicode;nonnull-u32vector;str->ustr")
    507 
     507 
    508508 static void foo(unicode ws)
    509509 {
     
    511511 }
    512512 <#
    513 
     513 
    514514 (foo "this is a test!")
    515515
     
    520520 #>?
    521521 ___declare(opaque, "myfile;(pointer \"FILE\")")
    522 
     522 
    523523 myfile fopen(char *, char *);
    524524 <#
    525 
     525 
    526526 (fopen "somefile" "r")   ==> <myfile>
    527527
Note: See TracChangeset for help on using the changeset viewer.