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
12 ;;;; This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
18 (uffi:def-constant +column-length+ 10)
19 (uffi:def-constant +row-length+ 10)
21 (uffi:def-foreign-type long-ptr (* :long))
23 (defun test-array-1d ()
25 (let ((a (uffi:allocate-foreign-object :long +column-length+)))
26 (dotimes (i +column-length+)
27 (setf (uffi:deref-array a '(:array :long) i) (* i i)))
28 (dotimes (i +column-length+)
29 (format t "~&~D => ~D" i (uffi:deref-array a '(:array :long) i)))
30 (uffi:free-foreign-object a))
33 (defun test-array-2d ()
35 (let ((a (uffi:allocate-foreign-object 'long-ptr +row-length+)))
36 (dotimes (r +row-length+)
38 (setf (uffi:deref-array a '(:array (* :long)) r)
39 (uffi:allocate-foreign-object :long +column-length+))
40 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
41 (dotimes (c +column-length+)
43 (setf (uffi:deref-array col '(:array :long) c) (+ (* r +column-length+) c)))))
45 (dotimes (r +row-length+)
47 (format t "~&Row ~D: " r)
48 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
49 (dotimes (c +column-length+)
51 (let ((result (uffi:deref-array col '(:array :long) c)))
52 (format t "~d " result)))))
54 (uffi:free-foreign-object a))