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 ;;;; $Id: arrays.lisp,v 1.1 2002/09/30 10:02:36 kevin Exp $
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 (defun test-array-1d ()
26 (let ((a (uffi:allocate-foreign-object :long +column-length+)))
27 (dotimes (i +column-length+)
28 (setf (uffi:deref-array a '(:array :long) i) (* i i)))
29 (dotimes (i +column-length+)
30 (format t "~&~D => ~D" i (uffi:deref-array a '(:array :long) i)))
31 (uffi:free-foreign-object a))
34 (defun test-array-2d ()
36 (let ((a (uffi:allocate-foreign-object '(* :long) +row-length+)))
37 (dotimes (r +row-length+)
39 (setf (uffi:deref-array a '(:array (* :long)) r)
40 (uffi:allocate-foreign-object :long +column-length+))
41 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
42 (dotimes (c +column-length+)
44 (setf (uffi:deref-array col '(:array :long) c) (+ (* r +column-length+) c)))))
46 (dotimes (r +row-length+)
48 (format t "~&Row ~D: " r)
49 (let ((col (uffi:deref-array a '(:array (* :long)) r)))
50 (dotimes (c +column-length+)
52 (let ((result (uffi:deref-array col '(:array :long) c)))
53 (format t "~d " result)))))
55 (uffi:free-foreign-object a))