On Mon, 2014-03-24 at 12:08 -0700, Eduardo Acuña wrote: > Hello everybody. > > lately i have been programming in scheme, but i'm usually obligated to use > C++ for school. > > So i try to use guile inside C++ programs. > > I wrote two little classes for simplifying the initialization of guile and > evaluating expressions, and i have a couple of questions regarding how can > i enhance the implementation. > > The two classes are: > - GuileApplication (does the scm_boot_guile and other stuff) > - GuileEvaluator (has an eval function that gets a expression as an > std::string and returns the result as an std::string) >
Please write Makefile and use pkg-config next time ;-) And it's better if you can use github or similar thing we can read the code directly. Not all guys want to download a strange zip file from a strange link. > Questions about the GuileApplication class: > 1.- How can a send scm_boot_guile a member function? (relevant functions > are init, initializationHack and guileMain) > [Explanation: the scm_boot_guile is called from a member function of > GuileApplication and i want to send another member function as the > "inner_main", my half-solution was to use a normal function that received a > GuileApplication* casted as a void* and dereferencing that to call the > other member function (i had to friend this function and pass the instance > as the void * data )] > Can you explain why you want to `send' scm_boot_guile'? I can't figure it out from your description and your code. > 2.- Is the "(use-modules (system repl server)) (spawn-server)" a good way > of getting access to the program with emacs and geiser's > 'connect-to-guile'? (relevant functions are guileMain) > [Explanation: i like to use an external repl to test functions with emacs > and geiser, the only way i know to make this happen is to eval those two > expressions, but i don't know if it is the right way to do it] > I don't know if it's the best way, but the same method appears in geiser's code. So I think it's not bad for you. > Questions about the GuileEvaluator class: > 3.- How can i handle better the possible errors from evaluating expressions > from C++? (relevant functions are evalString, guileEvalHandler, > handler_message, guileEvalBody) > [Explanation: i think the curren way i'm handling errors is a bit clumsy, i > wanted to show the error message but don't exit the entire program, so i > had to copy the handler_message from the guile source, but i'm sure there > is a better way of doing this] > I'm not sure what you mean. If you don't want to exit while exceptions occur, you can just catch them all with #t and print the error message, then call your main loop again. My solution is not a good one, just one of the possible way, maybe not suit for your code. I suggest you elaborate your problem. > 4.- How can i avoid having to close the output string port and creating a > new one each time i convert an SCM value to an std::string? (relevant > functions are scmToString) > [Explanation: i want the output string port to be cleared when i evaluate > an expression and return the result as an std::string] > Your scmToString is too complicated for its function I understand. Maybe you just need scm_object_to_string BTW, your program is cool ;-) > > I attached the code i'm working on, i hope you can point me in the right > direction. > > I will appreciate any suggestion regarding this program :-) > > By the way, i'm currently trying to use guile in a couple of games with the > SFML library, and with this thow classes i wrote a very simple demo to > start working from, if you would like to check it out here it is: > https://www.mediafire.com/?kp094p85s10to4y > > Eduardo.