[Ecls-list] Thanks for the Embedding Help

"john fred connors" johnc at yagc.ndo.co.uk
Tue Aug 12 10:44:28 UTC 2008


Juan,

Thanks: with your help I was able to get the REPL working in my testbed, and
I learnt a bit more about catch and throw. For the future reference of
anybody doing this kind of thing, here's what I ended up with..

int main(int argc, char* argv)
{

   // ..
       const char *handler = "#.(lambda (str env err-value)
(multiple-value-list (catch 'si::protect-tag (let* ((*debugger-hook*
#'(lambda (condition old-hooks) (throw 'si::protect-tag condition))))
(si::eval-with-env (read-from-string str) env)))))";
        cl_boot(argc, argv);
	ecl_register_static_root(&g_eval_handler);
	g_eval_handler = c_string_to_object(handler);
        g_evalErrorSymbol = cl_gensym(0);

      // ..
}

             cl_object cl_str = make_simple_base_string((char *)
str.c_str());
             cl_object result = funcall(4, g_eval_handler, cl_str, Cnil,
g_evalErrorSymbol);
             cl_terpri(0);
             cl_princ(1,result);
             cl_terpri(0);

Note that g_evalErrorSymbol isn't used any more as I can just print the
returned condition and it gives the user some feedback. I also had to wrap
the evaluation in a mulitple-values-list as I couldn't get the multiple
values off the stack with NVALUES and VALUES() for some reason.

Thanks again,

John.




More information about the ecl-devel mailing list