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 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
21 (uffi:def-constant +column-length+ 10)
22 (uffi:def-constant +row-length+ 10)
24 (uffi:def-foreign-type long-ptr '(* :long))
26 (defun test-array-1d ()
28 (let ((a (uffi:allocate-foreign-object :long +column-length+)))
29 (dotimes (i +column-length+)
30 (setf (uffi:deref-array a '(:array :long) i) (* i i)))
31 (dotimes (i +column-length+)
32 (format t "~&~D => ~D" i (uffi:deref-array a '(:array :long) i)))
33 (uffi:free-foreign-object a))
36 (defun test-array-2d ()
38 (let ((a (uffi:allocate-foreign-object 'long-ptr +row-length+)))
39 (dotimes (r +row-length+)
41 (setf (uffi:deref-array a '(:array (* :long)) r)
42 (uffi:allocate-foreign-object :long +column-length+))
43 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
44 (dotimes (c +column-length+)
46 (setf (uffi:deref-array col '(:array :long) c) (+ (* r +column-length+) c)))))
48 (dotimes (r +row-length+)
50 (format t "~&Row ~D: " r)
51 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
52 (dotimes (c +column-length+)
54 (let ((result (uffi:deref-array col '(:array :long) c)))
55 (format t "~d " result)))))
57 (uffi:free-foreign-object a))