1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: UFFI Example file to test arrays
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
10 ;;;; This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
12 ;;;; *************************************************************************
16 (uffi:def-constant +column-length+ 10)
17 (uffi:def-constant +row-length+ 10)
19 (uffi:def-foreign-type long-ptr (* :long))
21 (defun test-array-1d ()
23 (let ((a (uffi:allocate-foreign-object :long +column-length+)))
24 (dotimes (i +column-length+)
25 (setf (uffi:deref-array a '(:array :long) i) (* i i)))
26 (dotimes (i +column-length+)
27 (format t "~&~D => ~D" i (uffi:deref-array a '(:array :long) i)))
28 (uffi:free-foreign-object a))
31 (defun test-array-2d ()
33 (let ((a (uffi:allocate-foreign-object 'long-ptr +row-length+)))
34 (dotimes (r +row-length+)
36 (setf (uffi:deref-array a '(:array (* :long)) r)
37 (uffi:allocate-foreign-object :long +column-length+))
38 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
39 (dotimes (c +column-length+)
41 (setf (uffi:deref-array col '(:array :long) c) (+ (* r +column-length+) c)))))
43 (dotimes (r +row-length+)
45 (format t "~&Row ~D: " r)
46 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
47 (dotimes (c +column-length+)
49 (let ((result (uffi:deref-array col '(:array :long) c)))
50 (format t "~d " result)))))
52 (uffi:free-foreign-object a))