X-Git-Url: https://git.siccegge.de//index.cgi?p=frida%2Ffrida.git;a=blobdiff_plain;f=src%2Fbindings%2FGuile.cxx;fp=src%2Fbindings%2FGuile.cxx;h=2552e7d215ab8b97e85edfc77a372a7fe13f6e2e;hp=0000000000000000000000000000000000000000;hb=7cc1f7b923b7859a7469e6a651d4a87bc48c4772;hpb=30bd2ac7409f9d7496708b77a404fd69be291387 diff --git a/src/bindings/Guile.cxx b/src/bindings/Guile.cxx new file mode 100644 index 0000000..2552e7d --- /dev/null +++ b/src/bindings/Guile.cxx @@ -0,0 +1,52 @@ +#include "Guile.hxx" + +namespace { + SCM handler (void*, SCM tag, SCM throw_args) { + scm_handle_by_message_noexit ((void*)"foo", tag, throw_args); + return SCM_BOOL_F; + } +} + +GuileInterpreter::GuileInterpreter() { + scm_init_guile(); + + scm_internal_catch(SCM_BOOL_T, + (SCM (*)(void *))scm_c_eval_string, + (void*)"(use-modules (system repl server))", + handler, NULL); + scm_internal_catch(SCM_BOOL_T, + (SCM (*)(void *))scm_c_eval_string, + (void*)"(spawn-server)", + handler, NULL); + + guile_output_port = scm_open_output_string(); + guile_error_port = scm_open_output_string(); + scm_set_current_output_port(guile_output_port); + scm_set_current_error_port(guile_error_port); +} + +int GuileInterpreter::evaluate(const std::string& command, + std::ostream& stdout, + std::ostream& stderr, + std::string& result) { + + SCM result_obj = scm_internal_catch(SCM_BOOL_T, + (SCM (*)(void *))scm_c_eval_string, + (void*)command.c_str(), + handler, NULL); + + SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED); + + SCM output = scm_get_output_string(guile_output_port); + stdout << scm_to_locale_string(output); + + output = scm_get_output_string(guile_error_port); + stderr << scm_to_locale_string(output); + + result = scm_to_locale_string(result_str); + + scm_truncate_file(guile_output_port, scm_from_uint16(0)); + scm_truncate_file(guile_error_port, scm_from_uint16(0)); + + return 0; +}