X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=examples%2Fatoifl.lisp;fp=examples%2Fatoifl.lisp;h=47c194cf9e4fe5f9430ccb746e245e5810b31018;hb=a95b9a217335917d96b8c0cced4f49c3e4846115;hp=0000000000000000000000000000000000000000;hpb=bcd9fb3deb580f2976e7505a7433795ed6ad1bb3;p=uffi.git diff --git a/examples/atoifl.lisp b/examples/atoifl.lisp new file mode 100644 index 0000000..47c194c --- /dev/null +++ b/examples/atoifl.lisp @@ -0,0 +1,59 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +;;;; ************************************************************************* +;;;; FILE IDENTIFICATION +;;;; +;;;; Name: atoifl.cl +;;;; Purpose: UFFI Example file to atoi/atof/atol +;;;; Programmer: Kevin M. Rosenberg +;;;; Date Started: Mar 2002 +;;;; +;;;; $Id: atoifl.lisp,v 1.1 2002/09/30 10:02:36 kevin Exp $ +;;;; +;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg +;;;; +;;;; UFFI users are granted the rights to distribute and use this software +;;;; as governed by the terms of the Lisp Lesser GNU Public License +;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. +;;;; ************************************************************************* + +(in-package :cl-user) + +(uffi:def-function ("atoi" c-atoi) + ((str :cstring)) + :returning :int) + +(uffi:def-function ("atol" c-atol) + ((str :cstring)) + :returning :long) + +(uffi:def-function ("atof" c-atof) + ((str :cstring)) + :returning :double) + +(defun atoi (str) + "Returns a int from a string." + (uffi:with-cstring (str-cstring str) + (c-atoi str-cstring))) + +(defun atof (str) + "Returns a double float from a string." + (uffi:with-cstring (str-cstring str) + (c-atof str-cstring))) + +#+examples-uffi +(progn + (flet ((print-results (str) + (format t "~&(atoi ~S) => ~S" str (atoi str)))) + (print-results "55"))) + + +#+test-uffi +(progn + (util.test:test (atoi "123") 123 :test #'eql + :fail-info "Error with atoi") + (util.test:test (atoi "") 0 :test #'eql + :fail-info "Error with atoi") + (util.test:test (atof "2.23") 2.23d0 :test #'eql + :fail-info "Error with atof") + ) +