[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Guile initialization and string evaluation with C++

From: Eduardo Acuña
Subject: Guile initialization and string evaluation with C++
Date: Mon, 24 Mar 2014 12:08:10 -0700

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)

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 )]

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]

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]

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]

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:


Description: Zip archive

reply via email to

[Prev in Thread] Current Thread [Next in Thread]