You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
917 B

  1. #!/usr/bin/env pil
  2. (setq P (native "@" "malloc" 'N 32))
  3. # initialize the struct
  4. (struct P 'N
  5. 32 (char "!") # 2 bytes
  6. 67 (char "D") # 2 chars
  7. 255 255 255 255 # int
  8. 1 0 0 0 0 0 0 0 # long
  9. 65 66 67 68 69 70 71 72 # string
  10. 1 2 3 4 5 6 7 8 ) # char array
  11. (let Res (native "target/debug/libpilrust.so" "extract" 'I P)
  12. (prinl "Result code: " Res)
  13. (if (=0 Res)
  14. (let Extracted (struct P '((B . 2) (C . 2) I N S (B . 8)))
  15. (native "@" "free" NIL P)
  16. (prinl "Extracted struct: ")
  17. (pp 'Extracted)
  18. # tests
  19. (test (42 43) (car Extracted))
  20. (test '("A" "B") (; Extracted 2))
  21. (test 65535 (; Extracted 3))
  22. (test 9223372036854775807 (; Extracted 4))
  23. (test "pilrust" (; Extracted 5))
  24. (test "PicoLisp" (pack (mapcar char (last Extracted)))) )
  25. (bye 1) ]
  26. (bye)