[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Wrapping C's printf
From: |
Ozzi |
Subject: |
[Chicken-users] Wrapping C's printf |
Date: |
Tue, 30 Oct 2007 21:20:40 -0500 |
User-agent: |
Thunderbird 2.0.0.6 (Macintosh/20070728) |
I'd like to wrap C's printf so that I can do something like this:
(c-printf "The %s of %d and %d is %d" "sum" 1 1 2)
Which would print "The sum of 1 and 1 is 2."
I realize that I can't use a simple foreign-lambda, as I need to call C's printf
with an arbitrary argument list.
Is there a clean way to do this with ffi?
If there is not, my idea is to chop the format string up into chunks, like so:
'("The %s" " of %d" " and %d" " is %d")
and run each chunk through the correct single-argument foreign-lambda of printf.
That means I will have to create one foreign function for each type of argument
printf can take, which shouldn't be a big deal.
Any comments on this method?
Of course, if someone knows of a pre-made version of printf with C syntax that
will work with chicken, all of this will be moot, and I will be grateful.
Oz
- [Chicken-users] Wrapping C's printf,
Ozzi <=