[Ecls-list] how to convert a string from lisp to a c string (char *)?
Seth Burleigh
seth at tewebs.com
Thu Mar 25 03:06:21 UTC 2010
Does
(char*)cl_string->base_string.self;
work?
or maybe
cl_object princed = cl_princ_to_string(1, cl_string);
char* result = (char*)princed->base_string.self;
On Thu, 2010-03-25 at 07:27 +0800, yami wrote:
> 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?
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________ Ecls-list mailing list Ecls-list at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ecls-list
More information about the ecl-devel
mailing list