-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract.l
executable file
·32 lines (26 loc) · 905 Bytes
/
extract.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env pil
(setq P (native "@" "malloc" 'N 32))
# initialize the struct
(struct P 'N
32 (char "!") # 2 bytes
67 (char "D") # 2 chars
255 255 255 255 # int
1 0 0 0 0 0 0 0 # long
65 66 67 68 69 70 71 72 # string
1 2 3 4 5 6 7 8 ) # char array
(let Res (native "./libpil.so" "extract" 'I P)
(prinl "Result code: " Res)
(if (=0 Res)
(let Extracted (struct P '((B . 2) (C . 2) I N S (B . 8)))
(native "@" "free" NIL P)
(prinl "Extracted struct: ")
(pp 'Extracted)
# tests
(test (42 43) (car Extracted))
(test '("A" "B") (; Extracted 2))
(test 65535 (; Extracted 3))
(test 9223372036854775807 (; Extracted 4))
(test "pilcrystal" (; Extracted 5))
(test "PicoLisp" (pack (mapcar char (last Extracted)))) )
(bye 1) ]
(bye)