[Ecls-list] how to convert a string from lisp to a c string (char *)?
yami
yamisoe at gmail.com
Wed Mar 24 23:27:46 UTC 2010
Hi,
How can I convert a string from lisp to a c string, so that I can use it in
C?
It seems a FAQ question, but I can not find the answer...
My current version looks exactly like:
-------------------C---------------------
int main(int argc, char** argv)
{
cl_boot(argc, argv);
cl_load(1, make_base_string_copy("simple.lisp"));
for (int i=0; i<220; i++) { /* 220 is just a random large
value for testing, see below */
cl_object cl_string = cl_funcall(1, cl_intern(1,
make_simple_base_string("GET-STRING")));
char* c_string = ecl_base_string_pointer_safe(cl_string);
}
cl_shutdown();
}
--------------------CL: simple.lisp---------------------------
(defun get-string ()
(let ((result (format nil "<?xml version='1.0' encoding='UTF-8'
standalone='no'?>~%~%<svg xmlns='http://www.w3.org/2000/svg'
version='1.1'>~% <rect x='0' y='0' width='fixed' height='fixed'
style='fill: none' stroke='blue' />~%</svg>~%")))
(print (format nil "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$~%"))
(print (format nil "~a~%" result))
(print (format nil "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~%"))
result))
However when I ran the program, after several correct iterations, I
encountered following problem:
--------------------OUTPUT------------------------------
Cannot coerce a string with fill pointer to (char *)
Available restarts:
1. (QUIT-DEBUGGER) Quit debugger level 1.
Broken at NIL.
So I mean the error occurs after several successful iterations.
Any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20100325/948cdd0a/attachment.html>
More information about the ecl-devel
mailing list