source: project/release/5/foreigners/tags/1.5/tests/enum-1.scm @ 36185

Last change on this file since 36185 was 36185, checked in by Kooda, 13 months ago

Port foreigners to CHICKEN 5

File size: 1.1 KB
Line 
1#>
2#define STATUS_OK 0
3#define STATUS_BUSY 1
4#define STATUS_FAIL 2
5
6static int _status = STATUS_OK;
7int get_status() { return _status;
8}
9void set_status(int s) { _status = s;
10}
11<#
12
13(module enum-1
14  (status->int int->status
15   get-status set-status busy?)
16
17  (import scheme (chicken foreign) foreigners)
18
19  (define-foreign-enum-type (foo:status int)
20    (status->int int->status)
21    ((ok status/ok) STATUS_OK)
22    ((busy status/busy) STATUS_BUSY)
23    ((fail status/fail) STATUS_FAIL))
24
25  (define get-status
26    (foreign-lambda foo:status "get_status"))
27  (define set-status
28    (foreign-lambda void "set_status" foo:status))
29  (define (busy? s)
30    (= s status/busy))
31  )
32
33(import test)
34(import enum-1)
35
36(test "status->int" 1 (status->int 'busy))
37(test "int->status" 'fail (int->status 2))
38(set-status 'busy)
39(test "get-status" 'busy (get-status))
40(test "status/busy via busy?" #t (busy? (status->int (get-status))))
41;; Normally won't work, however status/fail is a foreign-variable and
42;; therefore visible inside entire compilation unit.
43(test "status/fail" 'fail (int->status status/fail))
44(test-exit)
Note: See TracBrowser for help on using the repository browser.