Hi, On Friday 27 October 2006 15:57, J. Manuel Velasco wrote: > Hi Kish, > > Thanks for your reply. > > I've tried your trick, but I don't get nothing. > > This is what I try: > > /* LICENSE BLock > ... > */ > > #include "eclipseclass.h" > #include <iostream> > > using namespace std; > > main() > { > char buf[1024]; > int n; > > ec_set_option_int(EC_OPTION_IO, MEMORY_IO); > ec_init(); > > // orientacion_main is a Prolog file > post_goal(term(EC_functor("compile", 1), "orientacion_main")); > > // orientacion is a Prolog file got it after processing the CHR file with > chr2pl command > post_goal(term(EC_functor("compile", 1), "orientacion")); > > // This is the query I want to pass to prolog. > // I need to do it like that because I get strings like that after > // an image processing from a C++ controller > ec_post_string("ctr_orient(C,A,B,[lm]),ctr_orient(D,C,B,[lm])"); > > ec_resume(); > > n = ec_queue_read(1, buf, 1024); > buf[n] = 0; > cout << "eclipse returned: " << buf << ".\n"; > > n = ec_queue_read(2, buf, 1024); > buf[n] = 0; > cout << "eclipse error returned: " << buf << ".\n"; > > ec_cleanup(); > exit(0); > } > > > And when I compile and execute it, nothing happends: > > manou_at_acad5071act:~/test$ make > g++ -O -I/home/manou/eclipse/include/i386_linux -c eg_cc_basic.cc > g++ eg_cc_basic.o -L/home/manou/eclipse/lib/i386_linux -leclipse -lgmp > -L/home/manou/eclipse/tcltk/i386_linux/lib -L. -lnsl -ldl -lieee -lm -s > -Wl,--export-dynamic -o eg_cc_basic > manou_at_acad5071act:~/test$ ./eg_cc_basic > eclipse returned: . > eclipse error returned: . > > Thanks in advance for any comment. > I don't think anything would be sent to either output (1) or the error (2) streams for your program -- ec_post_string() should only be used for goals you don't want output for. Unless you have special need to manipulate ECLiPSe data structures in your C/C++ code, you should also avoid them in your C/C++ code, it is quite difficult to do, and easy to get wrong. It is better to leave the complex data structures on the ECLiPSe side if you can, and wrap any complex query you have in a simpler goal you call from C/C++, looking something like: my_c_call(Data) :- do_my_eclipse_query(Data, Result), writeln(output, Result). where do_my_eclipse_query is the actual ECLiPSe goal(s) you want to run, and Result is the final result(s) you want to see. Of course Data and Result in do_my_eclipse_query may be arranged as you need it in your code. You then call my_c_call(Data) from C/C++, using ec_post_string(). By the way, you seem to be using lib(chr) instead of the newer lib(ech): ech should generate code that runs faster than chr, and it also does not need the extra step of chr2pl to compile CHR code. [See the end of the chapter on CHR in the library manual for information on lib(ech)] Cheers, Kish > > El Viernes, 27 de Octubre de 2006 14:32, Kish Shen escribió: > > post_goal(term(EC_functor("compile", 1), "orientacion")); > > _______________________________________________ > ECLiPSe-Users mailing list > ECLiPSe-Users_at_crosscoreop.com > http://www.crosscoreop.com/mailman/listinfo/eclipse-users >Received on Tue Oct 31 2006 - 15:41:30 CET
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:57 CET